diff --git a/.clang-format b/.clang-format index 0ac5d23..21a3082 100644 --- a/.clang-format +++ b/.clang-format @@ -1,10 +1,11 @@ --- +# vim: ft=yaml Language: Cpp BasedOnStyle: Microsoft AccessModifierOffset: -4 -AlignAfterOpenBracket: BlockIndent +AlignAfterOpenBracket: true AlignArrayOfStructures: Left AlignConsecutiveAssignments: Enabled: true @@ -20,7 +21,7 @@ AlignConsecutiveDeclarations: Enabled: true AcrossEmptyLines: false AcrossComments: true - #AlignFunctionDeclarations: false # only for AlignConsecutiveDeclarations # clang-format 20 + AlignFunctionDeclarations: true # only for AlignConsecutiveDeclarations # clang-format 20 AlignFunctionPointers: false # only for AlignConsecutiveDeclarations AlignConsecutiveMacros: Enabled: true @@ -43,6 +44,7 @@ AllowAllConstructorInitializersOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: true AllowBreakBeforeNoexceptSpecifier: Never +AllowBreakBeforeQtProperty: false # clang-format 22 AllowShortBlocksOnASingleLine: Empty AllowShortCaseExpressionOnASingleLine: true @@ -53,6 +55,7 @@ AllowShortFunctionsOnASingleLine: InlineOnly AllowShortIfStatementsOnASingleLine: Never AllowShortLambdasOnASingleLine: Inline AllowShortLoopsOnASingleLine: false +AllowShortNamespacesOnASingleLine: false # clang-format 20 AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: true @@ -64,8 +67,9 @@ AttributeMacros: - __ununsed - GSL_SUPPRESS -BinPackArguments: false -BinPackParameters: false +BinPackArguments: false +BinPackLongBracedList: true # clang-format 21 +BinPackParameters: OnePerLine BitFieldColonSpacing: Both BraceWrapping: @@ -90,12 +94,24 @@ BraceWrapping: BracedInitializerIndentWidth: 4 BreakAdjacentStringLiterals: true BreakAfterAttributes: Leave -BreakAfterReturnType: ExceptShortType +BreakAfterOpenBracketBracedList: true # clang-format 22 +BreakAfterOpenBracketFunction: true # clang-format 22 +BreakAfterOpenBracketIf: true # clang-format 22 +BreakAfterOpenBracketLoop: true # clang-format 22 +BreakAfterOpenBracketSwitch: true # clang-format 22 +BreakAfterReturnType: Automatic BreakBeforeBinaryOperators: None # TBD BreakBeforeBraces: Custom +BreakBeforeCloseBracketBracedList: true # clang-format 22 +BreakBeforeCloseBracketFunction: true # clang-format 22 +BreakBeforeCloseBracketIf: true # clang-format 22 +BreakBeforeCloseBracketLoop: true # clang-format 22 +BreakBeforeCloseBracketSwitch: true # clang-format 22 BreakBeforeConceptDeclarations: Always BreakBeforeInlineASMColon: Always +BreakBeforeTemplateCloser: true # clang-format 21 BreakBeforeTernaryOperators: false +BreakBinaryOperations: RespectPrecedence # clang-format 20 BreakConstructorInitializers: BeforeComma BreakFunctionDefinitionParameters: false BreakInheritanceList: BeforeComma @@ -108,7 +124,7 @@ CompactNamespaces: false ConstructorInitializerAllOnOneLineOrOnePerLine: true ConstructorInitializerIndentWidth: 4 ContinuationIndentWidth: 4 -Cpp11BracedListStyle: true +Cpp11BracedListStyle: FunctionCall # clang-format 22 DeriveLineEnding: true DerivePointerAlignment: true @@ -116,6 +132,7 @@ DerivePointerAlignment: true DisableFormat: false EmptyLineAfterAccessModifier: Leave EmptyLineBeforeAccessModifier: Leave +EnumTrailingComma: Leave # clang-format 21, not safe if not set to Leave FixNamespaceComments: true ForEachMacros: - foreach @@ -139,6 +156,7 @@ IncludeIsMainSourceRegex: "" IndentAccessModifiers: false IndentCaseBlocks: false IndentCaseLabels: false +IndentExportBlock: false # clang-format 20 IndentExternBlock: NoIndent IndentGotoLabels: false IndentPPDirectives: BeforeHash @@ -159,15 +177,25 @@ KeepEmptyLines: AtEndOfFile: true AtStartOfBlock: false AtStartOfFile: false +KeepFormFeed: true # clang-format 20 LambdaBodyIndentation: Signature MacroBlockBegin: "" # TBD MacroBlockEnd: "" # TBD Macros: [] # TBD -#MainIncludeChar: Quota # clang-format 20 +# A vector of function-like macros whose invocations should be skipped by RemoveParentheses. +MacrosSkippedByRemoveParentheses: [] # TBD, clang-format 21 +MainIncludeChar: Quote # clang-format 19 MaxEmptyLinesToKeep: 1 NamespaceIndentation: None NamespaceMacros: [] # TBD A vector of macros which are used to open namespace blocks. +NumericLiteralCase: # clang-format 22 + ExponentLetter: Leave + HexDigit: Leave + Prefix: Leave + Suffix: Leave + +OneLineFormatOffRegex: '' # clone-format 21 PPIndentWidth: -1 # default to IndentWidth PackConstructorInitializers: Never @@ -175,6 +203,7 @@ PackConstructorInitializers: Never # Penalty is hard to understand, leave it to default(style=Microsoft) #PenaltyBreakAssignment: 2 #PenaltyBreakBeforeFirstCallParameter: 19 +#PenaltyBreakBeforeMemberAccess: 150 # clang-format 20 #PenaltyBreakComment: 300 #PenaltyBreakFirstLessLess: 120 #PenaltyBreakOpenParenthesis: 0 @@ -195,6 +224,8 @@ ReferenceAlignment: Left ReflowComments: false +RemoveEmptyLinesInUnwrappedLines: true # clang-format 20 +RemoveParentheses: Leave # not safe if not Leave RemoveSemicolon: false # not safe if true RequiresClausePosition: OwnLine @@ -209,6 +240,7 @@ SortUsingDeclarations: false SpaceAfterCStyleCast: true SpaceAfterLogicalNot: false +SpaceAfterOperatorKeyword: false # clang-format 21 SpaceAfterTemplateKeyword: false SpaceAroundPointerQualifiers: Default @@ -268,6 +300,8 @@ WhitespaceSensitiveMacros: - PP_STRINGIZE - BOOST_PP_STRINGIZE +WrapNamespaceBodyWithEmptyLines: Always # clang-format 20 + --- Language: Json BreakArrays: false diff --git a/include/zeus/expected.hpp b/include/zeus/expected.hpp index 60ac325..bc36dcc 100644 --- a/include/zeus/expected.hpp +++ b/include/zeus/expected.hpp @@ -286,46 +286,49 @@ inline constexpr bool is_value_type_valid_v = is_value_type_valid::value; template using enable_forward_t = std::enable_if_t< - std::is_constructible_v && // - !std::is_same_v, std::in_place_t> && // - !std::is_same_v, expected_detail::remove_cvref_t> && // - !expected_detail::is_specialization_v, unexpected> && // - (!std::is_same_v, bool> || // LWG-3836 - !expected_detail::is_specialization_v, expected>) && // - !std::is_same_v, unexpect_t> // LWG-4222 - >; + std::is_constructible_v && + !std::is_same_v, std::in_place_t> && + !std::is_same_v, expected_detail::remove_cvref_t> && + !expected_detail::is_specialization_v, unexpected> && + (!std::is_same_v, bool> || // LWG-3836 + !expected_detail::is_specialization_v, expected>) && + !std::is_same_v, unexpect_t> // LWG-4222 +>; template using enable_from_other_expected_t = std::enable_if_t< - std::is_constructible_v && // - std::is_constructible_v && // + std::is_constructible_v && + std::is_constructible_v && std::disjunction_v< std::is_same, bool>, // LWG-3836 std::negation &>, // - std::is_constructible>, // - std::is_constructible &>, // - std::is_constructible>, // - std::is_convertible &, T>, // - std::is_convertible &&, T>, // - std::is_convertible &, T>, // - std::is_convertible &&, T>, // - std::is_constructible, expected &>, // - std::is_constructible, expected>, // - std::is_constructible, const expected &>, // - std::is_constructible, const expected> // - >>>>; + std::is_constructible &>, + std::is_constructible>, + std::is_constructible &>, + std::is_constructible>, + std::is_convertible &, T>, + std::is_convertible &&, T>, + std::is_convertible &, T>, + std::is_convertible &&, T>, + std::is_constructible, expected &>, + std::is_constructible, expected>, + std::is_constructible, const expected &>, + std::is_constructible, const expected> + >> + > +>; template using enable_from_other_void_expected_t = std::enable_if_t< - std::is_void_v && // - std::is_constructible_v && // - std::negation_v, expected &>, // - std::is_constructible, expected>, // - std::is_constructible, const expected &>, // - std::is_constructible, const expected> // - >>>; + std::is_void_v && + std::is_constructible_v && + std::negation_v, expected &>, + std::is_constructible, expected>, + std::is_constructible, const expected &>, + std::is_constructible, const expected> + >> +>; } // namespace expected_detail @@ -459,8 +462,9 @@ struct storage_base // helper ctor for transform() template - constexpr explicit storage_base(construct_with_invoke_result_t, Fn &&func, Args &&...args) // - noexcept(noexcept(static_cast(std::invoke(std::forward(func), std::forward(args)...)))) + constexpr explicit storage_base(construct_with_invoke_result_t, Fn &&func, Args &&...args) noexcept( + noexcept(static_cast(std::invoke(std::forward(func), std::forward(args)...))) + ) : m_val(std::invoke(std::forward(func), std::forward(args)...)) , m_has_val(true) { @@ -468,8 +472,9 @@ struct storage_base // helper ctor for transform_error() template - constexpr explicit storage_base(construct_with_invoke_result_t, unexpect_t, Fn &&func, Args &&...args) // - noexcept(noexcept(static_cast(std::invoke(std::forward(func), std::forward(args)...)))) + constexpr explicit storage_base(construct_with_invoke_result_t, unexpect_t, Fn &&func, Args &&...args) noexcept( + noexcept(static_cast(std::invoke(std::forward(func), std::forward(args)...))) + ) : m_unexpect(std::invoke(std::forward(func), std::forward(args)...)) , m_has_val(false) { @@ -539,8 +544,9 @@ struct storage_base // helper ctor for transform() template - constexpr explicit storage_base(construct_with_invoke_result_t, Fn &&func, Args &&...args) // - noexcept(noexcept(static_cast(std::invoke(std::forward(func), std::forward(args)...)))) + constexpr explicit storage_base(construct_with_invoke_result_t, Fn &&func, Args &&...args) noexcept( + noexcept(static_cast(std::invoke(std::forward(func), std::forward(args)...))) + ) : m_val(std::invoke(std::forward(func), std::forward(args)...)) , m_has_val(true) { @@ -548,8 +554,9 @@ struct storage_base // helper ctor for transform_error() template - constexpr explicit storage_base(construct_with_invoke_result_t, unexpect_t, Fn &&func, Args &&...args) // - noexcept(noexcept(static_cast(std::invoke(std::forward(func), std::forward(args)...)))) + constexpr explicit storage_base(construct_with_invoke_result_t, unexpect_t, Fn &&func, Args &&...args) noexcept( + noexcept(static_cast(std::invoke(std::forward(func), std::forward(args)...))) + ) : m_unexpect(std::invoke(std::forward(func), std::forward(args)...)) , m_has_val(false) { @@ -623,8 +630,9 @@ struct storage_base // helper ctor for transform_error() template - constexpr explicit storage_base(construct_with_invoke_result_t, unexpect_t, Fn &&func, Args &&...args) // - noexcept(noexcept(static_cast(std::invoke(std::forward(func), std::forward(args)...)))) + constexpr explicit storage_base(construct_with_invoke_result_t, unexpect_t, Fn &&func, Args &&...args) noexcept( + noexcept(static_cast(std::invoke(std::forward(func), std::forward(args)...))) + ) : m_unexpect(std::invoke(std::forward(func), std::forward(args)...)) , m_has_val(false) { @@ -686,8 +694,9 @@ struct storage_base // helper ctor for transform_error() template - constexpr explicit storage_base(construct_with_invoke_result_t, unexpect_t, Fn &&func, Args &&...args) // - noexcept(noexcept(static_cast(std::invoke(std::forward(func), std::forward(args)...)))) + constexpr explicit storage_base(construct_with_invoke_result_t, unexpect_t, Fn &&func, Args &&...args) noexcept( + noexcept(static_cast(std::invoke(std::forward(func), std::forward(args)...))) + ) : m_unexpect(std::invoke(std::forward(func), std::forward(args)...)) , m_has_val(false) { @@ -722,24 +731,21 @@ struct operations_base : storage_base using storage_base::storage_base; template - constexpr void construct(Args &&...args) // - noexcept(std::is_nothrow_constructible_v) + constexpr void construct(Args &&...args) noexcept(std::is_nothrow_constructible_v) { expected_detail::construct_at(&this->m_val, std::forward(args)...); this->m_has_val = true; } template - constexpr void construct_with(Rhs &&rhs) // - noexcept(std::is_nothrow_constructible_v) + constexpr void construct_with(Rhs &&rhs) noexcept(std::is_nothrow_constructible_v) { expected_detail::construct_at(&this->m_val, std::forward(rhs).get()); this->m_has_val = true; } template - constexpr void construct_error(Args &&...args) // - noexcept(std::is_nothrow_constructible_v) + constexpr void construct_error(Args &&...args) noexcept(std::is_nothrow_constructible_v) { expected_detail::construct_at(&this->m_unexpect, std::forward(args)...); this->m_has_val = false; @@ -774,8 +780,7 @@ struct operations_base : storage_base } template - constexpr void construct_error(Args &&...args) // - noexcept(std::is_nothrow_constructible_v) + constexpr void construct_error(Args &&...args) noexcept(std::is_nothrow_constructible_v) { expected_detail::construct_at(&this->m_unexpect, std::forward(args)...); this->m_has_val = false; @@ -791,9 +796,10 @@ struct operations_base : storage_base // This specialization is for when T and E are trivially copy constructible template< class T, - class E, // - bool Enabled = is_copy_constructible_or_void_v && std::is_copy_constructible_v, // - bool Trivially = is_trivially_copy_constructible_or_void_v && std::is_trivially_copy_constructible_v> + class E, + bool Enabled = is_copy_constructible_or_void_v && std::is_copy_constructible_v, + bool Trivially = is_trivially_copy_constructible_or_void_v && std::is_trivially_copy_constructible_v +> struct copy_ctor_base : operations_base { using operations_base::operations_base; @@ -822,8 +828,9 @@ struct copy_ctor_base : operations_base ~copy_ctor_base() = default; copy_ctor_base() = default; - constexpr copy_ctor_base(const copy_ctor_base &rhs) // - noexcept(is_nothrow_copy_constructible_or_void_v && std::is_nothrow_copy_constructible_v) + constexpr copy_ctor_base( + const copy_ctor_base &rhs + ) noexcept(is_nothrow_copy_constructible_or_void_v && std::is_nothrow_copy_constructible_v) : operations_base(no_init) { if (rhs.m_has_val) @@ -845,8 +852,9 @@ struct copy_ctor_base : operations_base template< class T, class E, - bool Enabled = is_move_constructible_or_void_v && std::is_move_constructible_v, // - bool Trivially = is_trivially_move_constructible_or_void_v && std::is_trivially_move_constructible_v> + bool Enabled = is_move_constructible_or_void_v && std::is_move_constructible_v, + bool Trivially = is_trivially_move_constructible_or_void_v && std::is_trivially_move_constructible_v +> struct move_ctor_base : copy_ctor_base { using copy_ctor_base::copy_ctor_base; @@ -876,8 +884,9 @@ struct move_ctor_base : copy_ctor_base move_ctor_base() = default; move_ctor_base(const move_ctor_base &rhs) = default; - constexpr move_ctor_base(move_ctor_base &&rhs) // - noexcept(is_nothrow_move_constructible_or_void_v && std::is_nothrow_move_constructible_v) + constexpr move_ctor_base( + move_ctor_base &&rhs + ) noexcept(is_nothrow_move_constructible_or_void_v && std::is_nothrow_move_constructible_v) : copy_ctor_base(no_init) { if (rhs.m_has_val) @@ -895,27 +904,29 @@ struct move_ctor_base : copy_ctor_base }; template -inline constexpr bool is_expected_copy_assignable_v = // - is_copy_assignable_or_void_v && is_copy_constructible_or_void_v && // - std::is_copy_assignable_v && std::is_copy_constructible_v && // +inline constexpr bool is_expected_copy_assignable_v = + is_copy_assignable_or_void_v && + is_copy_constructible_or_void_v && + std::is_copy_assignable_v && + std::is_copy_constructible_v && (is_nothrow_move_constructible_or_void_v || std::is_nothrow_move_constructible_v); // LWG-4026 template -inline constexpr bool is_expected_trivially_copy_assignable_v = // - is_trivially_copy_constructible_or_void_v && // - is_trivially_copy_assignable_or_void_v && // - is_trivially_destructible_or_void_v && // - std::is_trivially_copy_constructible_v && // - std::is_trivially_copy_assignable_v && // - std::is_trivially_destructible_v; +inline constexpr bool is_expected_trivially_copy_assignable_v = is_trivially_copy_constructible_or_void_v && + is_trivially_copy_assignable_or_void_v && + is_trivially_destructible_or_void_v && + std::is_trivially_copy_constructible_v && + std::is_trivially_copy_assignable_v && + std::is_trivially_destructible_v; // This class manages conditionally having a (possibly trivial) copy assignment operator template< class T, class E, - bool Enabled = is_expected_copy_assignable_v, // - bool Trivially = is_expected_trivially_copy_assignable_v> + bool Enabled = is_expected_copy_assignable_v, + bool Trivially = is_expected_trivially_copy_assignable_v +> struct copy_assign_base : move_ctor_base { using move_ctor_base::move_ctor_base; @@ -951,11 +962,12 @@ struct copy_assign_base : move_ctor_base copy_assign_base(const copy_assign_base &rhs) = default; copy_assign_base(copy_assign_base &&rhs) = default; - constexpr copy_assign_base &operator=(const copy_assign_base &rhs) // - noexcept( - std::is_nothrow_copy_constructible_v && std::is_nothrow_copy_assignable_v && std::is_nothrow_copy_constructible_v && - std::is_nothrow_copy_assignable_v - ) + constexpr copy_assign_base &operator=(const copy_assign_base &rhs) noexcept( + std::is_nothrow_copy_constructible_v && + std::is_nothrow_copy_assignable_v && + std::is_nothrow_copy_constructible_v && + std::is_nothrow_copy_assignable_v + ) { if (this->m_has_val && rhs.m_has_val) { @@ -990,8 +1002,9 @@ struct copy_assign_base : move_ctor_base copy_assign_base(const copy_assign_base &rhs) = default; copy_assign_base(copy_assign_base &&rhs) = default; - constexpr copy_assign_base &operator=(const copy_assign_base &rhs) // - noexcept(std::is_nothrow_copy_constructible_v && std::is_nothrow_copy_assignable_v) + constexpr copy_assign_base &operator=( + const copy_assign_base &rhs + ) noexcept(std::is_nothrow_copy_constructible_v && std::is_nothrow_copy_assignable_v) { if (this->m_has_val && rhs.m_has_val) { @@ -1018,27 +1031,29 @@ struct copy_assign_base : move_ctor_base }; template -inline constexpr bool is_expected_move_assignable_v = // - is_move_assignable_or_void_v && is_move_constructible_or_void_v && // - std::is_move_assignable_v && std::is_move_constructible_v && // +inline constexpr bool is_expected_move_assignable_v = + is_move_assignable_or_void_v && + is_move_constructible_or_void_v && + std::is_move_assignable_v && + std::is_move_constructible_v && (is_nothrow_move_constructible_or_void_v || std::is_nothrow_move_constructible_v); // LWG-4026 template -inline constexpr bool is_expected_trivially_move_assignable_v = // - is_trivially_move_constructible_or_void_v && // - is_trivially_move_assignable_or_void_v && // - is_trivially_destructible_or_void_v && // - std::is_trivially_move_constructible_v && // - std::is_trivially_move_assignable_v && // - std::is_trivially_destructible_v; +inline constexpr bool is_expected_trivially_move_assignable_v = is_trivially_move_constructible_or_void_v && + is_trivially_move_assignable_or_void_v && + is_trivially_destructible_or_void_v && + std::is_trivially_move_constructible_v && + std::is_trivially_move_assignable_v && + std::is_trivially_destructible_v; // This class manages conditionally having a (possibly trivial) move assignment operator template< class T, class E, - bool Enabled = is_expected_move_assignable_v, // - bool Trivially = is_expected_trivially_move_assignable_v> + bool Enabled = is_expected_move_assignable_v, + bool Trivially = is_expected_trivially_move_assignable_v +> struct move_assign_base : copy_assign_base { using copy_assign_base::copy_assign_base; @@ -1075,11 +1090,12 @@ struct move_assign_base : copy_assign_base move_assign_base(move_assign_base &&rhs) = default; move_assign_base &operator=(const move_assign_base &rhs) = default; - constexpr move_assign_base &operator=(move_assign_base &&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 move_assign_base &operator=(move_assign_base &&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 + ) { if (this->m_has_val && rhs.m_has_val) { @@ -1113,8 +1129,9 @@ struct move_assign_base : copy_assign_base move_assign_base(move_assign_base &&rhs) = default; move_assign_base &operator=(const move_assign_base &rhs) = default; - constexpr move_assign_base &operator=(move_assign_base &&rhs) // - noexcept(std::is_nothrow_move_constructible_v && std::is_nothrow_move_assignable_v) + constexpr move_assign_base &operator=( + move_assign_base &&rhs + ) noexcept(std::is_nothrow_move_constructible_v && std::is_nothrow_move_assignable_v) { if (this->m_has_val && rhs.m_has_val) { @@ -1174,6 +1191,7 @@ struct default_ctor_base constexpr explicit default_ctor_base(default_constructor_tag) {} }; + } // namespace expected_detail /// An `expected` object is an object that contains the storage for @@ -1223,13 +1241,15 @@ class expected // implicit const reference template< - class U, // - class G, // - std::enable_if_t, expected>> * = nullptr, // - std::enable_if_t && std::is_convertible_v> * = nullptr, // - expected_detail::enable_from_other_expected_t * = nullptr> - constexpr expected(const expected &rhs) // - noexcept(std::is_nothrow_constructible_v && std::is_nothrow_constructible_v) + class U, + class G, + std::enable_if_t, expected>> * = nullptr, + std::enable_if_t && std::is_convertible_v> * = nullptr, + expected_detail::enable_from_other_expected_t * = nullptr + > + constexpr expected( + const expected &rhs + ) noexcept(std::is_nothrow_constructible_v && std::is_nothrow_constructible_v) : ctor_base(expected_detail::default_constructor_tag {}) { if (rhs.has_value()) @@ -1244,13 +1264,15 @@ class expected // explicit const reference template< - class U, // - class G, // - std::enable_if_t, expected>> * = nullptr, // - std::enable_if_t && std::is_convertible_v)> * = nullptr, // - expected_detail::enable_from_other_expected_t * = nullptr> - constexpr explicit expected(const expected &rhs) // - noexcept(std::is_nothrow_constructible_v && std::is_nothrow_constructible_v) + class U, + class G, + std::enable_if_t, expected>> * = nullptr, + std::enable_if_t && std::is_convertible_v)> * = nullptr, + expected_detail::enable_from_other_expected_t * = nullptr + > + constexpr explicit expected( + const expected &rhs + ) noexcept(std::is_nothrow_constructible_v && std::is_nothrow_constructible_v) : ctor_base(expected_detail::default_constructor_tag {}) { if (rhs.has_value()) @@ -1265,13 +1287,13 @@ class expected // implicit rvalue template< - class U, // - class G, // - std::enable_if_t, expected>> * = nullptr, // - std::enable_if_t && std::is_convertible_v> * = nullptr, // - expected_detail::enable_from_other_expected_t * = nullptr> - constexpr expected(expected &&rhs) // - noexcept(std::is_nothrow_constructible_v && std::is_nothrow_constructible_v) + class U, + class G, + std::enable_if_t, expected>> * = nullptr, + std::enable_if_t && std::is_convertible_v> * = nullptr, + expected_detail::enable_from_other_expected_t * = nullptr + > + constexpr expected(expected &&rhs) noexcept(std::is_nothrow_constructible_v && std::is_nothrow_constructible_v) : ctor_base(expected_detail::default_constructor_tag {}) { if (rhs.has_value()) @@ -1286,13 +1308,15 @@ class expected // explicit rvalue template< - class U, // - class G, // - std::enable_if_t, expected>> * = nullptr, // - std::enable_if_t && std::is_convertible_v)> * = nullptr, // - expected_detail::enable_from_other_expected_t * = nullptr> - constexpr explicit expected(expected &&rhs) // - noexcept(std::is_nothrow_constructible_v && std::is_nothrow_constructible_v) + class U, + class G, + std::enable_if_t, expected>> * = nullptr, + std::enable_if_t && std::is_convertible_v)> * = nullptr, + expected_detail::enable_from_other_expected_t * = nullptr + > + constexpr explicit expected( + expected &&rhs + ) noexcept(std::is_nothrow_constructible_v && std::is_nothrow_constructible_v) : ctor_base(expected_detail::default_constructor_tag {}) { if (rhs.has_value()) @@ -1312,7 +1336,8 @@ class expected template< class U = std::remove_cv_t, std::enable_if_t> * = nullptr, - expected_detail::enable_forward_t * = nullptr> + expected_detail::enable_forward_t * = nullptr + > constexpr expected(U &&v) noexcept(std::is_nothrow_constructible_v) : expected(std::in_place, std::forward(v)) { @@ -1322,7 +1347,8 @@ class expected template< class U = std::remove_cv_t, std::enable_if_t> * = nullptr, - expected_detail::enable_forward_t * = nullptr> + expected_detail::enable_forward_t * = nullptr + > constexpr explicit expected(U &&v) noexcept(std::is_nothrow_constructible_v) : expected(std::in_place, std::forward(v)) { @@ -1332,9 +1358,10 @@ class expected // explicit const unexpected & template< - class G, // - std::enable_if_t> * = nullptr, // - std::enable_if_t> * = nullptr> + class G, + std::enable_if_t> * = nullptr, + std::enable_if_t> * = nullptr + > explicit constexpr expected(const unexpected &e) noexcept(std::is_nothrow_constructible_v) : impl_base(unexpect, e.error()) , ctor_base(expected_detail::default_constructor_tag {}) @@ -1343,9 +1370,10 @@ class expected // implicit const unexpected & template< - class G, // - std::enable_if_t> * = nullptr, // - std::enable_if_t> * = nullptr> + class G, + std::enable_if_t> * = nullptr, + std::enable_if_t> * = nullptr + > constexpr expected(unexpected const &e) noexcept(std::is_nothrow_constructible_v) : impl_base(unexpect, e.error()) , ctor_base(expected_detail::default_constructor_tag {}) @@ -1354,9 +1382,10 @@ class expected // explicit unexpected && template< - class G, // - std::enable_if_t> * = nullptr, // - std::enable_if_t> * = nullptr> + class G, + std::enable_if_t> * = nullptr, + std::enable_if_t> * = nullptr + > explicit constexpr expected(unexpected &&e) noexcept(std::is_nothrow_constructible_v) : impl_base(unexpect, std::move(e.error())) , ctor_base(expected_detail::default_constructor_tag {}) @@ -1365,9 +1394,10 @@ class expected // implicit unexpected && template< - class G, // - std::enable_if_t> * = nullptr, // - std::enable_if_t> * = nullptr> + class G, + std::enable_if_t> * = nullptr, + std::enable_if_t> * = nullptr + > constexpr expected(unexpected &&e) noexcept(std::is_nothrow_constructible_v) : impl_base(unexpect, std::move(e.error())) , ctor_base(expected_detail::default_constructor_tag {}) @@ -1378,8 +1408,7 @@ class expected // expected(std::in_place_t, Args &&...) template> * = nullptr> - constexpr explicit expected(std::in_place_t, Args &&...args) // - noexcept(std::is_nothrow_constructible_v) + constexpr explicit expected(std::in_place_t, Args &&...args) noexcept(std::is_nothrow_constructible_v) : impl_base(std::in_place, std::forward(args)...) , ctor_base(expected_detail::default_constructor_tag {}) { @@ -1389,8 +1418,9 @@ class expected // expected(std::in_place_t, std::initializer_list, Args &&...) template &, Args...>> * = nullptr> - constexpr explicit expected(std::in_place_t, std::initializer_list il, Args &&...args) // - noexcept(std::is_nothrow_constructible_v &, Args...>) + constexpr explicit expected( + std::in_place_t, std::initializer_list il, Args &&...args + ) noexcept(std::is_nothrow_constructible_v &, Args...>) : impl_base(std::in_place, il, std::forward(args)...) , ctor_base(expected_detail::default_constructor_tag {}) { @@ -1398,8 +1428,9 @@ class expected // helper ctor for transform() template - constexpr explicit expected(expected_detail::construct_with_invoke_result_t tag, Fn &&func, Args &&...args) // - noexcept(noexcept(static_cast(std::invoke(std::forward(func), std::forward(args)...)))) + constexpr explicit expected(expected_detail::construct_with_invoke_result_t tag, Fn &&func, Args &&...args) noexcept( + noexcept(static_cast(std::invoke(std::forward(func), std::forward(args)...))) + ) : impl_base(tag, std::forward(func), std::forward(args)...) , ctor_base(expected_detail::default_constructor_tag {}) { @@ -1409,8 +1440,7 @@ class expected // expected(unexpect_t, Args &&...) template> * = nullptr> - constexpr explicit expected(unexpect_t, Args &&...args) // - noexcept(std::is_nothrow_constructible_v) + constexpr explicit expected(unexpect_t, Args &&...args) noexcept(std::is_nothrow_constructible_v) : impl_base(unexpect, std::forward(args)...) , ctor_base(expected_detail::default_constructor_tag {}) { @@ -1420,8 +1450,9 @@ class expected // expected(unexpect_t, std::initializer_list, Args &&...) template &, Args...>> * = nullptr> - constexpr explicit expected(unexpect_t, std::initializer_list il, Args &&...args) // - noexcept(std::is_nothrow_constructible_v &, Args...>) + constexpr explicit expected( + unexpect_t, std::initializer_list il, Args &&...args + ) noexcept(std::is_nothrow_constructible_v &, Args...>) : impl_base(unexpect, il, std::forward(args)...) , ctor_base(expected_detail::default_constructor_tag {}) { @@ -1429,8 +1460,9 @@ class expected // helper ctor for transform_error() template - constexpr explicit expected(expected_detail::construct_with_invoke_result_t tag1, unexpect_t tag2, Fn &&func, Args &&...args) // - noexcept(noexcept(static_cast(std::invoke(std::forward(func), std::forward(args)...)))) + constexpr explicit expected(expected_detail::construct_with_invoke_result_t tag1, unexpect_t tag2, Fn &&func, Args &&...args) noexcept( + noexcept(static_cast(std::invoke(std::forward(func), std::forward(args)...))) + ) : impl_base(tag1, tag2, std::forward(func), std::forward(args)...) , ctor_base(expected_detail::default_constructor_tag {}) { @@ -1445,17 +1477,15 @@ class expected template< class U = std::remove_cv_t, - std::enable_if_t< // - !std::is_same_v> && // - !expected_detail::is_specialization_v, unexpected> && // - std::is_constructible_v && // - std::is_assignable_v && // - (std::is_nothrow_constructible_v || // - std::is_nothrow_move_constructible_v || // - std::is_nothrow_move_constructible_v) // - > * = nullptr> - constexpr expected &operator=(U &&v) // - noexcept(std::is_nothrow_constructible_v && std::is_nothrow_assignable_v) + std::enable_if_t< + !std::is_same_v> && + !expected_detail::is_specialization_v, unexpected> && + std::is_constructible_v && + std::is_assignable_v && + (std::is_nothrow_constructible_v || std::is_nothrow_move_constructible_v || std::is_nothrow_move_constructible_v) + > * = nullptr + > + constexpr expected &operator=(U &&v) noexcept(std::is_nothrow_constructible_v && std::is_nothrow_assignable_v) { if (has_value()) { @@ -1471,17 +1501,17 @@ class expected } template< - class G, // - class GF = const G &, // - std::enable_if_t< // - std::is_constructible_v && // - std::is_assignable_v && // - (std::is_nothrow_constructible_v || // - std::is_nothrow_move_constructible_v || // - std::is_nothrow_move_constructible_v) // - > * = nullptr> - constexpr expected &operator=(const unexpected &rhs) // - noexcept(std::is_nothrow_constructible_v && std::is_nothrow_assignable_v) + class G, + class GF = const G &, + std::enable_if_t< + std::is_constructible_v && + std::is_assignable_v && + (std::is_nothrow_constructible_v || std::is_nothrow_move_constructible_v || std::is_nothrow_move_constructible_v) + > * = nullptr + > + constexpr expected &operator=( + const unexpected &rhs + ) noexcept(std::is_nothrow_constructible_v && std::is_nothrow_assignable_v) { if (!has_value()) { @@ -1497,17 +1527,17 @@ class expected } template< - class G, // - class GF = G, // - std::enable_if_t< // - std::is_constructible_v && // - std::is_assignable_v && // - (std::is_nothrow_constructible_v || // - std::is_nothrow_move_constructible_v || // - std::is_nothrow_move_constructible_v) // - > * = nullptr> - constexpr expected &operator=(unexpected &&rhs) // - noexcept(std::is_nothrow_constructible_v && std::is_nothrow_assignable_v) + class G, + class GF = G, + std::enable_if_t< + std::is_constructible_v && + std::is_assignable_v && + (std::is_nothrow_constructible_v || std::is_nothrow_move_constructible_v || std::is_nothrow_move_constructible_v) + > * = nullptr + > + constexpr expected &operator=( + unexpected &&rhs + ) noexcept(std::is_nothrow_constructible_v && std::is_nothrow_assignable_v) { if (!has_value()) { @@ -1547,7 +1577,8 @@ class expected template< class U, class... Args, - std::enable_if_t &, Args &&...>> * = nullptr> + std::enable_if_t &, Args &&...>> * = nullptr + > constexpr T &emplace(std::initializer_list il, Args &&...args) { if (has_value()) @@ -1571,14 +1602,18 @@ class expected template constexpr std::enable_if_t< - std::is_swappable_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)> - swap(expected &rhs) // - noexcept( - std::is_nothrow_move_constructible_v && std::is_nothrow_swappable_v && // - std::is_nothrow_move_constructible_v && std::is_nothrow_swappable_v - ) + std::is_swappable_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) + > + swap(expected &rhs) noexcept( + std::is_nothrow_move_constructible_v && + std::is_nothrow_swappable_v && + std::is_nothrow_move_constructible_v && + std::is_nothrow_swappable_v + ) { using std::swap; if (this->m_has_val && rhs.m_has_val) @@ -1647,22 +1682,10 @@ class expected constexpr const T *operator->() const noexcept { return valptr(); } constexpr T *operator->() noexcept { return valptr(); } - constexpr const T &operator*() const & noexcept // - { - return val(); - } - constexpr T &operator*() & noexcept // - { - return val(); - } - constexpr const T &&operator*() const && noexcept // - { - return std::move(val()); - } - constexpr T &&operator*() && noexcept // - { - return std::move(val()); - } + constexpr const T &operator*() const &noexcept { return val(); } + constexpr T &operator*() &noexcept { return val(); } + constexpr const T &&operator*() const && noexcept { return std::move(val()); } + constexpr T &&operator*() &&noexcept { return std::move(val()); } constexpr bool has_value() const noexcept { return this->m_has_val; } constexpr explicit operator bool() const noexcept { return this->m_has_val; } @@ -1698,26 +1721,13 @@ class expected return std::move(val()); } - constexpr const E &error() const & noexcept // - { - return err(); - } - constexpr E &error() & noexcept // - { - return err(); - } - constexpr const E &&error() const && noexcept // - { - return std::move(err()); - } - constexpr E &&error() && noexcept // - { - return std::move(err()); - } + constexpr const E &error() const &noexcept { return err(); } + constexpr E &error() &noexcept { return err(); } + constexpr const E &&error() const && noexcept { return std::move(err()); } + constexpr E &&error() &&noexcept { return std::move(err()); } template> - constexpr T value_or(U &&v) const & // - noexcept(std::is_nothrow_copy_constructible_v && expected_detail::is_nothrow_convertible_v) + constexpr T value_or(U &&v) const & noexcept(std::is_nothrow_copy_constructible_v && expected_detail::is_nothrow_convertible_v) { static_assert(std::is_copy_constructible_v, "T must be copy-constructible"); static_assert(std::is_convertible_v, "is_convertible_v must be true"); @@ -1731,8 +1741,7 @@ class expected } } template> - constexpr T value_or(U &&v) && // - noexcept(std::is_nothrow_move_constructible_v && expected_detail::is_nothrow_convertible_v) + constexpr T value_or(U &&v) && noexcept(std::is_nothrow_move_constructible_v && expected_detail::is_nothrow_convertible_v) { static_assert(std::is_move_constructible_v, "T must be move-constructible"); static_assert(std::is_convertible_v, "is_convertible_v must be true"); @@ -1747,8 +1756,7 @@ class expected } template - constexpr E error_or(G &&v) const & // - noexcept(std::is_nothrow_copy_constructible_v && expected_detail::is_nothrow_convertible_v) + constexpr E error_or(G &&v) const & noexcept(std::is_nothrow_copy_constructible_v && expected_detail::is_nothrow_convertible_v) { static_assert(std::is_copy_constructible_v, "E must be copy-constructible"); static_assert(std::is_convertible_v, "is_convertible_v must be true"); @@ -1762,8 +1770,7 @@ class expected } } template - constexpr E error_or(G &&v) && // - noexcept(std::is_nothrow_move_constructible_v && expected_detail::is_nothrow_convertible_v) + constexpr E error_or(G &&v) && noexcept(std::is_nothrow_move_constructible_v && expected_detail::is_nothrow_convertible_v) { static_assert(std::is_move_constructible_v, "E must be move-constructible"); static_assert(std::is_convertible_v, "is_convertible_v must be true"); @@ -2030,8 +2037,9 @@ class expected } template - [[nodiscard]] friend constexpr std::enable_if_t, bool> operator==(const expected &x, const expected &y) // - noexcept(noexcept(*x == *y) && noexcept(x.error() == y.error())) + [[nodiscard]] friend constexpr std::enable_if_t, bool> operator==( + const expected &x, const expected &y + ) noexcept(noexcept(*x == *y) && noexcept(x.error() == y.error())) { if (x.has_value() != y.has_value()) { @@ -2048,16 +2056,16 @@ class expected } #if ZEUS_EXPECTED_CPLUSPLUS < 202'002L template - [[nodiscard]] friend constexpr std::enable_if_t, bool> operator!=(const expected &x, const expected &y) // - noexcept(noexcept(x == y)) + [[nodiscard]] friend constexpr std::enable_if_t, bool> operator!=( + const expected &x, const expected &y + ) noexcept(noexcept(x == y)) { return !(x == y); } #endif template - [[nodiscard]] friend constexpr bool operator==(const expected &x, const T2 &v) // - noexcept(noexcept(*x == v)) + [[nodiscard]] friend constexpr bool operator==(const expected &x, const T2 &v) noexcept(noexcept(*x == v)) { if (x.has_value()) { @@ -2070,32 +2078,28 @@ class expected } #if ZEUS_EXPECTED_CPLUSPLUS < 202'002L template - [[nodiscard]] friend constexpr bool operator!=(const expected &x, const T2 &v) // - noexcept(noexcept(x == v)) + [[nodiscard]] friend constexpr bool operator!=(const expected &x, const T2 &v) noexcept(noexcept(x == v)) { return !(x == v); } template [[nodiscard]] friend constexpr std::enable_if_t, bool> operator==( const T2 &v, const expected &x - ) // - noexcept(noexcept(x == v)) + ) noexcept(noexcept(x == v)) { return x == v; } template [[nodiscard]] friend constexpr std::enable_if_t, bool> operator!=( const T2 &v, const expected &x - ) // - noexcept(noexcept(x == v)) + ) noexcept(noexcept(x == v)) { return x != v; } #endif template - [[nodiscard]] friend constexpr bool operator==(const expected &x, const unexpected &e) // - noexcept(noexcept(x.error() == e.error())) + [[nodiscard]] friend constexpr bool operator==(const expected &x, const unexpected &e) noexcept(noexcept(x.error() == e.error())) { if (x.has_value()) { @@ -2108,20 +2112,17 @@ class expected } #if ZEUS_EXPECTED_CPLUSPLUS < 202'002L template - [[nodiscard]] friend constexpr bool operator!=(const expected &x, const unexpected &e) // - noexcept(noexcept(x == e)) + [[nodiscard]] friend constexpr bool operator!=(const expected &x, const unexpected &e) noexcept(noexcept(x == e)) { return !(x == e); } template - [[nodiscard]] friend constexpr bool operator==(const unexpected &e, const expected &x) // - noexcept(noexcept(x == e)) + [[nodiscard]] friend constexpr bool operator==(const unexpected &e, const expected &x) noexcept(noexcept(x == e)) { return x == e; } template - [[nodiscard]] friend constexpr bool operator!=(const unexpected &e, const expected &x) // - noexcept(noexcept(x == e)) + [[nodiscard]] friend constexpr bool operator!=(const unexpected &e, const expected &x) noexcept(noexcept(x == e)) { return x != e; } @@ -2133,10 +2134,14 @@ template< class T, class E, std::enable_if_t< - !std::is_void_v && // - std::is_move_constructible_v && std::is_swappable_v && // - std::is_move_constructible_v && std::is_swappable_v && // - (std::is_nothrow_move_constructible_v || std::is_nothrow_move_constructible_v)> * = nullptr> + !std::is_void_v && + std::is_move_constructible_v && + std::is_swappable_v && + std::is_move_constructible_v && + std::is_swappable_v && + (std::is_nothrow_move_constructible_v || std::is_nothrow_move_constructible_v) + > * = nullptr +> constexpr void swap(expected &lhs, expected &rhs) noexcept(noexcept(lhs.swap(rhs))) { lhs.swap(rhs); @@ -2178,13 +2183,13 @@ class expected constexpr expected(expected &&rhs) = default; template< - class U, // - class G, // - std::enable_if_t, expected>> * = nullptr, // - std::enable_if_t> * = nullptr, // - expected_detail::enable_from_other_void_expected_t * = nullptr> - constexpr expected(const expected &rhs) // - noexcept(std::is_nothrow_constructible_v) + class U, + class G, + std::enable_if_t, expected>> * = nullptr, + std::enable_if_t> * = nullptr, + expected_detail::enable_from_other_void_expected_t * = nullptr + > + constexpr expected(const expected &rhs) noexcept(std::is_nothrow_constructible_v) : ctor_base(expected_detail::default_constructor_tag {}) { if (rhs.has_value()) @@ -2198,13 +2203,13 @@ class expected } template< - class U, // - class G, // - std::enable_if_t, expected>> * = nullptr, // - std::enable_if_t> * = nullptr, // - expected_detail::enable_from_other_void_expected_t * = nullptr> - constexpr explicit expected(const expected &rhs) // - noexcept(std::is_nothrow_constructible_v) + class U, + class G, + std::enable_if_t, expected>> * = nullptr, + std::enable_if_t> * = nullptr, + expected_detail::enable_from_other_void_expected_t * = nullptr + > + constexpr explicit expected(const expected &rhs) noexcept(std::is_nothrow_constructible_v) : ctor_base(expected_detail::default_constructor_tag {}) { if (rhs.has_value()) @@ -2218,13 +2223,13 @@ class expected } template< - class U, // - class G, // - std::enable_if_t, expected>> * = nullptr, // - std::enable_if_t> * = nullptr, // - expected_detail::enable_from_other_void_expected_t * = nullptr> - constexpr expected(expected &&rhs) // - noexcept(std::is_nothrow_constructible_v) + class U, + class G, + std::enable_if_t, expected>> * = nullptr, + std::enable_if_t> * = nullptr, + expected_detail::enable_from_other_void_expected_t * = nullptr + > + constexpr expected(expected &&rhs) noexcept(std::is_nothrow_constructible_v) : ctor_base(expected_detail::default_constructor_tag {}) { if (rhs.has_value()) @@ -2238,13 +2243,13 @@ class expected } template< - class U, // - class G, // - std::enable_if_t, expected>> * = nullptr, // - std::enable_if_t> * = nullptr, // - expected_detail::enable_from_other_void_expected_t * = nullptr> - constexpr explicit expected(expected &&rhs) // - noexcept(std::is_nothrow_constructible_v) + class U, + class G, + std::enable_if_t, expected>> * = nullptr, + std::enable_if_t> * = nullptr, + expected_detail::enable_from_other_void_expected_t * = nullptr + > + constexpr explicit expected(expected &&rhs) noexcept(std::is_nothrow_constructible_v) : ctor_base(expected_detail::default_constructor_tag {}) { if (rhs.has_value()) @@ -2261,9 +2266,10 @@ class expected // explicit const unexpected & template< - class G, // - std::enable_if_t> * = nullptr, // - std::enable_if_t> * = nullptr> + class G, + std::enable_if_t> * = nullptr, + std::enable_if_t> * = nullptr + > explicit constexpr expected(const unexpected &e) noexcept(std::is_nothrow_constructible_v) : impl_base(unexpect, e.error()) , ctor_base(expected_detail::default_constructor_tag {}) @@ -2272,9 +2278,10 @@ class expected // implicit const unexpected & template< - class G, // - std::enable_if_t> * = nullptr, // - std::enable_if_t> * = nullptr> + class G, + std::enable_if_t> * = nullptr, + std::enable_if_t> * = nullptr + > constexpr expected(unexpected const &e) noexcept(std::is_nothrow_constructible_v) : impl_base(unexpect, e.error()) , ctor_base(expected_detail::default_constructor_tag {}) @@ -2283,9 +2290,10 @@ class expected // explicit unexpected && template< - class G, // - std::enable_if_t> * = nullptr, // - std::enable_if_t> * = nullptr> + class G, + std::enable_if_t> * = nullptr, + std::enable_if_t> * = nullptr + > explicit constexpr expected(unexpected &&e) noexcept(std::is_nothrow_constructible_v) : impl_base(unexpect, std::move(e.error())) , ctor_base(expected_detail::default_constructor_tag {}) @@ -2294,9 +2302,10 @@ class expected // implicit unexpected && template< - class G, // - std::enable_if_t> * = nullptr, // - std::enable_if_t> * = nullptr> + class G, + std::enable_if_t> * = nullptr, + std::enable_if_t> * = nullptr + > constexpr expected(unexpected &&e) noexcept(std::is_nothrow_constructible_v) : impl_base(unexpect, std::move(e.error())) , ctor_base(expected_detail::default_constructor_tag {}) @@ -2313,8 +2322,7 @@ class expected // template // expected(unexpect_t, Args &&...) template> * = nullptr> - constexpr explicit expected(unexpect_t, Args &&...args) // - noexcept(std::is_nothrow_constructible_v) + constexpr explicit expected(unexpect_t, Args &&...args) noexcept(std::is_nothrow_constructible_v) : impl_base(unexpect, std::forward(args)...) , ctor_base(expected_detail::default_constructor_tag {}) { @@ -2323,8 +2331,9 @@ class expected // template // expected(unexpect_t, std::initializer_list, Args &&...) template &, Args...>> * = nullptr> - constexpr explicit expected(unexpect_t, std::initializer_list il, Args &&...args) // - noexcept(std::is_nothrow_constructible_v &, Args...>) + constexpr explicit expected( + unexpect_t, std::initializer_list il, Args &&...args + ) noexcept(std::is_nothrow_constructible_v &, Args...>) : impl_base(unexpect, il, std::forward(args)...) , ctor_base(expected_detail::default_constructor_tag {}) { @@ -2332,8 +2341,9 @@ class expected // helper ctor for transform_error() template - constexpr explicit expected(expected_detail::construct_with_invoke_result_t tag1, unexpect_t tag2, Fn &&func, Args &&...args) // - noexcept(noexcept(static_cast(std::invoke(std::forward(func), std::forward(args)...)))) + constexpr explicit expected(expected_detail::construct_with_invoke_result_t tag1, unexpect_t tag2, Fn &&func, Args &&...args) noexcept( + noexcept(static_cast(std::invoke(std::forward(func), std::forward(args)...))) + ) : impl_base(tag1, tag2, std::forward(func), std::forward(args)...) , ctor_base(expected_detail::default_constructor_tag {}) { @@ -2342,15 +2352,10 @@ class expected expected &operator=(const expected &rhs) = default; expected &operator=(expected &&rhs) = default; - template< - class G, // - class GF = const G &, // - std::enable_if_t< // - std::is_constructible_v && // - std::is_assignable_v // - > * = nullptr> - constexpr expected &operator=(const unexpected &rhs) // - noexcept(std::is_nothrow_constructible_v && std::is_nothrow_assignable_v) + template && std::is_assignable_v> * = nullptr> + constexpr expected &operator=( + const unexpected &rhs + ) noexcept(std::is_nothrow_constructible_v && std::is_nothrow_assignable_v) { if (has_value()) { @@ -2365,15 +2370,10 @@ class expected return *this; } - template< - class G, // - class GF = G, // - std::enable_if_t< // - std::is_constructible_v && // - std::is_assignable_v // - > * = nullptr> - constexpr expected &operator=(unexpected &&rhs) // - noexcept(std::is_nothrow_constructible_v && std::is_nothrow_assignable_v) + template && std::is_assignable_v> * = nullptr> + constexpr expected &operator=( + unexpected &&rhs + ) noexcept(std::is_nothrow_constructible_v && std::is_nothrow_assignable_v) { if (has_value()) { @@ -2401,10 +2401,9 @@ class expected } template - constexpr std::enable_if_t< // - std::is_swappable_v && std::is_move_constructible_v> - swap(expected &rhs) // - noexcept(std::is_nothrow_move_constructible_v && std::is_nothrow_swappable_v) + constexpr std::enable_if_t && std::is_move_constructible_v> swap( + expected &rhs + ) noexcept(std::is_nothrow_move_constructible_v && std::is_nothrow_swappable_v) { using std::swap; if (this->m_has_val && rhs.m_has_val) @@ -2457,26 +2456,13 @@ class expected ZEUS_EXPECTED_THROW(bad_expected_access(std::move(err()))); } - constexpr const E &error() const & noexcept // - { - return err(); - } - constexpr E &error() & noexcept // - { - return err(); - } - constexpr const E &&error() const && noexcept // - { - return std::move(err()); - } - constexpr E &&error() && noexcept // - { - return std::move(err()); - } + constexpr const E &error() const &noexcept { return err(); } + constexpr E &error() &noexcept { return err(); } + constexpr const E &&error() const && noexcept { return std::move(err()); } + constexpr E &&error() &&noexcept { return std::move(err()); } template - constexpr E error_or(G &&v) const & // - noexcept(std::is_nothrow_copy_constructible_v && expected_detail::is_nothrow_convertible_v) + constexpr E error_or(G &&v) const & noexcept(std::is_nothrow_copy_constructible_v && expected_detail::is_nothrow_convertible_v) { static_assert(std::is_copy_constructible_v, "E must be copy-constructible"); static_assert(std::is_convertible_v, "is_convertible_v must be true"); @@ -2490,8 +2476,7 @@ class expected } } template - constexpr E error_or(G &&v) && // - noexcept(std::is_nothrow_move_constructible_v && expected_detail::is_nothrow_convertible_v) + constexpr E error_or(G &&v) && noexcept(std::is_nothrow_move_constructible_v && expected_detail::is_nothrow_convertible_v) { static_assert(std::is_move_constructible_v, "E must be move-constructible"); static_assert(std::is_convertible_v, "is_convertible_v must be true"); @@ -2758,8 +2743,9 @@ class expected } template - [[nodiscard]] friend constexpr std::enable_if_t, bool> operator==(const expected &x, const expected &y) // - noexcept(noexcept(x.error() == y.error())) + [[nodiscard]] friend constexpr std::enable_if_t, bool> operator==( + const expected &x, const expected &y + ) noexcept(noexcept(x.error() == y.error())) { if (x.has_value() != y.has_value()) { @@ -2772,16 +2758,16 @@ class expected } #if ZEUS_EXPECTED_CPLUSPLUS < 202'002L template - [[nodiscard]] friend constexpr std::enable_if_t, bool> operator!=(const expected &x, const expected &y) // - noexcept(noexcept(x == y)) + [[nodiscard]] friend constexpr std::enable_if_t, bool> operator!=( + const expected &x, const expected &y + ) noexcept(noexcept(x == y)) { return !(x == y); } #endif template - [[nodiscard]] friend constexpr bool operator==(const expected &x, const unexpected &e) // - noexcept(noexcept(x.error() == e.error())) + [[nodiscard]] friend constexpr bool operator==(const expected &x, const unexpected &e) noexcept(noexcept(x.error() == e.error())) { if (x.has_value()) { @@ -2794,20 +2780,17 @@ class expected } #if ZEUS_EXPECTED_CPLUSPLUS < 202'002L template - [[nodiscard]] friend constexpr bool operator!=(const expected &x, const unexpected &e) // - noexcept(noexcept(x == e)) + [[nodiscard]] friend constexpr bool operator!=(const expected &x, const unexpected &e) noexcept(noexcept(x == e)) { return !(x == e); } template - [[nodiscard]] friend constexpr bool operator==(const unexpected &e, const expected &x) // - noexcept(noexcept(x == e)) + [[nodiscard]] friend constexpr bool operator==(const unexpected &e, const expected &x) noexcept(noexcept(x == e)) { return x == e; } template - [[nodiscard]] friend constexpr bool operator!=(const unexpected &e, const expected &x) // - noexcept(noexcept(x == e)) + [[nodiscard]] friend constexpr bool operator!=(const unexpected &e, const expected &x) noexcept(noexcept(x == e)) { return x != e; } @@ -2815,9 +2798,7 @@ class expected }; // standalone swap for void value type -template< - class E, // - std::enable_if_t && std::is_swappable_v> * = nullptr> +template && std::is_swappable_v> * = nullptr> constexpr void swap(expected &lhs, expected &rhs) noexcept(noexcept(lhs.swap(rhs))) { lhs.swap(rhs); diff --git a/tests/test_expected/lwg_4025_tests.cpp b/tests/test_expected/lwg_4025_tests.cpp index 2942aec..35b3063 100644 --- a/tests/test_expected/lwg_4025_tests.cpp +++ b/tests/test_expected/lwg_4025_tests.cpp @@ -17,42 +17,54 @@ namespace struct CopyableNotMovable { - CopyableNotMovable() = default; - CopyableNotMovable(const CopyableNotMovable &) = default; + CopyableNotMovable() = default; + CopyableNotMovable(const CopyableNotMovable &) = default; CopyableNotMovable &operator=(const CopyableNotMovable &) = default; - CopyableNotMovable(CopyableNotMovable &&) = delete; - CopyableNotMovable &operator=(CopyableNotMovable &&) = delete; + CopyableNotMovable(CopyableNotMovable &&) = delete; + CopyableNotMovable &operator=(CopyableNotMovable &&) = delete; }; struct NotCopyableNotMovable { - NotCopyableNotMovable() = default; - NotCopyableNotMovable(const NotCopyableNotMovable &) = delete; + NotCopyableNotMovable() = default; + NotCopyableNotMovable(const NotCopyableNotMovable &) = delete; NotCopyableNotMovable &operator=(const NotCopyableNotMovable &) = delete; - NotCopyableNotMovable(NotCopyableNotMovable &&) = delete; - NotCopyableNotMovable &operator=(NotCopyableNotMovable &&) = delete; + NotCopyableNotMovable(NotCopyableNotMovable &&) = delete; + NotCopyableNotMovable &operator=(NotCopyableNotMovable &&) = delete; }; struct MoveOnly { int value; - MoveOnly() : value(0) {} - MoveOnly(int v) : value(v) {} - MoveOnly(const MoveOnly &) = delete; + MoveOnly() + : value(0) + { + } + MoveOnly(int v) + : value(v) + { + } + MoveOnly(const MoveOnly &) = delete; MoveOnly &operator=(const MoveOnly &) = delete; - MoveOnly(MoveOnly &&) = default; - MoveOnly &operator=(MoveOnly &&) = default; + MoveOnly(MoveOnly &&) = default; + MoveOnly &operator=(MoveOnly &&) = default; }; struct StatefulCopyableNotMovable { int value; - StatefulCopyableNotMovable() : value(0) {} - StatefulCopyableNotMovable(int v) : value(v) {} - StatefulCopyableNotMovable(const StatefulCopyableNotMovable &) = default; + StatefulCopyableNotMovable() + : value(0) + { + } + StatefulCopyableNotMovable(int v) + : value(v) + { + } + StatefulCopyableNotMovable(const StatefulCopyableNotMovable &) = default; StatefulCopyableNotMovable &operator=(const StatefulCopyableNotMovable &) = default; - StatefulCopyableNotMovable(StatefulCopyableNotMovable &&) = delete; - StatefulCopyableNotMovable &operator=(StatefulCopyableNotMovable &&) = delete; + StatefulCopyableNotMovable(StatefulCopyableNotMovable &&) = delete; + StatefulCopyableNotMovable &operator=(StatefulCopyableNotMovable &&) = delete; }; } // namespace @@ -68,8 +80,7 @@ TEST_CASE("expected is trivially move-assignable when E is trivial", "[ STATIC_REQUIRE(std::is_nothrow_move_assignable_v>); } -TEST_CASE("expected is move-assignable via copy fallback when E is copyable but not movable", - "[LWG-4025]") +TEST_CASE("expected is move-assignable via copy fallback when E is copyable but not movable", "[LWG-4025]") { STATIC_REQUIRE(std::is_move_assignable_v>); STATIC_REQUIRE(std::is_trivially_move_assignable_v>); @@ -172,8 +183,7 @@ TEST_CASE("expected is trivially move-assignable when E is trivial", "[LWG STATIC_REQUIRE(std::is_nothrow_move_assignable_v>); } -TEST_CASE("expected is move-assignable via copy fallback when E is copyable but not movable", - "[LWG-4025]") +TEST_CASE("expected is move-assignable via copy fallback when E is copyable but not movable", "[LWG-4025]") { STATIC_REQUIRE(std::is_move_assignable_v>); STATIC_REQUIRE(std::is_trivially_move_assignable_v>); diff --git a/tests/test_expected/lwg_4031_tests.cpp b/tests/test_expected/lwg_4031_tests.cpp index 1d154da..64f498f 100644 --- a/tests/test_expected/lwg_4031_tests.cpp +++ b/tests/test_expected/lwg_4031_tests.cpp @@ -6,11 +6,13 @@ using namespace zeus; namespace { + // Exposing all members for testing struct test_bad_expected_access : public bad_expected_access { using bad_expected_access::bad_expected_access; }; + } TEST_CASE("bad_expected_access special members are noexcept", "[LWG-4031]") diff --git a/tests/test_no_exceptions/test_no_exceptions.cpp b/tests/test_no_exceptions/test_no_exceptions.cpp index d7dd593..09d8341 100644 --- a/tests/test_no_exceptions/test_no_exceptions.cpp +++ b/tests/test_no_exceptions/test_no_exceptions.cpp @@ -40,7 +40,7 @@ int main() if (!ev.has_value()) return 8; - zeus::expected ev2{zeus::unexpect, 10}; + zeus::expected ev2 {zeus::unexpect, 10}; if (ev2.has_value()) return 9; if (ev2.error() != 10)