Debian Codegraph @

yo/advancedtemplates/examples/userdefined.cc

raw
1 #include <iostream>
2 using namespace std;
3
4 template <typename ...Chars>
5 double _kmh(Chars ...chars);
6
7 double _kmh()
8 {
9 return 0;
10 }
11
12 template<size_t n>
13 struct factor
14 {
15 enum { value = 10 * factor<n - 1>::value };
16 };
17
18 template<>
19 struct factor<0>
20 {
21 enum {value = 1};
22 };
23
24 template <typename ...Chars>
25 double _kmh(char c, Chars ...chars)
26 {
27 return (c - '0') * factor<sizeof...(Chars)>::value + _kmh(chars ...);
28 }
29
30 int main()
31 {
32 cout << _kmh('1', '2', '3') << '\n';
33 }