Skip to content

Commit 069a380

Browse files
committed
Merge remote-tracking branch 'upstream/master' into merge_stable
# Conflicts: # changelog/2.078.3.dd
2 parents b59f4e8 + 658c314 commit 069a380

File tree

149 files changed

+1208
-664
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+1208
-664
lines changed

articles/variadic-function-templates.dd

Lines changed: 38 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ Ddoc
22

33
$(D_S Variadic Templates,
44

5+
$(HEADERNAV_TOC)
6+
57
$(P The problem statement is simple: write a function that
68
takes an arbitrary number of values of arbitrary types,
79
and print those values out one per line in a manner
@@ -22,15 +24,14 @@ $(CONSOLE
2224
)
2325

2426
$(P We'll explore how this can
25-
be done in standard C++, followed by doing it using
26-
the proposed variadic template C++ extension.
27+
be done in C++.
2728
Then, we'll do it the various ways the D programming
2829
language makes possible.
2930
)
3031

31-
$(H3 C++ Solutions)
32+
$(H2 $(LNAME2 cpp-solutions, C++ Solutions))
3233

33-
$(H4 The Standard C++ Solution)
34+
$(H3 The Overload Solution)
3435

3536
$(P The straightforward way to do this in standard C++
3637
is to use a series of function templates, one for
@@ -97,12 +98,9 @@ template<class T1, class T2, class T3> void print(T1 a1, T2 a2, T3 a3)
9798
compilation.
9899
)
99100

100-
$(H4 The C++ Extension Solution)
101+
$(H3 C++ Variadic Templates)
101102

102-
$(P Douglas Gregor has proposed a
103-
variadic template scheme [1]
104-
for C++ that solves these problems.
105-
The result looks like:
103+
$(P C++11 supports variadic templates:
106104
)
107105

108106
$(CCODE
@@ -120,17 +118,11 @@ template<class T, class... U> void print(T a1, U... an)
120118
$(P It uses recursive function template instantiation
121119
to pick off the arguments one by one.
122120
A specialization with no arguments ends the recursion.
123-
It's a neat and tidy solution, but with one glaring problem:
124-
it's a proposed extension, which means it isn't part
125-
of the C++ standard, may not get into the C++ standard
126-
in its current form, may not get into the standard
127-
in any form, and even if it does, it may be many, many
128-
years before the feature is commonly implemented.
129121
)
130122

131-
$(H3 D Programming Language Solutions)
123+
$(H2 $(LNAME2 d-solutions, D Programming Language Solutions))
132124

133-
$(H4 The D Look Ma No Templates Solution)
125+
$(H3 The D Look Ma No Templates Solution)
134126

135127
$(P It is not practical to solve this problem in C++ without
136128
using templates. In D, one can because D supports typesafe
@@ -155,46 +147,51 @@ void print(...)
155147

156148
$(P It isn't elegant or the most efficient,
157149
but it does work. However it is not the recommended way to write variadic functions.
158-
(It relies on the parameters _argptr and _arguments imported from core.vararg
150+
(It relies on the parameters `_argptr` and `_arguments` imported from `core.vararg`
159151
which give a pointer to the values and their types, respectively.)
160152
)
161153

162-
$(H4 Translating the Variadic C++ Solution into D)
154+
$(H3 Translating the Variadic C++ Solution into D)
163155

164156
$(P Variadic templates in D enable a straightforward translation
165-
of the proposed C++ variadic syntax:
157+
of the C++11 variadic solution:
166158
)
167159

168160
---
169-
void print()()
161+
void print()
170162
{
171163
}
172164

173165
void print(T, A...)(T t, A a)
174166
{
167+
import std.stdio;
175168
writeln(t);
176169
print(a);
177170
}
178171
---
179172

180-
$(P There are two function templates. The first provides the
173+
$(P There are two overloads. The first provides the
181174
degenerate case of no arguments, and a terminus for the
182175
recursion of the second. The second has two arguments:
183-
t for the first value and a for the rest of the values.
184-
A... says the parameter is a tuple, and implicit function
185-
template instantiation will fill in A with the list of
186-
all the types following t. So, print(7, 'a', 6.8) will
187-
fill in int for T, and a tuple (char, double) for A.
188-
The parameter a becomes an expression tuple of the arguments.
176+
`t` for the first value and `a` for any remaining values.
177+
`A...` says the parameter is a sequence, and
178+
$(GLOSSARY2 ifti, Implicit Function Template Instantiation)
179+
will fill in `A` with all the types of any
180+
arguments supplied following `t`. So, `print(7, 'a', 6.8)` will
181+
fill in `int` for `T`, and a type sequence `(char, double)` for `A`.
182+
The parameter `a` is an lvalue sequence of any
183+
arguments supplied after `t`. See
184+
$(DDLINK articles/ctarguments, Compile-time Sequences, Compile-time Sequences)
185+
for more information.
189186
)
190187

191-
$(P The function works by printing the first parameter t,
188+
$(P The function works by printing the first parameter `t`,
192189
and then recursively calling itself with the remaining arguments
193-
a. The recursion terminates when there are no longer any
194-
arguments by calling print()().
190+
`a`. The recursion terminates when there are no longer any
191+
arguments by calling `print()`.
195192
)
196193

197-
$(H4 The Static If Solution)
194+
$(H3 The Static If Solution)
198195

199196
$(P It would be nice to encapsulate all the logic into a
200197
single function. One way to do that is by using
@@ -213,18 +210,18 @@ void print(A...)(A a)
213210
}
214211
---
215212

216-
$(P Tuples can be manipulated much like arrays.
217-
So a.length resolves to the number of expressions
218-
in the tuple a. a[0] gives the first expression
219-
in the tuple. a[1 .. $] creates a new tuple
220-
by slicing the original tuple.
213+
$(P Sequences can be manipulated much like arrays.
214+
So `a.length` resolves to the number of elements
215+
in the sequence `a`. `a[0]` gives the first element
216+
in the sequence. `a[1 .. $]` creates a new sequence
217+
from any remaining elements in the original sequence.
221218
)
222219

223-
$(H4 The Foreach Solution)
220+
$(H3 The Foreach Solution)
224221

225-
$(P But since tuples can be manipulated like arrays,
226-
we can use a foreach statement to 'loop' over
227-
the tuple's expressions:
222+
$(P But since sequences can be manipulated like arrays,
223+
we can use a `foreach` statement to iterate over
224+
the sequence's elements:
228225
)
229226

230227
---
@@ -254,14 +251,6 @@ $(H3 Acknowledgments)
254251

255252
)
256253

257-
$(H3 References)
258-
259-
$(OL
260-
261-
$(LI $(LINK2 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2080.pdf, Variadic Templates N2080))
262-
263-
)
264-
265254
)
266255

267256
Macros:

calendar.dd

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Ddoc
2+
3+
$(D_S $(TITLE),
4+
5+
$(DIVC center,
6+
$(DIVID calendar,
7+
<iframe src="https://calendar.google.com/calendar/embed?src=ut29n9vq9vu3ad4kbaabeed1d8%40group.calendar.google.com" style="border: 0" width="800" height="600" frameborder="0" scrolling="no"></iframe>
8+
)
9+
)
10+
)
11+
12+
Macros:
13+
TITLE=DLang Calendar

changelog/2.000.dd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Ddoc
22

3-
$(CHANGELOG_NAV_FIRST 2.001)
3+
$(CHANGELOG_NAV_INJECT)
44

55
$(VERSION Jun 17, 2007, =================================================,
66

@@ -22,7 +22,7 @@ $(BUGSFIXED
2222
$(LI $(BUGZILLA 1226): ICE on a struct literal)
2323
)
2424
)
25-
$(CHANGELOG_NAV_FIRST 2.001)
25+
$(CHANGELOG_NAV_INJECT)
2626

2727
Macros:
2828
VER=2.000

changelog/2.001.dd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Ddoc
22

3-
$(CHANGELOG_NAV 2.000,2.002)
3+
$(CHANGELOG_NAV_INJECT)
44

55
$(VERSION Jun 27, 2007, =================================================,
66

@@ -39,7 +39,7 @@ $(BUGSFIXED
3939
$(LI $(BUGZILLA 1286): crash on invariant struct member function referencing globals)
4040
)
4141
)
42-
$(CHANGELOG_NAV 2.000,2.002)
42+
$(CHANGELOG_NAV_INJECT)
4343

4444
Macros:
4545
VER=2.001

changelog/2.002.dd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Ddoc
22

3-
$(CHANGELOG_NAV 2.001,2.003)
3+
$(CHANGELOG_NAV_INJECT)
44

55
$(VERSION Jul 1, 2007, =================================================,
66

@@ -54,7 +54,7 @@ $(BUGSFIXED
5454
$(LI $(BUGZILLA 1295): Some minor errors in the lexer grammar)
5555
)
5656
)
57-
$(CHANGELOG_NAV 2.001,2.003)
57+
$(CHANGELOG_NAV_INJECT)
5858

5959
Macros:
6060
VER=2.002

changelog/2.003.dd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Ddoc
22

3-
$(CHANGELOG_NAV 2.002,2.004)
3+
$(CHANGELOG_NAV_INJECT)
44

55
$(VERSION Jul 21, 2007, =================================================,
66

@@ -31,7 +31,7 @@ $(BUGSFIXED
3131
$(LI $(BUGZILLA 1336): Internal error when trying to construct a class declared within a unittest from a templated class.)
3232
)
3333
)
34-
$(CHANGELOG_NAV 2.002,2.004)
34+
$(CHANGELOG_NAV_INJECT)
3535

3636
Macros:
3737
VER=2.003

changelog/2.004.dd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Ddoc
22

3-
$(CHANGELOG_NAV 2.003,2.005)
3+
$(CHANGELOG_NAV_INJECT)
44

55
$(VERSION Sep 5, 2007, =================================================,
66

@@ -41,7 +41,7 @@ $(BUGSFIXED
4141
$(LI $(BUGZILLA 1468): A bug about stack overflow.)
4242
)
4343
)
44-
$(CHANGELOG_NAV 2.003,2.005)
44+
$(CHANGELOG_NAV_INJECT)
4545

4646
Macros:
4747
VER=2.004

changelog/2.005.dd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Ddoc
22

3-
$(CHANGELOG_NAV 2.004,2.006)
3+
$(CHANGELOG_NAV_INJECT)
44

55
$(VERSION Oct 1, 2007, =================================================,
66

@@ -41,7 +41,7 @@ $(BUGSFIXED
4141
$(LI $(BUGZILLA 1537): Internal error: ..\ztc\cgcod.c 1521)
4242
)
4343
)
44-
$(CHANGELOG_NAV 2.004,2.006)
44+
$(CHANGELOG_NAV_INJECT)
4545

4646
Macros:
4747
VER=2.005

changelog/2.006.dd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Ddoc
22

3-
$(CHANGELOG_NAV 2.005,2.007)
3+
$(CHANGELOG_NAV_INJECT)
44

55
$(VERSION Oct 16, 2007, =================================================,
66

@@ -46,7 +46,7 @@ $(BUGSFIXED
4646
$(LI $(BUGZILLA 1580): Concatenating invariant based strings should work)
4747
)
4848
)
49-
$(CHANGELOG_NAV 2.005,2.007)
49+
$(CHANGELOG_NAV_INJECT)
5050

5151
Macros:
5252
VER=2.006

changelog/2.007.dd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Ddoc
22

3-
$(CHANGELOG_NAV 2.006,2.008)
3+
$(CHANGELOG_NAV_INJECT)
44

55
$(VERSION Oct 31, 2007, =================================================,
66

@@ -40,7 +40,7 @@ $(BUGSFIXED
4040
$(LI $(BUGZILLA 1618): Typo in std\system.d)
4141
)
4242
)
43-
$(CHANGELOG_NAV 2.006,2.008)
43+
$(CHANGELOG_NAV_INJECT)
4444

4545
Macros:
4646
VER=2.007

0 commit comments

Comments
 (0)