Skip to content

Commit 5badd44

Browse files
committed
Move old SMF functions to actual SMF body
1 parent ec07348 commit 5badd44

1 file changed

Lines changed: 81 additions & 109 deletions

File tree

‎include/iris/rvariant/rvariant.hpp‎

Lines changed: 81 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,18 @@ IRIS_RVARIANT_ALWAYS_THROWING_UNREACHABLE_END
209209
(!std::conjunction_v<std::is_trivially_copy_constructible<Ts>...>) &&
210210
std::conjunction_v<std::is_copy_constructible<Ts>...>
211211
{
212-
_copy_construct(w);
212+
constexpr bool is_noexcept = std::conjunction_v<std::is_nothrow_copy_constructible<Ts>...>;
213+
w.template raw_visit<is_noexcept>([this]<std::size_t j, class T>(std::in_place_index_t<j>, [[maybe_unused]] T const& alt)
214+
noexcept(is_noexcept)
215+
{
216+
if constexpr (j != std::variant_npos) {
217+
IRIS_RVARIANT_DISABLE_UNINITIALIZED_WARNING_BEGIN
218+
construct_on_valueless<j>(alt);
219+
IRIS_RVARIANT_DISABLE_UNINITIALIZED_WARNING_END
220+
} else {
221+
(void)this;
222+
}
223+
});
213224
}
214225

215226
rvariant_base(rvariant_base&&)
@@ -222,7 +233,19 @@ IRIS_RVARIANT_ALWAYS_THROWING_UNREACHABLE_END
222233
(!std::conjunction_v<std::is_trivially_move_constructible<Ts>...>) &&
223234
std::conjunction_v<std::is_move_constructible<Ts>...>
224235
{
225-
_move_construct(std::move(w));
236+
constexpr bool is_noexcept = std::conjunction_v<std::is_nothrow_move_constructible<Ts>...>;
237+
std::move(w).template raw_visit<is_noexcept>([this]<std::size_t j, class T>(std::in_place_index_t<j>, [[maybe_unused]] T&& alt)
238+
noexcept(is_noexcept)
239+
{
240+
if constexpr (j != std::variant_npos) {
241+
static_assert(std::is_rvalue_reference_v<T&&>);
242+
IRIS_RVARIANT_DISABLE_UNINITIALIZED_WARNING_BEGIN
243+
construct_on_valueless<j>(std::move(alt)); // NOLINT(bugprone-move-forwarding-reference)
244+
IRIS_RVARIANT_DISABLE_UNINITIALIZED_WARNING_END
245+
} else {
246+
(void)this;
247+
}
248+
});
226249
}
227250

228251
rvariant_base& operator=(rvariant_base const&)
@@ -258,7 +281,34 @@ IRIS_RVARIANT_ALWAYS_THROWING_UNREACHABLE_END
258281
>) &&
259282
std::conjunction_v<std::is_copy_constructible<Ts>..., std::is_copy_assignable<Ts>...>
260283
{
261-
_copy_assign(rhs);
284+
IRIS_RVARIANT_ALWAYS_THROWING_UNREACHABLE_BEGIN
285+
constexpr bool is_noexcept = std::conjunction_v<variant_nothrow_copy_assignable<Ts>...>;
286+
rhs.template raw_visit<is_noexcept>([this]<std::size_t j, class T>(std::in_place_index_t<j>, T const& rhs_alt)
287+
noexcept(is_noexcept)
288+
{
289+
if constexpr (j == std::variant_npos) {
290+
(void)rhs_alt;
291+
visit_reset();
292+
} else {
293+
IRIS_RVARIANT_DISABLE_UNINITIALIZED_WARNING_BEGIN
294+
if (index_ == j) {
295+
raw_get<j>(storage()) = rhs_alt;
296+
} else {
297+
// CC(noexcept) && MC(throw) => A
298+
// CC(noexcept) && MC(noexcept) => A
299+
// CC(throw) && MC(throw) => A
300+
// CC(throw) && MC(noexcept) => B
301+
if constexpr (std::is_nothrow_copy_constructible_v<T> || !std::is_nothrow_move_constructible_v<T>) {
302+
reset_construct<j>(rhs_alt); // A
303+
} else {
304+
T tmp(rhs_alt);
305+
reset_construct<j>(std::move(tmp)); // B
306+
}
307+
}
308+
IRIS_RVARIANT_DISABLE_UNINITIALIZED_WARNING_END
309+
}
310+
});
311+
IRIS_RVARIANT_ALWAYS_THROWING_UNREACHABLE_END
262312
return *this;
263313
}
264314

@@ -307,7 +357,25 @@ IRIS_RVARIANT_ALWAYS_THROWING_UNREACHABLE_END
307357
>) &&
308358
std::conjunction_v<std::is_move_constructible<Ts>..., std::is_move_assignable<Ts>...>
309359
{
310-
_move_assign(std::move(rhs));
360+
constexpr bool is_noexcept = std::conjunction_v<variant_nothrow_move_assignable<Ts>...>;
361+
std::move(rhs).template raw_visit<is_noexcept>([this]<std::size_t j, class T>(std::in_place_index_t<j>, [[maybe_unused]] T&& rhs_alt)
362+
noexcept(is_noexcept)
363+
{
364+
if constexpr (j == std::variant_npos) {
365+
(void)rhs_alt;
366+
visit_reset();
367+
} else {
368+
static_assert(std::is_rvalue_reference_v<T&&>);
369+
370+
IRIS_RVARIANT_DISABLE_UNINITIALIZED_WARNING_BEGIN
371+
if (index_ == j) {
372+
raw_get<j>(storage()) = std::move(rhs_alt); // NOLINT(bugprone-move-forwarding-reference)
373+
} else {
374+
reset_construct<j>(std::move(rhs_alt)); // NOLINT(bugprone-move-forwarding-reference)
375+
}
376+
IRIS_RVARIANT_DISABLE_UNINITIALIZED_WARNING_END
377+
}
378+
});
311379
return *this;
312380
}
313381

@@ -334,102 +402,6 @@ IRIS_RVARIANT_ALWAYS_THROWING_UNREACHABLE_END
334402
}
335403

336404
protected:
337-
// Copy constructor
338-
constexpr void _copy_construct(rvariant_base const& w)
339-
noexcept(std::conjunction_v<std::is_nothrow_copy_constructible<Ts>...>)
340-
{
341-
static constexpr bool is_noexcept = std::conjunction_v<std::is_nothrow_copy_constructible<Ts>...>;
342-
w.template raw_visit<is_noexcept>([this]<std::size_t j, class T>(std::in_place_index_t<j>, [[maybe_unused]] T const& alt)
343-
noexcept(is_noexcept)
344-
{
345-
if constexpr (j != std::variant_npos) {
346-
IRIS_RVARIANT_DISABLE_UNINITIALIZED_WARNING_BEGIN
347-
construct_on_valueless<j>(alt);
348-
IRIS_RVARIANT_DISABLE_UNINITIALIZED_WARNING_END
349-
} else {
350-
(void)this;
351-
}
352-
});
353-
}
354-
355-
// Move constructor
356-
constexpr void _move_construct(rvariant_base&& w)
357-
noexcept(std::conjunction_v<std::is_nothrow_move_constructible<Ts>...>)
358-
{
359-
static constexpr bool is_noexcept = std::conjunction_v<std::is_nothrow_move_constructible<Ts>...>;
360-
std::move(w).template raw_visit<is_noexcept>([this]<std::size_t j, class T>(std::in_place_index_t<j>, [[maybe_unused]] T&& alt)
361-
noexcept(is_noexcept)
362-
{
363-
if constexpr (j != std::variant_npos) {
364-
static_assert(std::is_rvalue_reference_v<T&&>);
365-
IRIS_RVARIANT_DISABLE_UNINITIALIZED_WARNING_BEGIN
366-
construct_on_valueless<j>(std::move(alt)); // NOLINT(bugprone-move-forwarding-reference)
367-
IRIS_RVARIANT_DISABLE_UNINITIALIZED_WARNING_END
368-
} else {
369-
(void)this;
370-
}
371-
});
372-
}
373-
374-
// Copy assignment
375-
constexpr void _copy_assign(rvariant_base const& rhs)
376-
noexcept(std::conjunction_v<variant_nothrow_copy_assignable<Ts>...>)
377-
{
378-
IRIS_RVARIANT_ALWAYS_THROWING_UNREACHABLE_BEGIN
379-
static constexpr bool is_noexcept = std::conjunction_v<variant_nothrow_copy_assignable<Ts>...>;
380-
rhs.template raw_visit<is_noexcept>([this]<std::size_t j, class T>(std::in_place_index_t<j>, T const& rhs_alt)
381-
noexcept(is_noexcept)
382-
{
383-
if constexpr (j == std::variant_npos) {
384-
(void)rhs_alt;
385-
visit_reset();
386-
} else {
387-
IRIS_RVARIANT_DISABLE_UNINITIALIZED_WARNING_BEGIN
388-
if (index_ == j) {
389-
raw_get<j>(storage()) = rhs_alt;
390-
} else {
391-
// CC(noexcept) && MC(throw) => A
392-
// CC(noexcept) && MC(noexcept) => A
393-
// CC(throw) && MC(throw) => A
394-
// CC(throw) && MC(noexcept) => B
395-
if constexpr (std::is_nothrow_copy_constructible_v<T> || !std::is_nothrow_move_constructible_v<T>) {
396-
reset_construct<j>(rhs_alt); // A
397-
} else {
398-
T tmp(rhs_alt);
399-
reset_construct<j>(std::move(tmp)); // B
400-
}
401-
}
402-
IRIS_RVARIANT_DISABLE_UNINITIALIZED_WARNING_END
403-
}
404-
});
405-
IRIS_RVARIANT_ALWAYS_THROWING_UNREACHABLE_END
406-
}
407-
408-
// Move assignment
409-
constexpr void _move_assign(rvariant_base&& rhs)
410-
noexcept(std::conjunction_v<variant_nothrow_move_assignable<Ts>...>)
411-
{
412-
static constexpr bool is_noexcept = std::conjunction_v<variant_nothrow_move_assignable<Ts>...>;
413-
std::move(rhs).template raw_visit<is_noexcept>([this]<std::size_t j, class T>(std::in_place_index_t<j>, [[maybe_unused]] T&& rhs_alt)
414-
noexcept(is_noexcept)
415-
{
416-
if constexpr (j == std::variant_npos) {
417-
(void)rhs_alt;
418-
visit_reset();
419-
} else {
420-
static_assert(std::is_rvalue_reference_v<T&&>);
421-
422-
IRIS_RVARIANT_DISABLE_UNINITIALIZED_WARNING_BEGIN
423-
if (index_ == j) {
424-
raw_get<j>(storage()) = std::move(rhs_alt); // NOLINT(bugprone-move-forwarding-reference)
425-
} else {
426-
reset_construct<j>(std::move(rhs_alt)); // NOLINT(bugprone-move-forwarding-reference)
427-
}
428-
IRIS_RVARIANT_DISABLE_UNINITIALIZED_WARNING_END
429-
}
430-
});
431-
}
432-
433405
// -------------------------------------------------------
434406

435407
[[nodiscard]] constexpr bool valueless_by_exception() const noexcept
@@ -549,7 +521,7 @@ IRIS_RVARIANT_ALWAYS_THROWING_UNREACHABLE_END
549521
{
550522
visit_reset();
551523

552-
static constexpr bool is_noexcept = std::conjunction_v<std::is_nothrow_move_constructible<Ts>...>;
524+
constexpr bool is_noexcept = std::conjunction_v<std::is_nothrow_move_constructible<Ts>...>;
553525
std::move(rhs).template raw_visit<is_noexcept>([this]<std::size_t i, class T>(std::in_place_index_t<i>, [[maybe_unused]] T&& alt)
554526
noexcept(is_noexcept)
555527
{
@@ -835,7 +807,7 @@ IRIS_RVARIANT_ALWAYS_THROWING_UNREACHABLE_BEGIN
835807
return *this;
836808
}
837809

838-
static constexpr bool is_noexcept = detail::variant_nothrow_assignable<Tj, T>::value;
810+
constexpr bool is_noexcept = detail::variant_nothrow_assignable<Tj, T>::value;
839811
this->template raw_visit<is_noexcept>([this, &t]<std::size_t i, class Ti>(std::in_place_index_t<i>, [[maybe_unused]] Ti& ti)
840812
noexcept(is_noexcept)
841813
{
@@ -879,7 +851,7 @@ IRIS_RVARIANT_ALWAYS_THROWING_UNREACHABLE_END
879851
constexpr rvariant(rvariant<Us...> const& w)
880852
noexcept(std::conjunction_v<std::is_nothrow_constructible<detail::select_maybe_wrapped_t<unwrap_recursive_t<Us>, Ts...>, Us const&>...>)
881853
{
882-
static constexpr bool is_noexcept = std::conjunction_v<std::is_nothrow_constructible<detail::select_maybe_wrapped_t<unwrap_recursive_t<Us>, Ts...>, Us const&>...>;
854+
constexpr bool is_noexcept = std::conjunction_v<std::is_nothrow_constructible<detail::select_maybe_wrapped_t<unwrap_recursive_t<Us>, Ts...>, Us const&>...>;
883855
w.template raw_visit<is_noexcept>([this]<std::size_t j, class Uj>(std::in_place_index_t<j>, [[maybe_unused]] Uj const& uj)
884856
noexcept(is_noexcept)
885857
{
@@ -902,7 +874,7 @@ IRIS_RVARIANT_ALWAYS_THROWING_UNREACHABLE_END
902874
constexpr rvariant(rvariant<Us...>&& w)
903875
noexcept(std::conjunction_v<std::is_nothrow_constructible<detail::select_maybe_wrapped_t<unwrap_recursive_t<Us>, Ts...>, Us&&>...>)
904876
{
905-
static constexpr bool is_noexcept = std::conjunction_v<std::is_nothrow_constructible<detail::select_maybe_wrapped_t<unwrap_recursive_t<Us>, Ts...>, Us&&>...>;
877+
constexpr bool is_noexcept = std::conjunction_v<std::is_nothrow_constructible<detail::select_maybe_wrapped_t<unwrap_recursive_t<Us>, Ts...>, Us&&>...>;
906878
std::move(w).template raw_visit<is_noexcept>([this]<std::size_t j, class Uj>(std::in_place_index_t<j>, [[maybe_unused]] Uj&& uj)
907879
noexcept(is_noexcept)
908880
{
@@ -928,7 +900,7 @@ IRIS_RVARIANT_ALWAYS_THROWING_UNREACHABLE_END
928900
constexpr rvariant& operator=(rvariant<Us...> const& rhs)
929901
noexcept(std::conjunction_v<detail::variant_nothrow_copy_assignable<detail::select_maybe_wrapped_t<unwrap_recursive_t<Us>, Ts...>, Us const&>...>)
930902
{
931-
static constexpr bool is_noexcept = std::conjunction_v<detail::variant_nothrow_copy_assignable<detail::select_maybe_wrapped_t<unwrap_recursive_t<Us>, Ts...>, Us const&>...>;
903+
constexpr bool is_noexcept = std::conjunction_v<detail::variant_nothrow_copy_assignable<detail::select_maybe_wrapped_t<unwrap_recursive_t<Us>, Ts...>, Us const&>...>;
932904
rhs.template raw_visit<is_noexcept>([this]<std::size_t j, class Uj>(std::in_place_index_t<j>, [[maybe_unused]] Uj const& uj)
933905
noexcept(is_noexcept)
934906
{
@@ -973,7 +945,7 @@ IRIS_RVARIANT_ALWAYS_THROWING_UNREACHABLE_END
973945
constexpr rvariant& operator=(rvariant<Us...>&& rhs)
974946
noexcept(std::conjunction_v<detail::variant_nothrow_move_assignable<detail::select_maybe_wrapped_t<unwrap_recursive_t<Us>, Ts...>, Us&&>...>)
975947
{
976-
static constexpr bool is_noexcept = std::conjunction_v<detail::variant_nothrow_move_assignable<detail::select_maybe_wrapped_t<unwrap_recursive_t<Us>, Ts...>, Us&&>...>;
948+
constexpr bool is_noexcept = std::conjunction_v<detail::variant_nothrow_move_assignable<detail::select_maybe_wrapped_t<unwrap_recursive_t<Us>, Ts...>, Us&&>...>;
977949
std::move(rhs).template raw_visit<is_noexcept>([this]<std::size_t j, class Uj>(std::in_place_index_t<j>, [[maybe_unused]] Uj&& uj)
978950
noexcept(is_noexcept)
979951
{
@@ -1137,7 +1109,7 @@ IRIS_RVARIANT_ALWAYS_THROWING_UNREACHABLE_END
11371109
IRIS_RVARIANT_ALWAYS_THROWING_UNREACHABLE_END
11381110
} else {
11391111
if (index_ == rhs.index_) {
1140-
static constexpr bool is_noexcept = std::conjunction_v<std::is_nothrow_swappable<Ts>...>;
1112+
constexpr bool is_noexcept = std::conjunction_v<std::is_nothrow_swappable<Ts>...>;
11411113
rhs.template raw_visit<is_noexcept>([this]<std::size_t i, class RhsAlt>(std::in_place_index_t<i>, [[maybe_unused]] RhsAlt& rhs_alt)
11421114
noexcept(is_noexcept)
11431115
{
@@ -1186,7 +1158,7 @@ IRIS_RVARIANT_ALWAYS_THROWING_UNREACHABLE_END
11861158
)
11871159
{
11881160
if constexpr (rvariant_set::equivalent_to<rvariant<Us...>, rvariant>) {
1189-
static constexpr bool is_noexcept = std::is_nothrow_constructible_v<rvariant<Us...>, rvariant const&>;
1161+
constexpr bool is_noexcept = std::is_nothrow_constructible_v<rvariant<Us...>, rvariant const&>;
11901162
return this->template raw_visit<is_noexcept>([]<std::size_t i, class Ti>(std::in_place_index_t<i>, [[maybe_unused]] Ti const& ti) static
11911163
noexcept(is_noexcept) -> rvariant<Us...>
11921164
{
@@ -1227,7 +1199,7 @@ IRIS_RVARIANT_ALWAYS_THROWING_UNREACHABLE_END
12271199
)
12281200
{
12291201
if constexpr (rvariant_set::equivalent_to<rvariant<Us...>, rvariant>) {
1230-
static constexpr bool is_noexcept = std::is_nothrow_constructible_v<rvariant<Us...>, rvariant&&>;
1202+
constexpr bool is_noexcept = std::is_nothrow_constructible_v<rvariant<Us...>, rvariant&&>;
12311203
return std::move(*this).template raw_visit<is_noexcept>([]<std::size_t i, class Ti>(std::in_place_index_t<i>, [[maybe_unused]] Ti&& ti) static
12321204
noexcept(is_noexcept) -> rvariant<Us...>
12331205
{

0 commit comments

Comments
 (0)