Skip to content

Commit 2468058

Browse files
authored
Merge pull request #7 from TartanLlama/void_support
Void support
2 parents 07f7b57 + 6a0a4f8 commit 2468058

File tree

4 files changed

+332
-160
lines changed

4 files changed

+332
-160
lines changed

tests/bases.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ TEST_CASE("Triviality", "[bases.triviality]") {
1515
REQUIRE(std::is_trivially_move_assignable<tl::expected<int,int>>::value);
1616
REQUIRE(std::is_trivially_destructible<tl::expected<int,int>>::value);
1717

18+
REQUIRE(std::is_trivially_copy_constructible<tl::expected<void,int>>::value);
19+
REQUIRE(std::is_trivially_move_constructible<tl::expected<void,int>>::value);
20+
REQUIRE(std::is_trivially_destructible<tl::expected<void,int>>::value);
21+
22+
1823
{
1924
struct T {
2025
T(const T&) = default;
@@ -127,8 +132,8 @@ TEST_CASE("Deletion", "[bases.deletion]") {
127132
REQUIRE(std::is_move_constructible<decltype(e)>::value);
128133
REQUIRE(std::is_copy_assignable<decltype(e)>::value);
129134
REQUIRE(std::is_move_assignable<decltype(e)>::value);
130-
REQUIRE(IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e)));
131-
REQUIRE(IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e)));
135+
REQUIRE(IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e))::value);
136+
REQUIRE(IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e))::value);
132137
# if !defined(TL_EXPECTED_GCC49)
133138
REQUIRE(std::is_trivially_move_constructible<decltype(e)>::value);
134139
REQUIRE(std::is_trivially_move_assignable<decltype(e)>::value);
@@ -142,8 +147,8 @@ TEST_CASE("Deletion", "[bases.deletion]") {
142147
REQUIRE(std::is_move_constructible<decltype(e)>::value);
143148
REQUIRE(std::is_copy_assignable<decltype(e)>::value);
144149
REQUIRE(std::is_move_assignable<decltype(e)>::value);
145-
REQUIRE(!IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e)));
146-
REQUIRE(!IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e)));
150+
REQUIRE(!IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e))::value);
151+
REQUIRE(!IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e))::value);
147152
# if !defined(TL_EXPECTED_GCC49)
148153
REQUIRE(!std::is_trivially_move_constructible<decltype(e)>::value);
149154
REQUIRE(!std::is_trivially_move_assignable<decltype(e)>::value);
@@ -157,8 +162,8 @@ TEST_CASE("Deletion", "[bases.deletion]") {
157162
REQUIRE(std::is_move_constructible<decltype(e)>::value);
158163
REQUIRE(std::is_copy_assignable<decltype(e)>::value);
159164
REQUIRE(std::is_move_assignable<decltype(e)>::value);
160-
REQUIRE(!IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e)));
161-
REQUIRE(!IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e)));
165+
REQUIRE(!IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e))::value);
166+
REQUIRE(!IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e))::value);
162167
# if !defined(TL_EXPECTED_GCC49)
163168
REQUIRE(!std::is_trivially_move_constructible<decltype(e)>::value);
164169
REQUIRE(!std::is_trivially_move_assignable<decltype(e)>::value);
@@ -172,8 +177,8 @@ TEST_CASE("Deletion", "[bases.deletion]") {
172177
REQUIRE(std::is_move_constructible<decltype(e)>::value);
173178
REQUIRE(std::is_copy_assignable<decltype(e)>::value);
174179
REQUIRE(std::is_move_assignable<decltype(e)>::value);
175-
REQUIRE(!IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e)));
176-
REQUIRE(!IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e)));
180+
REQUIRE(!IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e))::value);
181+
REQUIRE(!IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e))::value);
177182
# if !defined(TL_EXPECTED_GCC49)
178183
REQUIRE(!std::is_trivially_move_constructible<decltype(e)>::value);
179184
REQUIRE(!std::is_trivially_move_assignable<decltype(e)>::value);

tests/constructors.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ TEST_CASE("Constructors", "[constructors]") {
6868
REQUIRE(std::is_move_constructible<decltype(e)>::value);
6969
REQUIRE(std::is_copy_assignable<decltype(e)>::value);
7070
REQUIRE(std::is_move_assignable<decltype(e)>::value);
71-
REQUIRE(IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e)));
72-
REQUIRE(IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e)));
71+
REQUIRE(IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e))::value);
72+
REQUIRE(IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e))::value);
7373
# if !defined(TL_EXPECTED_GCC49)
7474
REQUIRE(std::is_trivially_move_constructible<decltype(e)>::value);
7575
REQUIRE(std::is_trivially_move_assignable<decltype(e)>::value);
@@ -83,8 +83,8 @@ TEST_CASE("Constructors", "[constructors]") {
8383
REQUIRE(std::is_move_constructible<decltype(e)>::value);
8484
REQUIRE(std::is_copy_assignable<decltype(e)>::value);
8585
REQUIRE(std::is_move_assignable<decltype(e)>::value);
86-
REQUIRE(!IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e)));
87-
REQUIRE(!IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e)));
86+
REQUIRE(!IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e))::value);
87+
REQUIRE(!IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e))::value);
8888
# if !defined(TL_EXPECTED_GCC49)
8989
REQUIRE(!std::is_trivially_move_constructible<decltype(e)>::value);
9090
REQUIRE(!std::is_trivially_move_assignable<decltype(e)>::value);
@@ -98,8 +98,8 @@ TEST_CASE("Constructors", "[constructors]") {
9898
REQUIRE(std::is_move_constructible<decltype(e)>::value);
9999
REQUIRE(std::is_copy_assignable<decltype(e)>::value);
100100
REQUIRE(std::is_move_assignable<decltype(e)>::value);
101-
REQUIRE(!IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e)));
102-
REQUIRE(!IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e)));
101+
REQUIRE(!IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e))::value);
102+
REQUIRE(!IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e))::value);
103103
# if !defined(TL_EXPECTED_GCC49)
104104
REQUIRE(!std::is_trivially_move_constructible<decltype(e)>::value);
105105
REQUIRE(!std::is_trivially_move_assignable<decltype(e)>::value);
@@ -113,11 +113,22 @@ TEST_CASE("Constructors", "[constructors]") {
113113
REQUIRE(std::is_move_constructible<decltype(e)>::value);
114114
REQUIRE(std::is_copy_assignable<decltype(e)>::value);
115115
REQUIRE(std::is_move_assignable<decltype(e)>::value);
116-
REQUIRE(!IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e)));
117-
REQUIRE(!IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e)));
116+
REQUIRE(!IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e))::value);
117+
REQUIRE(!IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e))::value);
118118
# if !defined(TL_EXPECTED_GCC49)
119119
REQUIRE(!std::is_trivially_move_constructible<decltype(e)>::value);
120120
REQUIRE(!std::is_trivially_move_assignable<decltype(e)>::value);
121121
# endif
122122
}
123+
124+
{
125+
tl::expected<void,int> e;
126+
REQUIRE(e);
127+
}
128+
129+
{
130+
tl::expected<void,int> e (tl::unexpect, 42);
131+
REQUIRE(!e);
132+
REQUIRE(e.error() == 42);
133+
}
123134
}

tests/extensions.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,63 +72,63 @@ TEST_CASE("Map extensions", "[extensions.map]") {
7272
auto ret = e.map(ret_void);
7373
REQUIRE(ret);
7474
STATIC_REQUIRE(
75-
(std::is_same<decltype(ret), tl::expected<tl::monostate, int>>::value));
75+
(std::is_same<decltype(ret), tl::expected<void, int>>::value));
7676
}
7777

7878
{
7979
const tl::expected<int, int> e = 21;
8080
auto ret = e.map(ret_void);
8181
REQUIRE(ret);
8282
STATIC_REQUIRE(
83-
(std::is_same<decltype(ret), tl::expected<tl::monostate, int>>::value));
83+
(std::is_same<decltype(ret), tl::expected<void, int>>::value));
8484
}
8585

8686
{
8787
tl::expected<int, int> e = 21;
8888
auto ret = std::move(e).map(ret_void);
8989
REQUIRE(ret);
9090
STATIC_REQUIRE(
91-
(std::is_same<decltype(ret), tl::expected<tl::monostate, int>>::value));
91+
(std::is_same<decltype(ret), tl::expected<void, int>>::value));
9292
}
9393

9494
{
9595
const tl::expected<int, int> e = 21;
9696
auto ret = std::move(e).map(ret_void);
9797
REQUIRE(ret);
9898
STATIC_REQUIRE(
99-
(std::is_same<decltype(ret), tl::expected<tl::monostate, int>>::value));
99+
(std::is_same<decltype(ret), tl::expected<void, int>>::value));
100100
}
101101

102102
{
103103
tl::expected<int, int> e(tl::unexpect, 21);
104104
auto ret = e.map(ret_void);
105105
REQUIRE(!ret);
106106
STATIC_REQUIRE(
107-
(std::is_same<decltype(ret), tl::expected<tl::monostate, int>>::value));
107+
(std::is_same<decltype(ret), tl::expected<void, int>>::value));
108108
}
109109

110110
{
111111
const tl::expected<int, int> e(tl::unexpect, 21);
112112
auto ret = e.map(ret_void);
113113
REQUIRE(!ret);
114114
STATIC_REQUIRE(
115-
(std::is_same<decltype(ret), tl::expected<tl::monostate, int>>::value));
115+
(std::is_same<decltype(ret), tl::expected<void, int>>::value));
116116
}
117117

118118
{
119119
tl::expected<int, int> e(tl::unexpect, 21);
120120
auto ret = std::move(e).map(ret_void);
121121
REQUIRE(!ret);
122122
STATIC_REQUIRE(
123-
(std::is_same<decltype(ret), tl::expected<tl::monostate, int>>::value));
123+
(std::is_same<decltype(ret), tl::expected<void, int>>::value));
124124
}
125125

126126
{
127127
const tl::expected<int, int> e(tl::unexpect, 21);
128128
auto ret = std::move(e).map(ret_void);
129129
REQUIRE(!ret);
130130
STATIC_REQUIRE(
131-
(std::is_same<decltype(ret), tl::expected<tl::monostate, int>>::value));
131+
(std::is_same<decltype(ret), tl::expected<void, int>>::value));
132132
}
133133

134134

0 commit comments

Comments
 (0)