diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-01-02 19:18:58 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-01-02 19:18:58 +0000 |
commit | 53a420fba21cf1644972b34dcd811a43cdb8368d (patch) | |
tree | 66a19f6f8b65215772549a51d688492ab8addc0d /test/std/utilities/tuple/tuple.tuple/tuple.assign/copy.pass.cpp | |
parent | b50f1549701eb950921e5d6f2e55ba1a1dadbb43 (diff) |
Notes
Diffstat (limited to 'test/std/utilities/tuple/tuple.tuple/tuple.assign/copy.pass.cpp')
-rw-r--r-- | test/std/utilities/tuple/tuple.tuple/tuple.assign/copy.pass.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.assign/copy.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.assign/copy.pass.cpp index d5d020779726..edb235a41919 100644 --- a/test/std/utilities/tuple/tuple.tuple/tuple.assign/copy.pass.cpp +++ b/test/std/utilities/tuple/tuple.tuple/tuple.assign/copy.pass.cpp @@ -16,9 +16,26 @@ // UNSUPPORTED: c++98, c++03 #include <tuple> +#include <memory> #include <string> #include <cassert> +#include "test_macros.h" + +struct NonAssignable { + NonAssignable& operator=(NonAssignable const&) = delete; + NonAssignable& operator=(NonAssignable&&) = delete; +}; +struct CopyAssignable { + CopyAssignable& operator=(CopyAssignable const&) = default; + CopyAssignable& operator=(CopyAssignable &&) = delete; +}; +static_assert(std::is_copy_assignable<CopyAssignable>::value, ""); +struct MoveAssignable { + MoveAssignable& operator=(MoveAssignable const&) = delete; + MoveAssignable& operator=(MoveAssignable&&) = default; +}; + int main() { { @@ -51,4 +68,37 @@ int main() assert(std::get<1>(t) == 'a'); assert(std::get<2>(t) == "some text"); } + { + // test reference assignment. + using T = std::tuple<int&, int&&>; + int x = 42; + int y = 100; + int x2 = -1; + int y2 = 500; + T t(x, std::move(y)); + T t2(x2, std::move(y2)); + t = t2; + assert(std::get<0>(t) == x2); + assert(&std::get<0>(t) == &x); + assert(std::get<1>(t) == y2); + assert(&std::get<1>(t) == &y); + } + { + // test that the implicitly generated copy assignment operator + // is properly deleted + using T = std::tuple<std::unique_ptr<int>>; + static_assert(!std::is_copy_assignable<T>::value, ""); + } + { + using T = std::tuple<int, NonAssignable>; + static_assert(!std::is_copy_assignable<T>::value, ""); + } + { + using T = std::tuple<int, CopyAssignable>; + static_assert(std::is_copy_assignable<T>::value, ""); + } + { + using T = std::tuple<int, MoveAssignable>; + static_assert(!std::is_copy_assignable<T>::value, ""); + } } |