1
1
Ddoc
2
2
3
+ $(COMMENT BE CAREFUL TO USE < AND > INSIDE CPPCODE2)
4
+
3
5
$(COMMUNITY Template Comparison,
4
6
5
7
$(P C++ pioneered templates and template metaprogramming and has continued
@@ -23,8 +25,8 @@ templates based on the C++ experience.
23
25
24
26
$(TR
25
27
$(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>` )
28
30
)
29
31
30
32
$(TR
@@ -151,7 +153,7 @@ MyFoo<unsigned> f;
151
153
$(CPPCODE2
152
154
template <class T>
153
155
class Foo {
154
- Foo(std::initializer_list<T> );
156
+ Foo(std::initializer_list<T> );
155
157
};
156
158
157
159
Foo<double> f = { 1.2, 3.0, 6.8 };
@@ -214,7 +216,8 @@ void foo(T)(T i)
214
216
SlowFoo f = slow_foo(i);
215
217
use_foo(f);
216
218
}
217
-
219
+ ---
220
+ ---
218
221
class HashTable(T, int maxLength)
219
222
{
220
223
static if (maxLength < 0xFFFE)
@@ -232,23 +235,23 @@ $(CPPCODE2
232
235
template<class T> void foo(T i)
233
236
{
234
237
// 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);
237
240
};
238
241
239
242
template<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>
242
245
::type CellIdx;
243
246
CellIdx index;
244
247
};
245
248
)
246
249
$(BR)$(B$(U C++17))$(BR)
247
- Yes, but is limited to block scope:
250
+ Yes, but it's limited to block scope:
248
251
$(CPPCODE2
249
252
template<class T> void foo(T i)
250
253
{
251
- if constexpr (can_fast_foo<T> )
254
+ if constexpr (can_fast_foo<T> )
252
255
FastFoo foo = fast_foo(i);
253
256
else
254
257
SlowFoo foo = slow_foo(i);
@@ -257,7 +260,7 @@ template<class T> void foo(T i)
257
260
258
261
template<class T, int maxLength> class HashTable {
259
262
// $(ERROR cannot use 'if' outside of a function)
260
- if constexpr (maxLength < 0xFFFE)
263
+ if constexpr (maxLength < 0xFFFE)
261
264
using CellIdx = ushort;
262
265
else
263
266
using CellIdx = uint;
@@ -298,8 +301,8 @@ class Foo {
298
301
class Bar { ... };
299
302
static T foo(T t, U u) { ... }
300
303
};
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);
303
306
)
304
307
)
305
308
)
0 commit comments