comparison 3rdparty/vmime/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-rvalue-references.cpp @ 0:a4671277546c tip

created the repository for the thymian project
author ferencd
date Tue, 17 Aug 2021 11:19:54 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:a4671277546c
1 #include <cassert>
2
3 class rvmove {
4 public:
5 void *ptr;
6 char *array;
7
8 rvmove()
9 : ptr(0),
10 array(new char[10])
11 {
12 ptr = this;
13 }
14
15 rvmove(rvmove &&other)
16 : ptr(other.ptr),
17 array(other.array)
18 {
19 other.array = 0;
20 other.ptr = 0;
21 }
22
23 ~rvmove()
24 {
25 assert(((ptr != 0) && (array != 0)) || ((ptr == 0) && (array == 0)));
26 delete[] array;
27 }
28
29 rvmove &operator=(rvmove &&other)
30 {
31 delete[] array;
32 ptr = other.ptr;
33 array = other.array;
34 other.array = 0;
35 other.ptr = 0;
36 return *this;
37 }
38
39 static rvmove create()
40 {
41 return rvmove();
42 }
43 private:
44 rvmove(const rvmove &);
45 rvmove &operator=(const rvmove &);
46 };
47
48 int main()
49 {
50 rvmove mine;
51 if (mine.ptr != &mine)
52 return 1;
53 mine = rvmove::create();
54 if (mine.ptr == &mine)
55 return 1;
56 return 0;
57 }