Skip to content

Commit 45084e9

Browse files
arturbacArtur Bać
and
Artur Bać
authored
Pr patch 7 (#19)
* update expected to match latest version in small_vectors * update version --------- Co-authored-by: Artur Bać <artur@ebasoft.com.pl>
1 parent e29694c commit 45084e9

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

include/simple_enum/core.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <concepts>
77
#include <type_traits>
88

9-
#define SIMPLE_ENUM_NAME_VERSION "0.8.6"
9+
#define SIMPLE_ENUM_NAME_VERSION "0.8.7"
1010

1111
namespace simple_enum::inline v0_8
1212
{

include/simple_enum/expected.h

+28-16
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#define SMALL_VECTORS_EXPECTED
99
#include <version>
1010

11-
#if defined(__cpp_lib_expected) && __cpp_lib_expected >= 202211L
11+
#if !defined(SMALL_VECTORS_ENABLE_CUSTOM_EXCPECTED) && defined(__cpp_lib_expected) && __cpp_lib_expected >= 202211L
1212
#include <expected>
1313

1414
namespace cxx23
@@ -110,7 +110,7 @@ namespace detail
110110
}
111111

112112
template<typename E>
113-
class unexpected
113+
class [[clang::trivial_abi]] unexpected
114114
{
115115
public:
116116
static_assert(concepts::unexpected_constraint<E>, "not a valid type for unexpected error type");
@@ -304,8 +304,11 @@ namespace concepts
304304
};
305305
} // namespace concepts
306306

307+
// https://clang.llvm.org/docs/AttributeReference.html#trivial-abi
308+
// Attribute trivial_abi has no effect when the class has a non-static data member whose type is non-trivial for the
309+
// purposes of calls
307310
template<typename T, typename E>
308-
class expected
311+
class [[nodiscard, clang::trivial_abi]] expected
309312
{
310313
public:
311314
static_assert(concepts::unexpected_constraint<E>, "not a valid type for expected error type");
@@ -388,9 +391,11 @@ class expected
388391
requires std::is_constructible_v<E, G const &>;
389392
requires concepts::expected_conv_constr<T, E, U, G>;
390393
}
391-
constexpr explicit(!std::is_convertible_v<std::add_lvalue_reference_t<U const>, T> || !std::is_convertible_v<G const &, E>) expected(
392-
expected<U, G> const & rh
393-
) noexcept(std::is_nothrow_constructible_v<value_type, decltype(std::forward<std::add_lvalue_reference_t<U const>>(rh.value()))> && std::is_nothrow_constructible_v<error_type, decltype(std::forward<G const &>(rh.error()))>) :
394+
constexpr explicit(!std::is_convertible_v<std::add_lvalue_reference_t<U const>, T> || !std::is_convertible_v<G const &, E>) expected(expected<U, G> const & rh) noexcept(
395+
std::
396+
is_nothrow_constructible_v<value_type, decltype(std::forward<std::add_lvalue_reference_t<U const>>(rh.value()))>
397+
&& std::is_nothrow_constructible_v<error_type, decltype(std::forward<G const &>(rh.error()))>
398+
) :
394399
has_value_{rh.has_value()}
395400
{
396401
if(has_value_) [[likely]]
@@ -405,8 +410,10 @@ class expected
405410
requires std::is_constructible_v<E, G>;
406411
requires concepts::expected_conv_constr<T, E, U, G>;
407412
}
408-
constexpr explicit(!std::is_convertible_v<U, T> || !std::is_convertible_v<G, E>) expected(expected<U, G> && rh
409-
) noexcept(std::is_nothrow_constructible_v<value_type, decltype(std::forward<U>(rh.value()))> && std::is_nothrow_constructible_v<error_type, decltype(std::forward<G>(rh.error()))>) :
413+
constexpr explicit(!std::is_convertible_v<U, T> || !std::is_convertible_v<G, E>) expected(expected<U, G> && rh) noexcept(
414+
std::is_nothrow_constructible_v<value_type, decltype(std::forward<U>(rh.value()))>
415+
&& std::is_nothrow_constructible_v<error_type, decltype(std::forward<G>(rh.error()))>
416+
) :
410417
has_value_{rh.has_value()}
411418
{
412419
if(has_value_) [[likely]]
@@ -423,8 +430,8 @@ class expected
423430
requires !concepts::is_unexpected<std::remove_cvref_t<U>>;
424431
requires !std::same_as<bool, T> || !concepts::is_expected<std::remove_cvref_t<U>>;
425432
}
426-
constexpr explicit(!std::is_convertible_v<U, T>)
427-
expected(U && v) noexcept(std::is_nothrow_constructible_v<value_type, decltype(std::forward<U>(v))>) :
433+
constexpr explicit(!std::is_convertible_v<U, T>
434+
) expected(U && v) noexcept(std::is_nothrow_constructible_v<value_type, decltype(std::forward<U>(v))>) :
428435
has_value_{true}
429436
{
430437
std::construct_at(std::addressof(value_), std::forward<U>(v));
@@ -617,7 +624,8 @@ class expected
617624

618625
template<typename U>
619626
[[nodiscard]]
620-
constexpr value_type value_or(U && default_value
627+
constexpr value_type value_or(
628+
U && default_value
621629
) const & noexcept(std::is_nothrow_copy_constructible_v<value_type> && std::is_nothrow_convertible_v<U, value_type>)
622630
requires value_copy_constructible && std::is_convertible_v<U, value_type>
623631
{
@@ -626,7 +634,8 @@ class expected
626634

627635
template<typename U>
628636
[[nodiscard]]
629-
constexpr value_type value_or(U && default_value
637+
constexpr value_type value_or(
638+
U && default_value
630639
) && noexcept(std::is_nothrow_move_constructible_v<value_type> && std::is_nothrow_convertible_v<U, value_type>)
631640
requires value_move_constructible && std::is_convertible_v<U, value_type>
632641
{
@@ -883,7 +892,8 @@ class expected<T, E>
883892
requires std::is_constructible_v<E, G const &>;
884893
requires concepts::expected_conv_constr<void, E, U, G>;
885894
}
886-
constexpr explicit(!std::is_convertible_v<G const &, E>) expected(expected<U, G> const & rh
895+
constexpr explicit(!std::is_convertible_v<G const &, E>) expected(
896+
expected<U, G> const & rh
887897
) noexcept(std::is_nothrow_constructible_v<error_type, decltype(std::forward<G const &>(rh.error()))>) :
888898
has_value_{rh.has_value()}
889899
{
@@ -897,7 +907,8 @@ class expected<T, E>
897907
requires std::is_constructible_v<E, G>;
898908
requires concepts::expected_conv_constr<void, E, U, G>;
899909
}
900-
constexpr explicit(!std::is_convertible_v<G, E>) expected(expected<U, G> && rh
910+
constexpr explicit(!std::is_convertible_v<G, E>) expected(
911+
expected<U, G> && rh
901912
) noexcept(std::is_nothrow_constructible_v<error_type, decltype(std::forward<G>(rh.error()))>) :
902913
has_value_{rh.has_value()}
903914
{
@@ -1286,8 +1297,9 @@ namespace detail
12861297
struct swap_expected_t
12871298
{
12881299
template<typename T, typename E>
1289-
static_call_operator constexpr void operator()(expected<T, E> & l, expected<T, E> & r) static_call_operator_const
1290-
noexcept(detail::swap_no_throw<T, E>)
1300+
static_call_operator constexpr void
1301+
operator()(expected<T, E> & l, expected<T, E> & r) static_call_operator_const noexcept(detail::swap_no_throw<T, E>
1302+
)
12911303
requires concepts::swap_constraints<T, E>
12921304
{
12931305
if(l.has_value() && r.has_value())

0 commit comments

Comments
 (0)