blob: cff78195c0a55c78abe16193567f8c7d9fc3aa5e [file] [log] [blame]
Brian Silvermanda861352019-02-02 16:42:28 -08001#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.
5#if (defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ <= 9 && \
6 !defined(__clang__))
7// nothing for now
8#else
9TEST_CASE("Triviality", "[bases.triviality]") {
10 REQUIRE(std::is_trivially_copy_constructible<tl::optional<int>>::value);
11 REQUIRE(std::is_trivially_copy_assignable<tl::optional<int>>::value);
12 REQUIRE(std::is_trivially_move_constructible<tl::optional<int>>::value);
13 REQUIRE(std::is_trivially_move_assignable<tl::optional<int>>::value);
14 REQUIRE(std::is_trivially_destructible<tl::optional<int>>::value);
15
16 {
17 struct T {
18 T(const T&) = default;
19 T(T&&) = default;
20 T& operator=(const T&) = default;
21 T& operator=(T&&) = default;
22 ~T() = default;
23 };
24 REQUIRE(std::is_trivially_copy_constructible<tl::optional<T>>::value);
25 REQUIRE(std::is_trivially_copy_assignable<tl::optional<T>>::value);
26 REQUIRE(std::is_trivially_move_constructible<tl::optional<T>>::value);
27 REQUIRE(std::is_trivially_move_assignable<tl::optional<T>>::value);
28 REQUIRE(std::is_trivially_destructible<tl::optional<T>>::value);
29 }
30
31 {
32 struct T {
33 T(const T&){}
34 T(T&&) {};
35 T& operator=(const T&) { return *this; }
36 T& operator=(T&&) { return *this; };
37 ~T(){}
38 };
39 REQUIRE(!std::is_trivially_copy_constructible<tl::optional<T>>::value);
40 REQUIRE(!std::is_trivially_copy_assignable<tl::optional<T>>::value);
41 REQUIRE(!std::is_trivially_move_constructible<tl::optional<T>>::value);
42 REQUIRE(!std::is_trivially_move_assignable<tl::optional<T>>::value);
43 REQUIRE(!std::is_trivially_destructible<tl::optional<T>>::value);
44 }
45
46}
47
48TEST_CASE("Deletion", "[bases.deletion]") {
49 REQUIRE(std::is_copy_constructible<tl::optional<int>>::value);
50 REQUIRE(std::is_copy_assignable<tl::optional<int>>::value);
51 REQUIRE(std::is_move_constructible<tl::optional<int>>::value);
52 REQUIRE(std::is_move_assignable<tl::optional<int>>::value);
53 REQUIRE(std::is_destructible<tl::optional<int>>::value);
54
55 {
56 struct T {
57 T(const T&) = default;
58 T(T&&) = default;
59 T& operator=(const T&) = default;
60 T& operator=(T&&) = default;
61 ~T() = default;
62 };
63 REQUIRE(std::is_copy_constructible<tl::optional<T>>::value);
64 REQUIRE(std::is_copy_assignable<tl::optional<T>>::value);
65 REQUIRE(std::is_move_constructible<tl::optional<T>>::value);
66 REQUIRE(std::is_move_assignable<tl::optional<T>>::value);
67 REQUIRE(std::is_destructible<tl::optional<T>>::value);
68 }
69
70 {
71 struct T {
72 T(const T&)=delete;
73 T(T&&)=delete;
74 T& operator=(const T&)=delete;
75 T& operator=(T&&)=delete;
76 };
77 REQUIRE(!std::is_copy_constructible<tl::optional<T>>::value);
78 REQUIRE(!std::is_copy_assignable<tl::optional<T>>::value);
79 REQUIRE(!std::is_move_constructible<tl::optional<T>>::value);
80 REQUIRE(!std::is_move_assignable<tl::optional<T>>::value);
81 }
82
83 {
84 struct T {
85 T(const T&)=delete;
86 T(T&&)=default;
87 T& operator=(const T&)=delete;
88 T& operator=(T&&)=default;
89 };
90 REQUIRE(!std::is_copy_constructible<tl::optional<T>>::value);
91 REQUIRE(!std::is_copy_assignable<tl::optional<T>>::value);
92 REQUIRE(std::is_move_constructible<tl::optional<T>>::value);
93 REQUIRE(std::is_move_assignable<tl::optional<T>>::value);
94 }
95
96 {
97 struct T {
98 T(const T&)=default;
99 T(T&&)=delete;
100 T& operator=(const T&)=default;
101 T& operator=(T&&)=delete;
102 };
103 REQUIRE(std::is_copy_constructible<tl::optional<T>>::value);
104 REQUIRE(std::is_copy_assignable<tl::optional<T>>::value);
105 }
106}
107#endif