| 1 |
#include <string> |
| 2 |
#include <iostream> |
| 3 |
|
| 4 |
#include "multi.h" |
| 5 |
|
| 6 |
using namespace std; |
| 7 |
|
| 8 |
//POLICY |
| 9 |
template <typename Type> |
| 10 |
struct Policy |
| 11 |
{ |
| 12 |
Type d_type; |
| 13 |
Policy(Type &&type) |
| 14 |
: |
| 15 |
d_type(std::forward<Type>(type)) |
| 16 |
{} |
| 17 |
}; |
| 18 |
//= |
| 19 |
|
| 20 |
int main() |
| 21 |
{ |
| 22 |
//ONE |
| 23 |
Multi<Policy, string> ms{ Policy<string>{ "hello" } }; |
| 24 |
Multi<Policy, string, string> ms2s{ Policy<string>{ "hello" }, |
| 25 |
Policy<string>{ "world" } }; |
| 26 |
|
| 27 |
|
| 28 |
using MPSI = Multi<Policy, string, int>; |
| 29 |
MPSI mpsi{ string{ "hello" }, 4 }; |
| 30 |
//= |
| 31 |
|
| 32 |
//TWO |
| 33 |
cout << "There are " << MPSI::size << " types in MPSI\n" |
| 34 |
"There are " << mpsi.size << " types in mpsi\n"; |
| 35 |
//= |
| 36 |
|
| 37 |
//THREE |
| 38 |
plainTypeAt<0, MPSI>::Type sx = "String type"; |
| 39 |
plainTypeAt<1, MPSI>::Type ix = 12; |
| 40 |
//= |
| 41 |
|
| 42 |
//FIVE |
| 43 |
cout << static_cast<Policy<string> &>(mpsi).d_type << '\n' << |
| 44 |
static_cast<Policy<int> &>(mpsi).d_type << '\n'; |
| 45 |
//= |
| 46 |
|
| 47 |
//SIX |
| 48 |
using MPII = Multi<Policy, int, int>; |
| 49 |
MPII mpii{ 4, 18 }; |
| 50 |
|
| 51 |
cout << get<0>(mpii).d_type << ' ' << get<1>(mpii).d_type << '\n'; |
| 52 |
//= |
| 53 |
|
| 54 |
get<0>(mpii).d_type = get<1>(mpii).d_type; |
| 55 |
cout << get<0>(mpii).d_type << ' ' << get<1>(mpii).d_type << '\n'; |
| 56 |
|
| 57 |
//SEVEN |
| 58 |
using MVID = Multi<Vector, int, double>; |
| 59 |
MVID mi{ {1, 2, 3}, {1.2, 3.4, 5.6, 7.8} }; |
| 60 |
//= |
| 61 |
|
| 62 |
//EIGHT |
| 63 |
typeAt<0, Multi<Vector, int>>::Type vi = {1, 2, 3}; |
| 64 |
//= |
| 65 |
|
| 66 |
//NINE |
| 67 |
cout << get<0>(mi)[2] << '\n'; |
| 68 |
get<1>(mi)[3] = get<0>(mi)[0]; |
| 69 |
cout << get<1>(mi)[3] << '\n'; |
| 70 |
//= |
| 71 |
|
| 72 |
// cout << "Using get<0>(mpsi): " << get<0>(mpsi).d_type << '\n'; |
| 73 |
// cout << "Using get<1>(mpsi): " << get<1>(mpsi).d_type << '\n'; |
| 74 |
// Policy<int> pi = get<1>(mpsi); |
| 75 |
|
| 76 |
// cout << static_cast<Vector<int> &>(mi)[2] << '\n'; |
| 77 |
// static_cast<Vector<int> &>(mi)[2] = 18; |
| 78 |
// cout << static_cast<Vector<int> &>(mi)[2] << '\n'; |
| 79 |
|
| 80 |
} |