11Ddoc
22
3+ $(COMMENT BE CAREFUL TO USE < AND > INSIDE CPPCODE2)
4+
35$(COMMUNITY Template Comparison,
46
57$(P C++ pioneered templates and template metaprogramming and has continued
@@ -23,8 +25,8 @@ templates based on the C++ experience.
2325
2426 $(TR
2527 $(TD Argument list delineation)
26- $(TD Uses !( ), as in Foo!(int). $(BR)Can omit parens when the argument is a single lexical token: Foo!int)
27- $(TD Uses < > as in Foo< int> )
28+ $(TD Uses ` !( )` , as in ` Foo!(int)` . $(BR)Can omit parens when the argument is a single lexical token: ` Foo!int` )
29+ $(TD Uses `< >` as in ` Foo< int>` )
2830 )
2931
3032 $(TR
@@ -151,7 +153,7 @@ MyFoo<unsigned> f;
151153$(CPPCODE2
152154template <class T>
153155class Foo {
154- Foo(std::initializer_list<T> );
156+ Foo(std::initializer_list<T> );
155157};
156158
157159Foo<double> f = { 1.2, 3.0, 6.8 };
@@ -214,7 +216,8 @@ void foo(T)(T i)
214216 SlowFoo f = slow_foo(i);
215217 use_foo(f);
216218}
217-
219+ ---
220+ ---
218221class HashTable(T, int maxLength)
219222{
220223 static if (maxLength < 0xFFFE)
@@ -232,23 +235,23 @@ $(CPPCODE2
232235template<class T> void foo(T i)
233236{
234237 // Differentiate using a
235- // Helper< bool> specialization
236- Helper< can_fast_foo<T>> ::use_foo(i);
238+ // Helper< bool> specialization
239+ Helper< can_fast_foo<T>> ::use_foo(i);
237240};
238241
239242template<class T, int maxLength> class HashTable {
240- typedef typename std::conditional<
241- maxLength < 0xFFFE, uint16_t, uint32_t>
243+ typedef typename std::conditional<
244+ maxLength < 0xFFFE, uint16_t, uint32_t>
242245 ::type CellIdx;
243246 CellIdx index;
244247};
245248)
246249 $(BR)$(B$(U C++17))$(BR)
247- Yes, but is limited to block scope:
250+ Yes, but it's limited to block scope:
248251$(CPPCODE2
249252template<class T> void foo(T i)
250253{
251- if constexpr (can_fast_foo<T> )
254+ if constexpr (can_fast_foo<T> )
252255 FastFoo foo = fast_foo(i);
253256 else
254257 SlowFoo foo = slow_foo(i);
@@ -257,7 +260,7 @@ template<class T> void foo(T i)
257260
258261template<class T, int maxLength> class HashTable {
259262 // $(ERROR cannot use 'if' outside of a function)
260- if constexpr (maxLength < 0xFFFE)
263+ if constexpr (maxLength < 0xFFFE)
261264 using CellIdx = ushort;
262265 else
263266 using CellIdx = uint;
@@ -298,8 +301,8 @@ class Foo {
298301 class Bar { ... };
299302 static T foo(T t, U u) { ... }
300303};
301- Foo< int, long> ::bar b;
302- return Foo< char, int> ::foo('c', 3);
304+ Foo< int, long> ::bar b;
305+ return Foo< char, int> ::foo('c', 3);
303306)
304307 )
305308 )
0 commit comments