Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F61439519
variadic_template.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, May 6, 16:50
Size
391 B
Mime Type
text/x-c++
Expires
Wed, May 8, 16:50 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
17513099
Attached To
R9360 PCSC_git
variadic_template.cpp
View Options
#include <iostream>
template
<
typename
T
>
T
adder
(
T
v
)
{
return
v
;
}
template
<
typename
T
,
typename
...
Args
>
// template ...Args is a variadic template
T
adder
(
T
first
,
Args
...
args
)
{
return
first
+
adder
(
args
...);
}
int
main
()
{
std
::
cout
<<
adder
(
1
,
2
,
3
,
4
);
std
::
cout
<<
adder
(
1.
,
2
,
3.
,
4
);
std
::
cout
<<
adder
(
std
::
string
(
"a"
),
std
::
string
(
"b"
));
std
::
cout
<<
std
::
endl
;
}
Event Timeline
Log In to Comment