aboutsummaryrefslogtreecommitdiffstats
path: root/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-rvalue-references.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-rvalue-references.cpp')
-rw-r--r--cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-rvalue-references.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-rvalue-references.cpp b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-rvalue-references.cpp
new file mode 100644
index 00000000..e6e7e5a9
--- /dev/null
+++ b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-rvalue-references.cpp
@@ -0,0 +1,57 @@
+#include <cassert>
+
+class rvmove {
+public:
+ void *ptr;
+ char *array;
+
+ rvmove()
+ : ptr(0),
+ array(new char[10])
+ {
+ ptr = this;
+ }
+
+ rvmove(rvmove &&other)
+ : ptr(other.ptr),
+ array(other.array)
+ {
+ other.array = 0;
+ other.ptr = 0;
+ }
+
+ ~rvmove()
+ {
+ assert(((ptr != 0) && (array != 0)) || ((ptr == 0) && (array == 0)));
+ delete[] array;
+ }
+
+ rvmove &operator=(rvmove &&other)
+ {
+ delete[] array;
+ ptr = other.ptr;
+ array = other.array;
+ other.array = 0;
+ other.ptr = 0;
+ return *this;
+ }
+
+ static rvmove create()
+ {
+ return rvmove();
+ }
+private:
+ rvmove(const rvmove &);
+ rvmove &operator=(const rvmove &);
+};
+
+int main()
+{
+ rvmove mine;
+ if (mine.ptr != &mine)
+ return 1;
+ mine = rvmove::create();
+ if (mine.ptr == &mine)
+ return 1;
+ return 0;
+}