First commit
[cpp_sandbox.git] / Sandbox / VariadicUsing.cpp
1 #include "VariadicUsing.h"
2
3 #include <iostream>
4 using namespace std;
5
6 // Ep 48: https://www.youtube.com/watch?v=1gNzhE-Tn40
7
8 namespace VariadicUsing
9 {
10 template<typename ... B>
11 struct Merged : B...
12 {
13 template<typename ... T>
14 Merged(T&& ... t) : B(forward<T>(t))...
15 {
16 }
17
18 using B::operator()...; // It seems not necessary.
19 };
20
21 // Class template argument deduction: https://en.cppreference.com/w/cpp/language/class_template_argument_deduction.
22 template<typename ... T>
23 Merged(T...) -> Merged<decay_t<T>...>;
24 }
25
26 void VariadicUsing::tests()
27 {
28 // Lambda are standard type.
29 const auto l1 = []() { return 4; };
30 const auto l2 = [](const int i) { return i * 10; };
31
32 Merged merged(l1, l2, [](const double d) { return d * 3.2; });
33
34 cout << merged() << endl;
35 cout << merged(10) << endl;
36 cout << merged(10.5) << endl;
37 }