| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| |
|
| | #include <utility> |
| | #include <type_traits> |
| | #include <cassert> |
| |
|
| | #include "test_macros.h" |
| |
|
| | class move_only |
| | { |
| | move_only(const move_only&); |
| | move_only& operator=(const move_only&); |
| | public: |
| | move_only(move_only&&) {} |
| | move_only& operator=(move_only&&) {return *this;} |
| |
|
| | move_only() {} |
| | }; |
| |
|
| | move_only source() {return move_only();} |
| | const move_only csource() {return move_only();} |
| |
|
| | void test(move_only) {} |
| |
|
| | int x = 42; |
| | const int& cx = x; |
| |
|
| | template <class QualInt> |
| | QualInt get() TEST_NOEXCEPT { return static_cast<QualInt>(x); } |
| |
|
| |
|
| | int copy_ctor = 0; |
| | int move_ctor = 0; |
| |
|
| | struct A { |
| | A() {} |
| | A(const A&) {++copy_ctor;} |
| | A(A&&) {++move_ctor;} |
| | A& operator=(const A&) = delete; |
| | }; |
| |
|
| | #if TEST_STD_VER > 11 |
| | constexpr bool test_constexpr_move() { |
| | int y = 42; |
| | const int cy = y; |
| | return std::move(y) == 42 |
| | && std::move(cy) == 42 |
| | && std::move(static_cast<int&&>(y)) == 42 |
| | && std::move(static_cast<int const&&>(y)) == 42; |
| | } |
| | #endif |
| | int main(int, char**) |
| | { |
| | { |
| | static_assert(std::is_same<decltype(std::move(x)), int&&>::value, ""); |
| | ASSERT_NOEXCEPT(std::move(x)); |
| | static_assert(std::is_same<decltype(std::move(cx)), const int&&>::value, ""); |
| | ASSERT_NOEXCEPT(std::move(cx)); |
| | static_assert(std::is_same<decltype(std::move(42)), int&&>::value, ""); |
| | ASSERT_NOEXCEPT(std::move(42)); |
| | static_assert(std::is_same<decltype(std::move(get<const int&&>())), const int&&>::value, ""); |
| | ASSERT_NOEXCEPT(std::move(get<int const&&>())); |
| | } |
| | { |
| | A a; |
| | const A ca = A(); |
| |
|
| | assert(copy_ctor == 0); |
| | assert(move_ctor == 0); |
| |
|
| | A a2 = a; |
| | assert(copy_ctor == 1); |
| | assert(move_ctor == 0); |
| |
|
| | A a3 = std::move(a); |
| | assert(copy_ctor == 1); |
| | assert(move_ctor == 1); |
| |
|
| | A a4 = ca; |
| | assert(copy_ctor == 2); |
| | assert(move_ctor == 1); |
| |
|
| | A a5 = std::move(ca); |
| | assert(copy_ctor == 3); |
| | assert(move_ctor == 1); |
| | } |
| | { |
| | move_only mo; |
| | test(std::move(mo)); |
| | test(source()); |
| | } |
| | #if TEST_STD_VER > 11 |
| | { |
| | constexpr int y = 42; |
| | static_assert(std::move(y) == 42, ""); |
| | static_assert(test_constexpr_move(), ""); |
| | } |
| | #endif |
| | #if TEST_STD_VER == 11 && defined(_LIBCUDACXX_VERSION) |
| | |
| | |
| | { |
| | constexpr int y = 42; |
| | static_assert(std::move(y) == 42, ""); |
| | } |
| | #endif |
| |
|
| | return 0; |
| | } |
| |
|