Skip to content

Commit 7c66126

Browse files
ntreldlang-bot
authored andcommitted
[articles/template-comparison] Fix < > in CPPCODE2 examples
1 parent 8b6dda1 commit 7c66126

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

articles/template-comparison.dd

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Ddoc
22

3+
$(COMMENT BE CAREFUL TO USE &lt; AND &gt; 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 &lt; &gt; as in Foo&lt;int&gt;)
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&lt;unsigned&gt; f;
151153
$(CPPCODE2
152154
template &lt;class T&gt;
153155
class Foo {
154-
Foo(std::initializer_list<T>);
156+
Foo(std::initializer_list&lt;T&gt;);
155157
};
156158

157159
Foo&lt;double&gt; 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+
---
218221
class HashTable(T, int maxLength)
219222
{
220223
static if (maxLength < 0xFFFE)
@@ -232,23 +235,23 @@ $(CPPCODE2
232235
template&lt;class T&gt; void foo(T i)
233236
{
234237
// Differentiate using a
235-
// Helper<bool> specialization
236-
Helper<can_fast_foo<T>>::use_foo(i);
238+
// Helper&lt;bool&gt; specialization
239+
Helper&lt;can_fast_foo&lt;T&gt;&gt;::use_foo(i);
237240
};
238241

239242
template&lt;class T, int maxLength&gt; class HashTable {
240-
typedef typename std::conditional<
241-
maxLength < 0xFFFE, uint16_t, uint32_t>
243+
typedef typename std::conditional&lt;
244+
maxLength &lt; 0xFFFE, uint16_t, uint32_t&gt;
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
249252
template&lt;class T&gt; void foo(T i)
250253
{
251-
if constexpr (can_fast_foo<T>)
254+
if constexpr (can_fast_foo&lt;T&gt;)
252255
FastFoo foo = fast_foo(i);
253256
else
254257
SlowFoo foo = slow_foo(i);
@@ -257,7 +260,7 @@ template&lt;class T&gt; void foo(T i)
257260

258261
template&lt;class T, int maxLength&gt; class HashTable {
259262
// $(ERROR cannot use 'if' outside of a function)
260-
if constexpr (maxLength < 0xFFFE)
263+
if constexpr (maxLength &lt; 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&lt;int, long&gt;::bar b;
305+
return Foo&lt;char, int&gt;::foo('c', 3);
303306
)
304307
)
305308
)

0 commit comments

Comments
 (0)