1 #include "FoldExpressions.h"
7 // Ep 20: https://www.youtube.com/watch?v=nhk8pF_SlTk
8 // https://en.cppreference.com/w/cpp/language/fold
10 namespace FoldExpressions
12 // Old fashion (before C++17).
13 template<typename
... T
>
16 typename common_type
<T
...>::type result
{};
17 initializer_list
<int>{ (result
+= t
, 0)... };
22 template<typename
... T
>
29 template<typename
... T
>
32 return (t
+ ...) / sizeof...(t
);
36 void FoldExpressions::tests()
38 cout
<< sum(1, 2.2, 3, 4, 5) << endl
;
39 cout
<< sum2(1, 2.2, 3, 4, 5) << endl
;
41 cout
<< avg(1, 2.2, 3, 4, 5) << endl
;