Skip to content

Commit 43b6210

Browse files
authored
Improve template-comparison article (#3685)
* Improve template-comparison article C++ still cannot do an enum type template. It was actually C++14 that introduced constexpr constants: https://en.cppreference.com/w/cpp/language/variable_template C++11 introduced type alias templates: https://en.cppreference.com/w/cpp/language/type_alias 2 other tweaks. * Add `using` example * Add line for deducing `this` type https://en.cppreference.com/w/cpp/language/member_functions#Explicit_object_parameter * Mention using alias param instead of ref
1 parent 54267fb commit 43b6210

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

articles/template-comparison.dd

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ T foo(T i)
8383

8484
$(TR
8585
$(TD Parameterize any Declaration)
86-
$(TD Yes, classes, functions, typedefs,
87-
variables, enums, etc. can be parameterized,
86+
$(TD Yes, classes, functions, any
87+
$(DDSUBLINK spec/declaration, alias, alias),
88+
variables, any enum, etc. can be parameterized,
8889
such as this variable:
8990
---
9091
template Foo(T)
@@ -97,7 +98,14 @@ template Foo(T)
9798
$(B$(U C++98))$(BR)
9899
No, only classes and functions
99100
$(BR)$(B$(U C++11))$(BR)
100-
Yes:
101+
Added `using` type aliases:
102+
$(CPPCODE2
103+
template<class T>
104+
using ptr = T*;
105+
ptr<int> p;
106+
)
107+
$(B$(U C++14))$(BR)
108+
Added `constexpr` constant:
101109
$(CPPCODE2
102110
template<class T>
103111
constexpr T pi = T(3.1415926535897932385L);
@@ -133,7 +141,8 @@ MyFoo<unsigned> f;
133141

134142
$(TR
135143
$(TD Sequence Constructors)
136-
$(TD No)
144+
$(TD No, use a
145+
$(DDSUBLINK spec/function, typesafe_variadic_functions, variadic parameter) instead)
137146
$(TD
138147
$(B$(U C++98))$(BR)
139148
No
@@ -259,8 +268,8 @@ template<class T, int maxLength> class HashTable {
259268
)
260269

261270
$(TR
262-
$(TD Template Declarations (with no definition))
263-
$(TD No)
271+
$(TD Template Forward Declarations)
272+
$(TD Not necessary)
264273
$(TD Yes:
265274
$(CPPCODE2
266275
template<class T>
@@ -295,6 +304,12 @@ return Foo<char, int>::foo('c', 3);
295304
)
296305
)
297306

307+
$(TR
308+
$(TD Deducing `this` parameter type)
309+
$(TD $(DDSUBLINK spec/template, template_this_parameter, Yes))
310+
$(TD $(B$(U C++23))$(BR)Yes)
311+
)
312+
298313
$(TR
299314
$(TD Compile time execution of functions)
300315
$(TD $(DDSUBLINK spec/function, interpretation, Yes):
@@ -376,7 +391,7 @@ void foo()
376391

377392
$(TR
378393
$(TD Reference Parameters)
379-
$(TD No, D does not have a general reference type)
394+
$(TD No, but an alias parameter can be used instead (see below).)
380395
$(TD Yes:
381396
$(CPPCODE2
382397
template&lt;double& D&gt;

0 commit comments

Comments
 (0)