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 | |
parent | b50f1549701eb950921e5d6f2e55ba1a1dadbb43 (diff) |
Notes
Diffstat (limited to 'test/std/utilities/tuple/tuple.tuple/tuple.assign')
6 files changed, 155 insertions, 36 deletions
diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.assign/const_pair.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.assign/const_pair.pass.cpp index a3d14487b47d..a66fba22d919 100644 --- a/test/std/utilities/tuple/tuple.tuple/tuple.assign/const_pair.pass.cpp +++ b/test/std/utilities/tuple/tuple.tuple/tuple.assign/const_pair.pass.cpp @@ -23,9 +23,9 @@ int main() { { - typedef std::pair<double, char> T0; - typedef std::tuple<int, short> T1; - T0 t0(2.5, 'a'); + typedef std::pair<long, char> T0; + typedef std::tuple<long long, short> T1; + T0 t0(2, 'a'); T1 t1; t1 = t0; assert(std::get<0>(t1) == 2); diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_copy.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_copy.pass.cpp index 91892efaf139..85dcee893a07 100644 --- a/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_copy.pass.cpp +++ b/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_copy.pass.cpp @@ -36,26 +36,26 @@ struct D int main() { { - typedef std::tuple<double> T0; - typedef std::tuple<int> T1; - T0 t0(2.5); + typedef std::tuple<long> T0; + typedef std::tuple<long long> T1; + T0 t0(2); T1 t1; t1 = t0; assert(std::get<0>(t1) == 2); } { - typedef std::tuple<double, char> T0; - typedef std::tuple<int, int> T1; - T0 t0(2.5, 'a'); + typedef std::tuple<long, char> T0; + typedef std::tuple<long long, int> T1; + T0 t0(2, 'a'); T1 t1; t1 = t0; assert(std::get<0>(t1) == 2); assert(std::get<1>(t1) == int('a')); } { - typedef std::tuple<double, char, D> T0; - typedef std::tuple<int, int, B> T1; - T0 t0(2.5, 'a', D(3)); + typedef std::tuple<long, char, D> T0; + typedef std::tuple<long long, int, B> T1; + T0 t0(2, 'a', D(3)); T1 t1; t1 = t0; assert(std::get<0>(t1) == 2); @@ -65,10 +65,10 @@ int main() { D d(3); D d2(2); - typedef std::tuple<double, char, D&> T0; - typedef std::tuple<int, int, B&> T1; - T0 t0(2.5, 'a', d2); - T1 t1(1.5, 'b', d); + typedef std::tuple<long, char, D&> T0; + typedef std::tuple<long long, int, B&> T1; + T0 t0(2, 'a', d2); + T1 t1(1, 'b', d); t1 = t0; assert(std::get<0>(t1) == 2); assert(std::get<1>(t1) == int('a')); diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_move.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_move.pass.cpp index afd3e0fdb8e3..1a32acd55cff 100644 --- a/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_move.pass.cpp +++ b/test/std/utilities/tuple/tuple.tuple/tuple.assign/convert_move.pass.cpp @@ -39,7 +39,7 @@ struct D struct E { E() = default; - E& operator=(int val) { + E& operator=(int) { return *this; } }; @@ -47,26 +47,26 @@ struct E { int main() { { - typedef std::tuple<double> T0; - typedef std::tuple<int> T1; - T0 t0(2.5); + typedef std::tuple<long> T0; + typedef std::tuple<long long> T1; + T0 t0(2); T1 t1; t1 = std::move(t0); assert(std::get<0>(t1) == 2); } { - typedef std::tuple<double, char> T0; - typedef std::tuple<int, int> T1; - T0 t0(2.5, 'a'); + typedef std::tuple<long, char> T0; + typedef std::tuple<long long, int> T1; + T0 t0(2, 'a'); T1 t1; t1 = std::move(t0); assert(std::get<0>(t1) == 2); assert(std::get<1>(t1) == int('a')); } { - typedef std::tuple<double, char, D> T0; - typedef std::tuple<int, int, B> T1; - T0 t0(2.5, 'a', D(3)); + typedef std::tuple<long, char, D> T0; + typedef std::tuple<long long, int, B> T1; + T0 t0(2, 'a', D(3)); T1 t1; t1 = std::move(t0); assert(std::get<0>(t1) == 2); @@ -76,19 +76,19 @@ int main() { D d(3); D d2(2); - typedef std::tuple<double, char, D&> T0; - typedef std::tuple<int, int, B&> T1; - T0 t0(2.5, 'a', d2); - T1 t1(1.5, 'b', d); + typedef std::tuple<long, char, D&> T0; + typedef std::tuple<long long, int, B&> T1; + T0 t0(2, 'a', d2); + T1 t1(1, 'b', d); t1 = std::move(t0); assert(std::get<0>(t1) == 2); assert(std::get<1>(t1) == int('a')); assert(std::get<2>(t1).id_ == 2); } { - typedef std::tuple<double, char, std::unique_ptr<D>> T0; - typedef std::tuple<int, int, std::unique_ptr<B>> T1; - T0 t0(2.5, 'a', std::unique_ptr<D>(new D(3))); + typedef std::tuple<long, char, std::unique_ptr<D>> T0; + typedef std::tuple<long long, int, std::unique_ptr<B>> T1; + T0 t0(2, 'a', std::unique_ptr<D>(new D(3))); T1 t1; t1 = std::move(t0); assert(std::get<0>(t1) == 2); 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, ""); + } } diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.assign/move.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.assign/move.pass.cpp index fc5e41ad569d..210f14be318a 100644 --- a/test/std/utilities/tuple/tuple.tuple/tuple.assign/move.pass.cpp +++ b/test/std/utilities/tuple/tuple.tuple/tuple.assign/move.pass.cpp @@ -21,6 +21,33 @@ #include "MoveOnly.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; +}; + + +struct CountAssign { + static int copied; + static int moved; + static void reset() { copied = moved = 0; } + CountAssign() = default; + CountAssign& operator=(CountAssign const&) { ++copied; return *this; } + CountAssign& operator=(CountAssign&&) { ++moved; return *this; } +}; +int CountAssign::copied = 0; +int CountAssign::moved = 0; + + int main() { { @@ -53,4 +80,46 @@ int main() assert(std::get<1>(t) == 1); assert(std::get<2>(t) == 2); } + { + // 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 = std::move(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 move assignment operator + // is properly deleted + using T = std::tuple<std::unique_ptr<int>>; + static_assert(std::is_move_assignable<T>::value, ""); + static_assert(!std::is_copy_assignable<T>::value, ""); + + } + { + using T = std::tuple<int, NonAssignable>; + static_assert(!std::is_move_assignable<T>::value, ""); + } + { + using T = std::tuple<int, MoveAssignable>; + static_assert(std::is_move_assignable<T>::value, ""); + } + { + // The move should decay to a copy. + CountAssign::reset(); + using T = std::tuple<CountAssign, CopyAssignable>; + static_assert(std::is_move_assignable<T>::value, ""); + T t1; + T t2; + t1 = std::move(t2); + assert(CountAssign::copied == 1); + assert(CountAssign::moved == 0); + } } diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.assign/move_pair.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.assign/move_pair.pass.cpp index 812e6329bb3e..27656a675982 100644 --- a/test/std/utilities/tuple/tuple.tuple/tuple.assign/move_pair.pass.cpp +++ b/test/std/utilities/tuple/tuple.tuple/tuple.assign/move_pair.pass.cpp @@ -39,9 +39,9 @@ struct D int main() { { - typedef std::pair<double, std::unique_ptr<D>> T0; - typedef std::tuple<int, std::unique_ptr<B>> T1; - T0 t0(2.5, std::unique_ptr<D>(new D(3))); + typedef std::pair<long, std::unique_ptr<D>> T0; + typedef std::tuple<long long, std::unique_ptr<B>> T1; + T0 t0(2, std::unique_ptr<D>(new D(3))); T1 t1; t1 = std::move(t0); assert(std::get<0>(t1) == 2); |