diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7c1a556..057d1f8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,7 +21,7 @@ repos: # CMake linting and formatting - repo: https://github.com/BlankSpruce/gersemi-pre-commit - rev: 0.27.6 + rev: 0.27.7 hooks: - id: gersemi name: CMake linting diff --git a/include/beman/expected/expected.hpp b/include/beman/expected/expected.hpp index 51da38c..e2d429b 100644 --- a/include/beman/expected/expected.hpp +++ b/include/beman/expected/expected.hpp @@ -94,8 +94,7 @@ template inline constexpr bool unexpect_dangles_v = false; template -inline constexpr bool unexpect_dangles_v = - std::is_reference_v && reference_constructs_from_temporary_v; +inline constexpr bool unexpect_dangles_v = std::is_reference_v && reference_constructs_from_temporary_v; } // namespace detail @@ -157,8 +156,8 @@ class expected { // Copy constructor (non-trivial path) constexpr expected(const expected& rhs) requires(std::is_copy_constructible_v && std::is_copy_constructible_v> && - !(std::is_trivially_copy_constructible_v && - std::is_trivially_copy_constructible_v>)); + !(std::is_trivially_copy_constructible_v && std::is_trivially_copy_constructible_v>)) + ; // Move constructor (trivial path) constexpr expected(expected&&) noexcept @@ -169,8 +168,8 @@ class expected { constexpr expected(expected&& rhs) noexcept(std::is_nothrow_move_constructible_v && std::is_nothrow_move_constructible_v>) requires(std::is_move_constructible_v && std::is_move_constructible_v> && - !(std::is_trivially_move_constructible_v && - std::is_trivially_move_constructible_v>)); + !(std::is_trivially_move_constructible_v && std::is_trivially_move_constructible_v>)) + ; // Converting copy constructor from expected — value-E path template @@ -205,8 +204,7 @@ class expected { template requires(std::is_reference_v && std::is_reference_v && std::is_constructible_v && std::is_convertible_v) - constexpr explicit(!std::is_convertible_v || !std::is_convertible_v) - expected(expected&& rhs); + constexpr explicit(!std::is_convertible_v || !std::is_convertible_v) expected(expected&& rhs); // Constructor from value U&& template > @@ -302,8 +300,7 @@ class expected { constexpr expected& operator=(const expected&) requires(std::is_trivially_copy_constructible_v && std::is_trivially_copy_assignable_v && std::is_trivially_destructible_v && std::is_trivially_copy_constructible_v> && - std::is_trivially_copy_assignable_v> && - std::is_trivially_destructible_v>) + std::is_trivially_copy_assignable_v> && std::is_trivially_destructible_v>) = default; // Copy assignment (non-trivial path) @@ -320,14 +317,14 @@ class expected { constexpr expected& operator=(expected&&) noexcept requires(std::is_trivially_move_constructible_v && std::is_trivially_move_assignable_v && std::is_trivially_destructible_v && std::is_trivially_move_constructible_v> && - std::is_trivially_move_assignable_v> && - std::is_trivially_destructible_v>) + std::is_trivially_move_assignable_v> && std::is_trivially_destructible_v>) = default; // Move assignment (non-trivial path) - constexpr expected& operator=(expected&& rhs) noexcept( - std::is_nothrow_move_constructible_v && std::is_nothrow_move_assignable_v && - std::is_nothrow_move_constructible_v> && std::is_nothrow_move_assignable_v>) + constexpr expected& operator=(expected&& rhs) noexcept(std::is_nothrow_move_constructible_v && + std::is_nothrow_move_assignable_v && + std::is_nothrow_move_constructible_v> && + std::is_nothrow_move_assignable_v>) requires(std::is_move_constructible_v && std::is_move_assignable_v && std::is_move_constructible_v> && std::is_move_assignable_v> && (std::is_nothrow_move_constructible_v || std::is_nothrow_move_constructible_v>) && @@ -393,9 +390,10 @@ class expected { // [expected.object.swap] Swap // ------------------------------------------------------------------------- - constexpr void swap(expected& rhs) noexcept( - std::is_nothrow_move_constructible_v && std::is_nothrow_swappable_v && - std::is_nothrow_move_constructible_v> && (std::is_reference_v || std::is_nothrow_swappable_v)) + constexpr void swap(expected& rhs) noexcept(std::is_nothrow_move_constructible_v && + std::is_nothrow_swappable_v && + std::is_nothrow_move_constructible_v> && + (std::is_reference_v || std::is_nothrow_swappable_v)) requires(std::is_swappable_v && (std::is_reference_v || std::is_swappable_v) && std::is_move_constructible_v && std::is_move_constructible_v> && (std::is_nothrow_move_constructible_v || std::is_nothrow_move_constructible_v>)); @@ -869,9 +867,10 @@ constexpr T& expected::emplace(std::initializer_list il, Args&&... args // ============================================================================= template -constexpr void expected::swap(expected& rhs) noexcept( - std::is_nothrow_move_constructible_v && std::is_nothrow_swappable_v && - std::is_nothrow_move_constructible_v> && (std::is_reference_v || std::is_nothrow_swappable_v)) +constexpr void expected::swap(expected& rhs) noexcept(std::is_nothrow_move_constructible_v && + std::is_nothrow_swappable_v && + std::is_nothrow_move_constructible_v> && + (std::is_reference_v || std::is_nothrow_swappable_v)) requires(std::is_swappable_v && (std::is_reference_v || std::is_swappable_v) && std::is_move_constructible_v && std::is_move_constructible_v> && (std::is_nothrow_move_constructible_v || std::is_nothrow_move_constructible_v>)) @@ -1175,7 +1174,8 @@ template constexpr auto expected::or_else(F&& f) & { using G = std::remove_cvref_t>; static_assert(detail::is_expected_specialization::value, "or_else: F must return a specialization of expected"); - static_assert(std::is_same_v, "or_else: F must return expected with the same value_type"); + static_assert(std::is_same_v, + "or_else: F must return expected with the same value_type"); if (has_val_) return G(std::in_place, val_); return std::invoke(std::forward(f), unex_.error()); @@ -1187,7 +1187,8 @@ template constexpr auto expected::or_else(F&& f) && { using G = std::remove_cvref_t>; static_assert(detail::is_expected_specialization::value, "or_else: F must return a specialization of expected"); - static_assert(std::is_same_v, "or_else: F must return expected with the same value_type"); + static_assert(std::is_same_v, + "or_else: F must return expected with the same value_type"); if (has_val_) return G(std::in_place, std::move(val_)); return std::invoke(std::forward(f), std::move(unex_).error()); @@ -1199,7 +1200,8 @@ template constexpr auto expected::or_else(F&& f) const& { using G = std::remove_cvref_t>; static_assert(detail::is_expected_specialization::value, "or_else: F must return a specialization of expected"); - static_assert(std::is_same_v, "or_else: F must return expected with the same value_type"); + static_assert(std::is_same_v, + "or_else: F must return expected with the same value_type"); if (has_val_) return G(std::in_place, val_); return std::invoke(std::forward(f), unex_.error()); @@ -1211,7 +1213,8 @@ template constexpr auto expected::or_else(F&& f) const&& { using G = std::remove_cvref_t>; static_assert(detail::is_expected_specialization::value, "or_else: F must return a specialization of expected"); - static_assert(std::is_same_v, "or_else: F must return expected with the same value_type"); + static_assert(std::is_same_v, + "or_else: F must return expected with the same value_type"); if (has_val_) return G(std::in_place, std::move(val_)); return std::invoke(std::forward(f), std::move(unex_).error()); @@ -1412,16 +1415,16 @@ class expected { = default; constexpr expected(const expected& rhs) - requires(std::is_copy_constructible_v> && - !std::is_trivially_copy_constructible_v>); + requires(std::is_copy_constructible_v> && !std::is_trivially_copy_constructible_v>) + ; constexpr expected(expected&&) noexcept requires std::is_trivially_move_constructible_v> = default; constexpr expected(expected&& rhs) noexcept(std::is_nothrow_move_constructible_v>) - requires(std::is_move_constructible_v> && - !std::is_trivially_move_constructible_v>); + requires(std::is_move_constructible_v> && !std::is_trivially_move_constructible_v>) + ; // Converting constructor from expected where is_void_v. Excludes U,G exactly // matching this class's own void,E (the real copy/move constructors already handle that @@ -1429,8 +1432,8 @@ class expected { // unexpected's constructibility from this very class, which some standard library // implementations of reference_constructs_from_temporary_v resolve as a circular constraint. template - requires(std::is_void_v && !std::is_same_v && - std::is_constructible_v && !std::is_constructible_v, expected&> && + requires(std::is_void_v && !std::is_same_v && std::is_constructible_v && + !std::is_constructible_v, expected&> && !std::is_constructible_v, expected &&> && !std::is_constructible_v, const expected&> && !std::is_constructible_v, const expected &&>) @@ -1523,8 +1526,7 @@ class expected { // Copy assignment (trivial path) constexpr expected& operator=(const expected&) requires(std::is_trivially_copy_constructible_v> && - std::is_trivially_copy_assignable_v> && - std::is_trivially_destructible_v>) + std::is_trivially_copy_assignable_v> && std::is_trivially_destructible_v>) = default; // Copy assignment (non-trivial path) @@ -1537,8 +1539,7 @@ class expected { // Move assignment (trivial path) constexpr expected& operator=(expected&&) noexcept requires(std::is_trivially_move_constructible_v> && - std::is_trivially_move_assignable_v> && - std::is_trivially_destructible_v>) + std::is_trivially_move_assignable_v> && std::is_trivially_destructible_v>) = default; // Move assignment (non-trivial path) @@ -1551,8 +1552,7 @@ class expected { // Assignment from unexpected — value-E path. template - requires(!std::is_reference_v && std::is_constructible_v && - std::is_assignable_v) + requires(!std::is_reference_v && std::is_constructible_v && std::is_assignable_v) constexpr expected& operator=(const unexpected& e); template @@ -1727,8 +1727,8 @@ constexpr expected::expected(expected&& rhs) noexcept(std::is_nothrow_m template template - requires(std::is_void_v && !std::is_same_v && - std::is_constructible_v && !std::is_constructible_v, expected&> && + requires(std::is_void_v && !std::is_same_v && std::is_constructible_v && + !std::is_constructible_v, expected&> && !std::is_constructible_v, expected &&> && !std::is_constructible_v, const expected&> && !std::is_constructible_v, const expected &&>) @@ -1779,7 +1779,6 @@ constexpr expected::expected(unexpected&& e) noexcept : has_val_(fal std::construct_at(std::addressof(unex_), e.error()); } - template template requires(std::is_constructible_v && !detail::unexpect_dangles_v) @@ -2341,7 +2340,8 @@ class expected { // Copy constructor (non-trivial path) constexpr expected(const expected& rhs) noexcept(std::is_nothrow_copy_constructible_v>) - requires(std::is_copy_constructible_v> && !std::is_trivially_copy_constructible_v>); + requires(std::is_copy_constructible_v> && !std::is_trivially_copy_constructible_v>) + ; // Move constructor (trivial path) constexpr expected(expected&&) noexcept @@ -2350,7 +2350,8 @@ class expected { // Move constructor (non-trivial path) constexpr expected(expected&& rhs) noexcept(std::is_nothrow_move_constructible_v>) - requires(std::is_move_constructible_v> && !std::is_trivially_move_constructible_v>); + requires(std::is_move_constructible_v> && !std::is_trivially_move_constructible_v>) + ; // Deleted: no in-place value constructor — T& cannot be constructed in-place template @@ -2362,8 +2363,7 @@ class expected { !std::is_same_v, expected> && !detail::is_unexpected_specialization>::value && std::is_constructible_v && !detail::reference_constructs_from_temporary_v) - constexpr explicit(!std::is_convertible_v) expected(U&& u) noexcept( - std::is_nothrow_constructible_v) + constexpr explicit(!std::is_convertible_v) expected(U&& u) noexcept(std::is_nothrow_constructible_v) : has_val_(true) { T& r = std::forward(u); val_ = std::addressof(r); @@ -2398,8 +2398,7 @@ class expected { template requires(std::is_reference_v && std::is_reference_v && std::is_constructible_v && std::is_convertible_v && !detail::reference_constructs_from_temporary_v) - constexpr explicit(!std::is_convertible_v || !std::is_convertible_v) - expected(expected&& rhs); + constexpr explicit(!std::is_convertible_v || !std::is_convertible_v) expected(expected&& rhs); // Constructor from unexpected const& / && — value-E path template @@ -2473,8 +2472,7 @@ class expected { // Copy assignment (trivial path) constexpr expected& operator=(const expected&) requires(std::is_trivially_copy_constructible_v> && - std::is_trivially_copy_assignable_v> && - std::is_trivially_destructible_v>) + std::is_trivially_copy_assignable_v> && std::is_trivially_destructible_v>) = default; // Copy assignment (non-trivial path) @@ -2487,8 +2485,7 @@ class expected { // Move assignment (trivial path) constexpr expected& operator=(expected&&) noexcept requires(std::is_trivially_move_constructible_v> && - std::is_trivially_move_assignable_v> && - std::is_trivially_destructible_v>) + std::is_trivially_move_assignable_v> && std::is_trivially_destructible_v>) = default; // Move assignment (non-trivial path) @@ -2519,8 +2516,7 @@ class expected { // Assignment from unexpected — value-E path template - requires(!std::is_reference_v && std::is_constructible_v && - std::is_assignable_v) + requires(!std::is_reference_v && std::is_constructible_v && std::is_assignable_v) constexpr expected& operator=(const unexpected& e); template @@ -2705,7 +2701,6 @@ constexpr expected::expected(expected&& rhs) noexcept(std::is_nothrow_mov std::construct_at(std::addressof(unex_), std::move(rhs.unex_)); } - template template requires(!std::is_reference_v && std::is_constructible_v && std::is_constructible_v && @@ -2862,7 +2857,6 @@ expected::operator=(expected&& rhs) noexcept(std::is_nothrow_move_constru return *this; } - template template requires(!std::is_reference_v && std::is_constructible_v && std::is_assignable_v) @@ -2929,8 +2923,9 @@ constexpr T& expected::emplace(U&& u) noexcept(std::is_nothrow_constructi // ============================================================================= template -constexpr void expected::swap(expected& rhs) noexcept( - std::is_nothrow_move_constructible_v> && (std::is_reference_v || std::is_nothrow_swappable_v)) +constexpr void expected::swap(expected& rhs) noexcept(std::is_nothrow_move_constructible_v> && + (std::is_reference_v || + std::is_nothrow_swappable_v)) requires((std::is_reference_v || std::is_swappable_v) && std::is_move_constructible_v>) { if (has_val_ && rhs.has_val_) { diff --git a/include/beman/expected/unexpected.hpp b/include/beman/expected/unexpected.hpp index 43516d0..9a269b4 100644 --- a/include/beman/expected/unexpected.hpp +++ b/include/beman/expected/unexpected.hpp @@ -125,10 +125,9 @@ class unexpected { // Binds E& directly to the referenced object; deleted below when G would bind to a temporary. template requires(!std::is_same_v, unexpected> && - !std::is_same_v, std::in_place_t> && std::is_constructible_v && + !std::is_same_v, std::in_place_t> && std::is_constructible_v && !detail::reference_constructs_from_temporary_v) - constexpr explicit unexpected(G&& e) noexcept - : ptr_(std::addressof(static_cast(std::forward(e)))) {} + constexpr explicit unexpected(G&& e) noexcept : ptr_(std::addressof(static_cast(std::forward(e)))) {} // Deleted: binding would dangle (G materializes a temporary) template @@ -138,7 +137,7 @@ class unexpected { // Deleted catch-all: neither constructible nor a dangling case template requires(!std::is_same_v, unexpected> && - !std::is_same_v, std::in_place_t> && !std::is_constructible_v && + !std::is_same_v, std::in_place_t> && !std::is_constructible_v && !detail::reference_constructs_from_temporary_v) constexpr unexpected(G&&) = delete; @@ -147,7 +146,7 @@ class unexpected { // reference or not. Naturally restricted to arity 1: there is no variadic overload here, // and expected only ever calls this when is_constructible_v already holds. template - requires(std::is_constructible_v && !detail::reference_constructs_from_temporary_v) + requires(std::is_constructible_v && !detail::reference_constructs_from_temporary_v) constexpr explicit unexpected(std::in_place_t, G&& e) noexcept : ptr_(std::addressof(static_cast(std::forward(e)))) {} diff --git a/papers/wg21-latex/implementation.hpp b/papers/wg21-latex/implementation.hpp index 1d6aad4..4c73798 100644 --- a/papers/wg21-latex/implementation.hpp +++ b/papers/wg21-latex/implementation.hpp @@ -10,9 +10,8 @@ template class optional { public: using value_type = T; - using iterator = - std::contiguous_iterator; // see [optionalref.iterators] + using iterator = std::contiguous_iterator; // see [optionalref.iterators] public: // \ref{optionalref.ctor}, constructors @@ -21,13 +20,11 @@ class optional { constexpr optional(const optional& rhs) noexcept = default; template - requires(std::is_constructible_v && - !std::reference_constructs_from_temporary_v) + requires(std::is_constructible_v && !std::reference_constructs_from_temporary_v) constexpr explicit optional(in_place_t, Arg&& arg); template - requires(std::is_constructible_v && - !(std::is_same_v, in_place_t>) && + requires(std::is_constructible_v && !(std::is_same_v, in_place_t>) && !(std::is_same_v, optional>) && !std::reference_constructs_from_temporary_v) constexpr explicit(!std::is_convertible_v) @@ -36,8 +33,7 @@ class optional { } template - requires(std::is_constructible_v && - !(std::is_same_v, in_place_t>) && + requires(std::is_constructible_v && !(std::is_same_v, in_place_t>) && !(std::is_same_v, optional>) && std::reference_constructs_from_temporary_v) constexpr optional(U&& u) = delete; @@ -47,66 +43,47 @@ class optional { // allows correct constraints by propagating the value category from the // optional to the value within the rhs. template - requires(std::is_constructible_v && - !std::is_same_v, optional> && - !std::is_same_v && - !std::reference_constructs_from_temporary_v) - constexpr explicit(!std::is_convertible_v) optional( - optional& rhs) noexcept(std::is_nothrow_constructible_v); + requires(std::is_constructible_v && !std::is_same_v, optional> && + !std::is_same_v && !std::reference_constructs_from_temporary_v) + constexpr explicit(!std::is_convertible_v) + optional(optional& rhs) noexcept(std::is_nothrow_constructible_v); template - requires(std::is_constructible_v && - !std::is_same_v, optional> && - !std::is_same_v && - !std::reference_constructs_from_temporary_v) + requires(std::is_constructible_v && !std::is_same_v, optional> && + !std::is_same_v && !std::reference_constructs_from_temporary_v) constexpr explicit(!std::is_convertible_v) - optional(const optional& rhs) noexcept( - std::is_nothrow_constructible_v); + optional(const optional& rhs) noexcept(std::is_nothrow_constructible_v); template - requires(std::is_constructible_v && - !std::is_same_v, optional> && - !std::is_same_v && - !std::reference_constructs_from_temporary_v) + requires(std::is_constructible_v && !std::is_same_v, optional> && + !std::is_same_v && !std::reference_constructs_from_temporary_v) constexpr explicit(!std::is_convertible_v) - optional(optional&& rhs) noexcept( - noexcept(std::is_nothrow_constructible_v)); + optional(optional&& rhs) noexcept(noexcept(std::is_nothrow_constructible_v)); template - requires(std::is_constructible_v && - !std::is_same_v, optional> && - !std::is_same_v && - !std::reference_constructs_from_temporary_v) + requires(std::is_constructible_v && !std::is_same_v, optional> && + !std::is_same_v && !std::reference_constructs_from_temporary_v) constexpr explicit(!std::is_convertible_v) - optional(const optional&& rhs) noexcept( - noexcept(std::is_nothrow_constructible_v)); + optional(const optional&& rhs) noexcept(noexcept(std::is_nothrow_constructible_v)); template - requires(std::is_constructible_v && - !std::is_same_v, optional> && - !std::is_same_v && - std::reference_constructs_from_temporary_v) + requires(std::is_constructible_v && !std::is_same_v, optional> && + !std::is_same_v && std::reference_constructs_from_temporary_v) constexpr optional(optional& rhs) = delete; template - requires(std::is_constructible_v && - !std::is_same_v, optional> && - !std::is_same_v && - std::reference_constructs_from_temporary_v) + requires(std::is_constructible_v && !std::is_same_v, optional> && + !std::is_same_v && std::reference_constructs_from_temporary_v) constexpr optional(const optional& rhs) = delete; template - requires(std::is_constructible_v && - !std::is_same_v, optional> && - !std::is_same_v && - std::reference_constructs_from_temporary_v) + requires(std::is_constructible_v && !std::is_same_v, optional> && + !std::is_same_v && std::reference_constructs_from_temporary_v) constexpr optional(optional&& rhs) = delete; template - requires(std::is_constructible_v && - !std::is_same_v, optional> && - !std::is_same_v && - std::reference_constructs_from_temporary_v) + requires(std::is_constructible_v && !std::is_same_v, optional> && + !std::is_same_v && std::reference_constructs_from_temporary_v) constexpr optional(const optional&& rhs) = delete; // \ref{optionalref.dtor}, destructor @@ -118,10 +95,8 @@ class optional { constexpr optional& operator=(const optional& rhs) noexcept = default; template - requires(std::is_constructible_v && - !std::reference_constructs_from_temporary_v) - constexpr T& - emplace(U&& u) noexcept(std::is_nothrow_constructible_v); + requires(std::is_constructible_v && !std::reference_constructs_from_temporary_v) + constexpr T& emplace(U&& u) noexcept(std::is_nothrow_constructible_v); // \ref{optionalref.swap}, swap constexpr void swap(optional& rhs) noexcept; @@ -167,8 +142,7 @@ class optional { // \rSec3[optionalref.ctor]{Constructors} template template - requires(std::is_constructible_v && - !std::reference_constructs_from_temporary_v) + requires(std::is_constructible_v && !std::reference_constructs_from_temporary_v) constexpr optional::optional(in_place_t, Arg&& arg) { convert_ref_init_val(std::forward(arg)); } @@ -187,12 +161,9 @@ constexpr optional::optional(in_place_t, Arg&& arg) { template template - requires(std::is_constructible_v && - !std::is_same_v, optional> && - !std::is_same_v && - !std::reference_constructs_from_temporary_v) -constexpr optional::optional(optional& rhs) noexcept( - std::is_nothrow_constructible_v) { + requires(std::is_constructible_v && !std::is_same_v, optional> && + !std::is_same_v && !std::reference_constructs_from_temporary_v) +constexpr optional::optional(optional& rhs) noexcept(std::is_nothrow_constructible_v) { if (rhs.has_value()) { convert_ref_init_val(*rhs); } @@ -200,12 +171,9 @@ constexpr optional::optional(optional& rhs) noexcept( template template - requires(std::is_constructible_v && - !std::is_same_v, optional> && - !std::is_same_v && - !std::reference_constructs_from_temporary_v) -constexpr optional::optional(const optional& rhs) noexcept( - std::is_nothrow_constructible_v) { + requires(std::is_constructible_v && !std::is_same_v, optional> && + !std::is_same_v && !std::reference_constructs_from_temporary_v) +constexpr optional::optional(const optional& rhs) noexcept(std::is_nothrow_constructible_v) { if (rhs.has_value()) { convert_ref_init_val(*rhs); } @@ -213,12 +181,9 @@ constexpr optional::optional(const optional& rhs) noexcept( template template - requires(std::is_constructible_v && - !std::is_same_v, optional> && - !std::is_same_v && - !std::reference_constructs_from_temporary_v) -constexpr optional::optional(optional&& rhs) noexcept( - noexcept(std::is_nothrow_constructible_v)) { + requires(std::is_constructible_v && !std::is_same_v, optional> && + !std::is_same_v && !std::reference_constructs_from_temporary_v) +constexpr optional::optional(optional&& rhs) noexcept(noexcept(std::is_nothrow_constructible_v)) { if (rhs.has_value()) { convert_ref_init_val(*std::move(rhs)); } @@ -226,10 +191,8 @@ constexpr optional::optional(optional&& rhs) noexcept( template template - requires(std::is_constructible_v && - !std::is_same_v, optional> && - !std::is_same_v && - !std::reference_constructs_from_temporary_v) + requires(std::is_constructible_v && !std::is_same_v, optional> && + !std::is_same_v && !std::reference_constructs_from_temporary_v) constexpr optional::optional(const optional&& rhs) noexcept( noexcept(std::is_nothrow_constructible_v)) { if (rhs.has_value()) { @@ -246,10 +209,8 @@ constexpr optional& optional::operator=(nullopt_t) noexcept { template template - requires(std::is_constructible_v && - !std::reference_constructs_from_temporary_v) -constexpr T& -optional::emplace(U&& u) noexcept(std::is_nothrow_constructible_v) { + requires(std::is_constructible_v && !std::reference_constructs_from_temporary_v) +constexpr T& optional::emplace(U&& u) noexcept(std::is_nothrow_constructible_v) { convert_ref_init_val(std::forward(u)); return *value_; } @@ -301,12 +262,9 @@ constexpr T& optional::value() const { template template constexpr std::remove_cv_t optional::value_or(U&& u) const { - static_assert(std::is_constructible_v, T&>, - "T must be constructible from a T&"); - static_assert(std::is_convertible_v>, - "Must be able to convert u to T"); - return has_value() ? *value_ - : static_cast>(std::forward(u)); + static_assert(std::is_constructible_v, T&>, "T must be constructible from a T&"); + static_assert(std::is_convertible_v>, "Must be able to convert u to T"); + return has_value() ? *value_ : static_cast>(std::forward(u)); } // \rSec3[optionalref.monadic]{Monadic operations} @@ -324,15 +282,11 @@ constexpr auto optional::and_then(F&& f) const { template template -constexpr optional> -optional::transform(F&& f) const { +constexpr optional> optional::transform(F&& f) const { using U = std::invoke_result_t; - static_assert(!std::is_same_v, in_place_t>, - "Result must not be in_place_t"); - static_assert(!std::is_same_v, nullopt_t>, - "Result must not be nullopt_t"); - static_assert((std::is_object_v && !std::is_array_v) || - std::is_lvalue_reference_v, + static_assert(!std::is_same_v, in_place_t>, "Result must not be in_place_t"); + static_assert(!std::is_same_v, nullopt_t>, "Result must not be nullopt_t"); + static_assert((std::is_object_v && !std::is_array_v) || std::is_lvalue_reference_v, "Result must be an non-array object or an lvalue reference"); if (has_value()) { return optional{std::invoke(std::forward(f), *value_)}; @@ -345,8 +299,7 @@ template template constexpr optional optional::or_else(F&& f) const { using U = std::invoke_result_t; - static_assert(std::is_same_v, optional>, - "Result must be an optional"); + static_assert(std::is_same_v, optional>, "Result must be an optional"); if (has_value()) { return *value_; } else { @@ -364,15 +317,11 @@ constexpr void optional::reset() noexcept { namespace std { template requires requires(T a) { - { - std::hash>{}(a) - } -> std::convertible_to; + { std::hash>{}(a) } -> std::convertible_to; } struct hash> { - static_assert(!is_reference_v, - "hash is not enabled for reference types"); - size_t operator()(const beman::optional::optional& o) const - noexcept(noexcept(hash>{}(*o))) { + static_assert(!is_reference_v, "hash is not enabled for reference types"); + size_t operator()(const beman::optional::optional& o) const noexcept(noexcept(hash>{}(*o))) { if (o) { return std::hash>{}(*o); } else { diff --git a/tests/beman/expected/CMakeLists.txt b/tests/beman/expected/CMakeLists.txt index 8b9c100..6995659 100644 --- a/tests/beman/expected/CMakeLists.txt +++ b/tests/beman/expected/CMakeLists.txt @@ -78,7 +78,10 @@ if(NOT BEMAN_EXPECTED_USING_LIBCXX) beman.expected.tests.expected.std PRIVATE BEMAN_EXPECTED_TEST_STD ) - target_compile_features(beman.expected.tests.expected.std PRIVATE cxx_std_23) + target_compile_features( + beman.expected.tests.expected.std + PRIVATE cxx_std_23 + ) target_include_directories( beman.expected.tests.expected.std PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/tests diff --git a/tests/beman/expected/expected_ref.test.cpp b/tests/beman/expected/expected_ref.test.cpp index 26f6775..e014aaf 100644 --- a/tests/beman/expected/expected_ref.test.cpp +++ b/tests/beman/expected/expected_ref.test.cpp @@ -522,8 +522,8 @@ TEST_CASE("expected: const transform", "[expected_ref]") { TEST_CASE("expected: const transform on error - propagates", "[expected_ref]") { const expected e(unexpect, 5); - bool called = false; - auto r = e.transform([&](int&) { + bool called = false; + auto r = e.transform([&](int&) { called = true; return 0; }); diff --git a/tests/beman/expected/expected_review_corrections.test.cpp b/tests/beman/expected/expected_review_corrections.test.cpp index 1852f75..39acb99 100644 --- a/tests/beman/expected/expected_review_corrections.test.cpp +++ b/tests/beman/expected/expected_review_corrections.test.cpp @@ -67,7 +67,7 @@ TEST_CASE("reference-error construction from unexpected binds an external ob static_assert(std::is_assignable_v&, unexpected>); static_assert(std::is_assignable_v&, unexpected>); static_assert(std::is_assignable_v&, unexpected>); -static_assert(std::is_assignable_v&, unexpected>); // more-const OK +static_assert(std::is_assignable_v&, unexpected>); // more-const OK static_assert(!std::is_assignable_v&, unexpected>); // value G: deleted static_assert(!std::is_assignable_v&, unexpected>); // const drop: no overload @@ -80,7 +80,7 @@ TEST_CASE("rebinding assignment from unexpected repoints the error reference REQUIRE(&e.error() == &g2); // rebound to g2 REQUIRE(g1 == 1); // previously-referenced object untouched g2 = 42; - REQUIRE(e.error() == 42); // sees the new referent + REQUIRE(e.error() == 42); // sees the new referent } SECTION("value -> error transition (expected)") { expected e{7}; @@ -89,7 +89,7 @@ TEST_CASE("rebinding assignment from unexpected repoints the error reference REQUIRE(&e.error() == &g2); } SECTION("both references (expected)") { - int target = 5; + int target = 5; expected e{target}; e = unexpected(g2); REQUIRE_FALSE(e.has_value()); @@ -129,9 +129,9 @@ TEST_CASE("value constructor propagates a throwing reference conversion", "[ref] } TEST_CASE("emplace propagates a throwing reference conversion", "[ref][emplace][noexcept]") { - int target = 5; + int target = 5; expected e{target}; - int caught = 0; + int caught = 0; try { e.emplace(ThrowingRef{}); } catch (int v) { @@ -199,14 +199,14 @@ static_assert(!has_error_or&, NotConvertible>); TEST_CASE("converting from an rvalue reference expected does not steal the referent", "[ref][convert][shallow]") { SECTION("value side: expected <- expected&&") { - std::string s = "bar"; + std::string s = "bar"; expected r{s}; expected o{std::move(r)}; REQUIRE(s == "bar"); // referent untouched (copied, not moved) REQUIRE(o.value() == "bar"); } SECTION("value side, assignment") { - std::string s = "bar"; + std::string s = "bar"; expected r{s}; expected o{std::in_place, "x"}; o = std::move(r); @@ -214,7 +214,7 @@ TEST_CASE("converting from an rvalue reference expected does not steal the refer REQUIRE(o.value() == "bar"); } SECTION("error side: expected <- expected&&") { - std::string s = "bar"; + std::string s = "bar"; expected r{unexpect, s}; expected o{std::move(r)}; REQUIRE(s == "bar"); @@ -225,8 +225,8 @@ TEST_CASE("converting from an rvalue reference expected does not steal the refer TEST_CASE("constructing/assigning a value error from unexpected does not steal the referent", "[unexpected][convert][shallow]") { SECTION("construction") { - std::string s = "bar"; - expected o{unexpected(s)}; + std::string s = "bar"; + expected o{unexpected(s)}; REQUIRE(s == "bar"); // external referent copied, not moved REQUIRE(o.error() == "bar"); } diff --git a/tests/beman/expected/expected_void_monadic.test.cpp b/tests/beman/expected/expected_void_monadic.test.cpp index cb480de..fa2a414 100644 --- a/tests/beman/expected/expected_void_monadic.test.cpp +++ b/tests/beman/expected/expected_void_monadic.test.cpp @@ -281,7 +281,7 @@ TEST_CASE("or_else rvalue on error calls F", "[expected_void_monadic]") { TEST_CASE("or_else const rvalue on error calls F", "[expected_void_monadic]") { const expected e(unexpect, 5); - auto r = std::move(e).or_else([](int v) -> expected { return unexpected(v + 1); }); + auto r = std::move(e).or_else([](int v) -> expected { return unexpected(v + 1); }); REQUIRE(!r.has_value()); CHECK(r.error() == 6); }