Skip to content

Commit 52b7e6d

Browse files
committed
Improve variadic function templates article
Use sequence instead of tuple. Minor wording changes. Formatting tweaks.
1 parent 27c0ad3 commit 52b7e6d

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

articles/variadic-function-templates.dd

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ void print(...)
155155

156156
$(P It isn't elegant or the most efficient,
157157
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
158+
(It relies on the parameters `_argptr` and `_arguments` imported from `core.vararg`
159159
which give a pointer to the values and their types, respectively.)
160160
)
161161

@@ -180,18 +180,19 @@ void print(T, A...)(T t, A a)
180180
$(P There are two function templates. The first provides the
181181
degenerate case of no arguments, and a terminus for the
182182
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.
183+
`t` for the first value and `a` for any remaining values.
184+
`A...` says the parameter is a sequence, and $(I implicit function
185+
template instantiation) will fill in `A` with all the types of any
186+
arguments supplied following `t`. So, `print(7, 'a', 6.8)` will
187+
fill in `int` for `T`, and a type sequence `(char, double)` for `A`.
188+
The parameter `a` is an lvalue sequence of any
189+
arguments supplied after `t`.
189190
)
190191

191-
$(P The function works by printing the first parameter t,
192+
$(P The function works by printing the first parameter `t`,
192193
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()().
194+
`a`. The recursion terminates when there are no longer any
195+
arguments by calling `print()()`.
195196
)
196197

197198
$(H4 The Static If Solution)
@@ -213,18 +214,18 @@ void print(A...)(A a)
213214
}
214215
---
215216

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.
217+
$(P Sequences can be manipulated much like arrays.
218+
So `a.length` resolves to the number of elements
219+
in the sequence `a`. `a[0]` gives the first element
220+
in the sequence. `a[1 .. $]` creates a new sequence
221+
from any remaining elements in the original sequence.
221222
)
222223

223224
$(H4 The Foreach Solution)
224225

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:
226+
$(P But since sequences can be manipulated like arrays,
227+
we can use a `foreach` statement to iterate over
228+
the sequence's elements:
228229
)
229230

230231
---

0 commit comments

Comments
 (0)