CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <type_traits>
/**
* Example 1
* Compute sum of all arguments
*/
template < typename... Args >
constexpr auto foo1( Args... args )
{
// expanded to ( ( ( v1 + v2 ) + v3 ) + ... )
return ( ... + args );
}
/**
* Example 2
* Specialization of Example 1
* -> also works with nontype template parameters
*/
template < int... Args >
constexpr auto foo2()
{
// same expansion as above
return ( ... + Args );
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run