-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathvariadic_templates.cpp
More file actions
34 lines (30 loc) · 872 Bytes
/
variadic_templates.cpp
File metadata and controls
34 lines (30 loc) · 872 Bytes
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
29
30
31
32
33
34
//*****************************************************************************
//
// Author: Michael Price
// License: Attribution-NonCommercial-NoDerivs 3.0 Unported
// http://creativecommons.org/licenses/by-nc-nd/3.0/legalcode
//
//*****************************************************************************
#ifndef WIN32
namespace std {
class out {}; out cout; int endl;
out& operator<<(out & o, int t) { return o; }
}
#endif // WIN32
template <typename T, typename ... Params>
auto multiplier (T && t, Params ... params) ->
decltype(t * multiplier(params...))
{
return t * multiplier(params...);
}
template <typename T>
auto multiplier (T && t) -> T
{
return t;
}
void varying ()
{
std::cout << multiplier(10) << std::endl;
std::cout << multiplier(1, 2, 3) << std::endl;
std::cout << multiplier(6, 7.1, 8) << std::endl;
}