Skip to content

Commit 8b6dda1

Browse files
ntreldlang-bot
authored andcommitted
[articles/template-comparison] Improve D examples
Fix `static if` example syntax. Make examples runnable. Fix & simplify `is` example (the template parameter has to be an alias).
1 parent 43b6210 commit 8b6dda1

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

articles/template-comparison.dd

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ template<> class factorial<1>
206206
based on Template Arguments)
207207
$(TD Yes:
208208
---
209-
template void foo(T)(T i)
209+
void foo(T)(T i)
210210
{
211211
static if (can_fast_foo!(T))
212212
FastFoo f = fast_foo(i);
@@ -313,6 +313,8 @@ return Foo<char, int>::foo('c', 3);
313313
$(TR
314314
$(TD Compile time execution of functions)
315315
$(TD $(DDSUBLINK spec/function, interpretation, Yes):
316+
317+
$(RUNNABLE_EXAMPLE_COMPILE
316318
---
317319
int factorial(int i)
318320
{
@@ -321,8 +323,9 @@ int factorial(int i)
321323
else
322324
return i * factorial(i - 1);
323325
}
324-
static f = factorial(6);
326+
pragma(msg, factorial(6));
325327
---
328+
)
326329
)
327330
$(TD
328331
$(B$(U C++98))$(BR)
@@ -722,19 +725,18 @@ void foo(int i) { }
722725
$(TD Can extract arguments of
723726
template instance)
724727
$(TD Yes:
725-
---
726-
class Foo(T)
727-
{
728-
static if (is(T x : T!A, A...))
729-
{
730-
pragma(msg, A); // (int, float)
731-
}
732-
}
733728

729+
$(RUNNABLE_EXAMPLE_COMPILE
730+
---
734731
struct Bar(T1, T2) { }
735732
alias BarInst = Bar!(int, float);
736-
Foo!(BarInst) f;
733+
734+
static if (is(BarInst : Template!Args, alias Template, Args...))
735+
{
736+
pragma(msg, Args); // (int, float)
737+
}
737738
---
739+
)
738740
See $(DDSUBLINK spec/expression, IsExpression, is expressions).)
739741
$(TD No)
740742
)

0 commit comments

Comments
 (0)