[
prev
] [
prev-tail
] [
tail
] [
up
]
1.6.9
Variadic Templates
Finally, there’s a way to write functions that take an arbitrary number of arguments in a type-safe way and have all the argument handling logic resolved at compile-time, rather than run-time.
template
<
typename
T
>
T
adder
(
T
v
)
{
return
v
;
}
template
<
typename
T
,
typename
...
Args
>
T
adder
(
T
first
,
Args
...
args
)
{
return
first
+
adder
(
args
...);
}
//
//////////////////////////
template
<
typename
T
>
show_list
(
const
T
&
value
){
cout
<<
value
<<
endl
;}
template
<
typename
T
,
typename
...
Args
>
show_list
(
const
T
&
value
,
const
Args
&...
args
){
cout
<<
value
<<
endl
;
show_list
(
args
...);
}
[
prev
] [
prev-tail
] [
front
] [
up
]