11#ifndef CPPUTILS_EXPECTED_HPP
22#define CPPUTILS_EXPECTED_HPP
33
4- #include " ../traits/is_specialization_of .hpp"
4+ #include " ../meta/traits .hpp"
55#include < concepts>
66#include < exception>
77#include < functional>
@@ -33,9 +33,9 @@ struct bad_expected_access_throw_policy {
3333
3434template <typename Policy>
3535concept expected_bad_access_policy = requires {
36- Policy::bad_value_access ();
37- Policy::bad_error_access ();
38- };
36+ Policy::bad_value_access ();
37+ Policy::bad_error_access ();
38+ };
3939
4040struct flag_value_t {};
4141struct flag_error_t {};
@@ -46,7 +46,7 @@ inline constexpr auto flag_error = flag_error_t{};
4646namespace detail {
4747
4848 template <template <typename > typename Condition, typename A, typename B>
49- inline constexpr auto both_types_v = Condition<A>::value &&Condition<B>::value;
49+ inline constexpr auto both_types_v = Condition<A>::value && Condition<B>::value;
5050
5151 template <template <typename > typename Condition, typename A, typename B>
5252 inline constexpr auto one_of_v = Condition<A>::value || Condition<B>::value;
@@ -234,17 +234,17 @@ namespace detail {
234234 constexpr expected_data () = delete;
235235
236236 template <expected_arg_constructible<value_t > Arg>
237- constexpr expected_data (flag_value_t , Arg &&v) requires(!is_specialization_v<Arg, expected_data>)
237+ constexpr expected_data (flag_value_t , Arg &&v) requires (!is_specialization_v<Arg, expected_data>)
238238 : m_val{get_arg (FWD (v))}
239239 , has_val{true } {}
240240
241241 template <expected_arg_constructible<error_t > Arg>
242- constexpr expected_data (flag_error_t , Arg &&v) requires(!is_specialization_v<Arg, expected_data>)
242+ constexpr expected_data (flag_error_t , Arg &&v) requires (!is_specialization_v<Arg, expected_data>)
243243 : m_err{get_arg (FWD (v))} {}
244244
245245 constexpr expected_data (flag_value_t , std::in_place_t , auto &&...args) requires std::negation_v<std::is_pointer<value_t>> && std::constructible_from<value_t, decltype(args)...>
246- : m_val{FWD (args)...},
247- has_val{true } {}
246+ : m_val{FWD (args)...}
247+ , has_val{true } {}
248248
249249 constexpr expected_data (flag_error_t , std::in_place_t , auto &&...args) requires std::negation_v<std::is_pointer<error_t>> && std::constructible_from<error_t, decltype(args)...>
250250 : m_err{FWD (args)...} {}
@@ -264,7 +264,8 @@ namespace detail {
264264 constexpr expected_data (expected_data const &) requires both_types_v<std::is_trivially_copy_constructible, value_t, error_t>
265265 = default;
266266
267- constexpr expected_data (expected_data const &other) requires has_non_default_copy_ctor_v<value_t, error_t> {
267+ constexpr expected_data (expected_data const &other) requires has_non_default_copy_ctor_v<value_t, error_t>
268+ {
268269 expected_resource_helper::initialize (*this , other);
269270 }
270271
@@ -276,32 +277,35 @@ namespace detail {
276277 constexpr expected_data (expected_data &&other) noexcept (
277278 noexcept (
278279 expected_resource_helper::initialize (std::declval<expected_data &>(),
279- std::declval<std::remove_cvref_t<decltype(other)>>()))) requires has_non_default_move_ctor_v<value_t, error_t> {
280+ std::declval<std::remove_cvref_t<decltype(other)>>()))) requires has_non_default_move_ctor_v<value_t, error_t>
281+ {
280282 expected_resource_helper::initialize (*this , std::move (other));
281283 }
282284
283285 constexpr expected_data &operator =(expected_data const &) = delete;
284286
285287 constexpr expected_data &operator =(expected_data const &) requires both_types_v<std::is_trivially_copy_assignable, value_t, error_t> //
286- && both_types_v<std::is_trivially_destructible, value_t, error_t> //
287- && both_types_v<std::is_trivially_copy_constructible, value_t, error_t>
288+ && both_types_v<std::is_trivially_destructible, value_t, error_t> //
289+ && both_types_v<std::is_trivially_copy_constructible, value_t, error_t>
288290 = default;
289291
290- constexpr expected_data &operator =(expected_data const &rhs) requires has_non_default_copy_assign_v<value_t , error_t > { // NOLINT(cert-oop54-cpp)
292+ constexpr expected_data &operator =(expected_data const &rhs) requires has_non_default_copy_assign_v<value_t , error_t >
293+ { // NOLINT(cert-oop54-cpp)
291294 expected_resource_helper::copy (*this , rhs);
292295 return *this ;
293296 }
294297
295298 constexpr expected_data &operator =(expected_data &&) noexcept = delete ;
296299
297300 constexpr expected_data &operator =(expected_data &&) noexcept requires both_types_v<std::is_trivially_move_assignable, value_t , error_t > //
298- && both_types_v<std::is_trivially_destructible, value_t , error_t > //
299- && both_types_v<std::is_trivially_move_constructible, value_t , error_t >
301+ && both_types_v<std::is_trivially_destructible, value_t , error_t > //
302+ && both_types_v<std::is_trivially_move_constructible, value_t , error_t >
300303 = default ;
301304
302305 constexpr expected_data &operator =(expected_data &&rhs) noexcept (
303306 noexcept (expected_resource_helper::copy(std::declval<expected_data &>(),
304- std::declval<std::remove_cvref_t <decltype (rhs)>>))) requires has_non_default_move_assign_v<value_t , error_t > {
307+ std::declval<std::remove_cvref_t <decltype (rhs)>>))) requires has_non_default_move_assign_v<value_t , error_t >
308+ {
305309 expected_resource_helper::copy (*this , std::move (rhs));
306310 return *this ;
307311 }
@@ -679,7 +683,8 @@ class expected
679683 }
680684
681685 static constexpr auto transform_error_impl (auto &&e, std::invocable<decltype (FWD (e).error_unchecked())> auto &&f) //
682- requires is_specialization_v<std::invoke_result_t<decltype(f), decltype(FWD (e).error_unchecked())>, expected> {
686+ requires is_specialization_v<std::invoke_result_t<decltype(f), decltype(FWD (e).error_unchecked())>, expected>
687+ {
683688 using ret_t = std::invoke_result_t <decltype (f), decltype (FWD (e).error_unchecked ())>;
684689 static_assert (std::is_same_v<typename base_expected::value_t , typename ret_t ::value_t >);
685690 if (!e) { return std::invoke (FWD (f), FWD (e).error_unchecked ()); }
@@ -700,7 +705,8 @@ class expected
700705 }
701706
702707 static constexpr auto value_or_else_impl (auto &&e, std::invocable<decltype (FWD (e).error_unchecked())> auto &&alternative) //
703- requires std::is_convertible_v<decltype(FWD (e).value_unchecked()), decltype(std::invoke(FWD (alternative), FWD(e).error_unchecked()))> {
708+ requires std::is_convertible_v<decltype(FWD (e).value_unchecked()), decltype(std::invoke(FWD (alternative), FWD(e).error_unchecked()))>
709+ {
704710 if (e) { return FWD (e).value_unchecked (); }
705711 return std::invoke (FWD (alternative), FWD (e).error_unchecked ());
706712 }
@@ -712,7 +718,8 @@ class expected
712718 }
713719
714720 static constexpr auto error_or_else_impl (auto &&e, std::invocable<decltype (FWD (e).value_unchecked())> auto &&alternative) //
715- requires std::is_convertible_v<decltype(FWD (e).error_unchecked()), decltype(std::invoke(FWD (alternative), FWD(e).value_unchecked()))> {
721+ requires std::is_convertible_v<decltype(FWD (e).error_unchecked()), decltype(std::invoke(FWD (alternative), FWD(e).value_unchecked()))>
722+ {
716723 if (!e) { return FWD (e).error_unchecked (); }
717724 return std::invoke (FWD (alternative), FWD (e).value_unchecked ());
718725 }
0 commit comments