-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.cpp
54 lines (51 loc) · 1.36 KB
/
test.cpp
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*********************************************************
File Name:test.cpp
Author: Abby Cin
Mail: [email protected]
Created Time: Mon 21 Nov 2016 09:55:05 PM CST
**********************************************************/
#include "fake_variant.h"
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
struct NonCopyMoveable {
NonCopyMoveable(int x) : data_(x)
{
}
NonCopyMoveable(const NonCopyMoveable &) = delete;
NonCopyMoveable(NonCopyMoveable &&) = delete;
NonCopyMoveable &operator=(const NonCopyMoveable &) = delete;
NonCopyMoveable &operator=(NonCopyMoveable &&) = delete;
int data_;
};
// ignore extra `int`
nm::FakeVariant<int,
int,
NonCopyMoveable,
int,
const char *,
double,
vector<string>>
va;
va.set<int>(10);
va.set<NonCopyMoveable>(309);
va.set<const char *>("+1s");
va.set<double>(3.09);
// call `set(const T&)`
va.set<vector<string>>({ "old", "value" });
// call `set(Para&&...)`
auto res = va.set<vector<string>, std::initializer_list<string>>(
{ "this", " is", " a", " test." });
if (!res)
cout << "override exist value!\n";
cout << va.get<int>() << endl;
cout << va.get<NonCopyMoveable>().data_ << endl;
cout << va.get<const char *>() << endl;
cout << va.get<double>() << endl;
for (const auto &x : va.get<vector<string>>())
cout << x;
cout << endl;
}