Brian Silverman | da86135 | 2019-02-02 16:42:28 -0800 | [diff] [blame] | 1 | #include "catch.hpp" |
| 2 | #include "optional.hpp" |
| 3 | |
| 4 | // Old versions of GCC don't have the correct trait names. Could fix them up if needs be. |
Brian Silverman | 019de8b | 2019-02-02 16:55:30 -0800 | [diff] [blame] | 5 | #ifdef TL_OPTIONAL_GCC49 |
Brian Silverman | da86135 | 2019-02-02 16:42:28 -0800 | [diff] [blame] | 6 | // nothing for now |
| 7 | #else |
| 8 | TEST_CASE("Triviality", "[bases.triviality]") { |
| 9 | REQUIRE(std::is_trivially_copy_constructible<tl::optional<int>>::value); |
| 10 | REQUIRE(std::is_trivially_copy_assignable<tl::optional<int>>::value); |
| 11 | REQUIRE(std::is_trivially_move_constructible<tl::optional<int>>::value); |
| 12 | REQUIRE(std::is_trivially_move_assignable<tl::optional<int>>::value); |
| 13 | REQUIRE(std::is_trivially_destructible<tl::optional<int>>::value); |
| 14 | |
| 15 | { |
| 16 | struct T { |
| 17 | T(const T&) = default; |
| 18 | T(T&&) = default; |
| 19 | T& operator=(const T&) = default; |
| 20 | T& operator=(T&&) = default; |
| 21 | ~T() = default; |
| 22 | }; |
| 23 | REQUIRE(std::is_trivially_copy_constructible<tl::optional<T>>::value); |
| 24 | REQUIRE(std::is_trivially_copy_assignable<tl::optional<T>>::value); |
| 25 | REQUIRE(std::is_trivially_move_constructible<tl::optional<T>>::value); |
| 26 | REQUIRE(std::is_trivially_move_assignable<tl::optional<T>>::value); |
| 27 | REQUIRE(std::is_trivially_destructible<tl::optional<T>>::value); |
| 28 | } |
| 29 | |
| 30 | { |
| 31 | struct T { |
| 32 | T(const T&){} |
| 33 | T(T&&) {}; |
| 34 | T& operator=(const T&) { return *this; } |
| 35 | T& operator=(T&&) { return *this; }; |
| 36 | ~T(){} |
| 37 | }; |
| 38 | REQUIRE(!std::is_trivially_copy_constructible<tl::optional<T>>::value); |
| 39 | REQUIRE(!std::is_trivially_copy_assignable<tl::optional<T>>::value); |
| 40 | REQUIRE(!std::is_trivially_move_constructible<tl::optional<T>>::value); |
| 41 | REQUIRE(!std::is_trivially_move_assignable<tl::optional<T>>::value); |
| 42 | REQUIRE(!std::is_trivially_destructible<tl::optional<T>>::value); |
| 43 | } |
| 44 | |
| 45 | } |
| 46 | |
| 47 | TEST_CASE("Deletion", "[bases.deletion]") { |
| 48 | REQUIRE(std::is_copy_constructible<tl::optional<int>>::value); |
| 49 | REQUIRE(std::is_copy_assignable<tl::optional<int>>::value); |
| 50 | REQUIRE(std::is_move_constructible<tl::optional<int>>::value); |
| 51 | REQUIRE(std::is_move_assignable<tl::optional<int>>::value); |
| 52 | REQUIRE(std::is_destructible<tl::optional<int>>::value); |
| 53 | |
| 54 | { |
| 55 | struct T { |
| 56 | T(const T&) = default; |
| 57 | T(T&&) = default; |
| 58 | T& operator=(const T&) = default; |
| 59 | T& operator=(T&&) = default; |
| 60 | ~T() = default; |
| 61 | }; |
| 62 | REQUIRE(std::is_copy_constructible<tl::optional<T>>::value); |
| 63 | REQUIRE(std::is_copy_assignable<tl::optional<T>>::value); |
| 64 | REQUIRE(std::is_move_constructible<tl::optional<T>>::value); |
| 65 | REQUIRE(std::is_move_assignable<tl::optional<T>>::value); |
| 66 | REQUIRE(std::is_destructible<tl::optional<T>>::value); |
| 67 | } |
| 68 | |
| 69 | { |
| 70 | struct T { |
| 71 | T(const T&)=delete; |
| 72 | T(T&&)=delete; |
| 73 | T& operator=(const T&)=delete; |
| 74 | T& operator=(T&&)=delete; |
| 75 | }; |
| 76 | REQUIRE(!std::is_copy_constructible<tl::optional<T>>::value); |
| 77 | REQUIRE(!std::is_copy_assignable<tl::optional<T>>::value); |
| 78 | REQUIRE(!std::is_move_constructible<tl::optional<T>>::value); |
| 79 | REQUIRE(!std::is_move_assignable<tl::optional<T>>::value); |
| 80 | } |
| 81 | |
| 82 | { |
| 83 | struct T { |
| 84 | T(const T&)=delete; |
| 85 | T(T&&)=default; |
| 86 | T& operator=(const T&)=delete; |
| 87 | T& operator=(T&&)=default; |
| 88 | }; |
| 89 | REQUIRE(!std::is_copy_constructible<tl::optional<T>>::value); |
| 90 | REQUIRE(!std::is_copy_assignable<tl::optional<T>>::value); |
| 91 | REQUIRE(std::is_move_constructible<tl::optional<T>>::value); |
| 92 | REQUIRE(std::is_move_assignable<tl::optional<T>>::value); |
| 93 | } |
| 94 | |
| 95 | { |
| 96 | struct T { |
| 97 | T(const T&)=default; |
| 98 | T(T&&)=delete; |
| 99 | T& operator=(const T&)=default; |
| 100 | T& operator=(T&&)=delete; |
| 101 | }; |
| 102 | REQUIRE(std::is_copy_constructible<tl::optional<T>>::value); |
| 103 | REQUIRE(std::is_copy_assignable<tl::optional<T>>::value); |
| 104 | } |
| 105 | } |
| 106 | #endif |