-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
61 lines (48 loc) · 1.1 KB
/
main.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
55
56
57
58
59
60
61
/*********************************************************
File Name: main.cpp
Author: Abby Cin
Mail: abbytsing@gmail.com
Created Time: Thu 04 Apr 2019 01:42:50 PM DST
**********************************************************/
#include "optional.h"
#include <iostream>
struct Bar {
explicit Bar(int z) : z_ { z }
{
}
virtual ~Bar()
{
}
int z_;
};
struct Foo : Bar {
Foo(int x, int y, int z) : Bar { z }, x_ { x }, y_ { y }
{
}
int x_;
int y_;
};
int main()
{
std::cerr << std::boolalpha;
Optional<Bar> b { Bar { 1 } };
Optional<Bar> h = b;
Optional<Foo> o { 1, 2, 3 };
Optional<Foo> l { Foo { 3, 2, 1 } };
std::cerr << (bool)l << '\t' << o->x_ << '\n';
o = std::move(l);
std::cerr << (bool)l << '\t' << o->x_ << '\n';
l = o;
std::cerr << (bool)l << '\t' << o->x_ << '\n';
l = Foo { 2, 2, 2 };
o = std::move(l);
std::cerr << (bool)l << '\t' << o->x_ << '\n';
Optional<Foo> m = o;
std::cerr << (bool)m << '\t' << m->x_ << '\n';
Optional<int> io { 1 };
Optional<int> ha {};
io = Optional<int>();
std::cerr << (bool)io << '\n';
io = ha;
std::cerr << (bool)io << '\n';
}