From 196e6f549e3cad4c4b84157f0e6f1ab5125de390 Mon Sep 17 00:00:00 2001 From: X1aomu Date: Tue, 14 Jul 2026 11:23:37 +0800 Subject: [PATCH 1/4] style: update clang-format configuration --- .clang-format | 48 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 7 deletions(-) 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 From 1f8831195385d8a36282ff67ceb37dc50425817d Mon Sep 17 00:00:00 2001 From: X1aomu Date: Tue, 14 Jul 2026 11:23:37 +0800 Subject: [PATCH 2/4] style: reformat expected header --- include/zeus/expected.hpp | 130 +++++++++++++++++++++++++------------- 1 file changed, 87 insertions(+), 43 deletions(-) diff --git a/include/zeus/expected.hpp b/include/zeus/expected.hpp index 60ac325..4fa721f 100644 --- a/include/zeus/expected.hpp +++ b/include/zeus/expected.hpp @@ -293,7 +293,7 @@ using enable_forward_t = std::enable_if_t< (!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< @@ -314,7 +314,9 @@ using enable_from_other_expected_t = std::enable_if_t< 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< @@ -793,7 +795,8 @@ 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> + 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; @@ -846,7 +849,8 @@ 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 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; @@ -895,9 +899,11 @@ 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 @@ -915,7 +921,8 @@ template< class T, class E, bool Enabled = is_expected_copy_assignable_v, // - bool Trivially = is_expected_trivially_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; @@ -953,7 +960,9 @@ struct copy_assign_base : move_ctor_base 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_constructible_v && + std::is_nothrow_copy_assignable_v && + std::is_nothrow_copy_constructible_v && std::is_nothrow_copy_assignable_v ) { @@ -1018,9 +1027,11 @@ 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 @@ -1038,7 +1049,8 @@ template< class T, class E, bool Enabled = is_expected_move_assignable_v, // - bool Trivially = is_expected_trivially_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; @@ -1077,7 +1089,9 @@ struct move_assign_base : copy_assign_base 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_constructible_v && + std::is_nothrow_move_assignable_v && + std::is_nothrow_move_constructible_v && std::is_nothrow_move_assignable_v ) { @@ -1174,6 +1188,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 @@ -1227,7 +1242,8 @@ class expected 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> + 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 {}) @@ -1248,7 +1264,8 @@ class expected 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> + 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 {}) @@ -1269,7 +1286,8 @@ class expected 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> + 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 {}) @@ -1290,7 +1308,8 @@ class expected 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> + 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 {}) @@ -1312,7 +1331,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 +1342,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)) { @@ -1334,7 +1355,8 @@ class expected template< class G, // std::enable_if_t> * = nullptr, // - 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 {}) @@ -1345,7 +1367,8 @@ class expected template< class G, // std::enable_if_t> * = nullptr, // - 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 {}) @@ -1356,7 +1379,8 @@ class expected template< class G, // std::enable_if_t> * = nullptr, // - 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 {}) @@ -1367,7 +1391,8 @@ class expected template< class G, // std::enable_if_t> * = nullptr, // - 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 {}) @@ -1547,7 +1572,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,13 +1597,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)> + 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_nothrow_move_constructible_v && + std::is_nothrow_swappable_v && // + std::is_nothrow_move_constructible_v && + std::is_nothrow_swappable_v ) { using std::swap; @@ -2133,10 +2164,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); @@ -2182,7 +2217,8 @@ class expected class G, // std::enable_if_t, expected>> * = nullptr, // std::enable_if_t> * = nullptr, // - expected_detail::enable_from_other_void_expected_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 {}) @@ -2202,7 +2238,8 @@ class expected class G, // std::enable_if_t, expected>> * = nullptr, // std::enable_if_t> * = nullptr, // - expected_detail::enable_from_other_void_expected_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 {}) @@ -2222,7 +2259,8 @@ class expected class G, // std::enable_if_t, expected>> * = nullptr, // std::enable_if_t> * = nullptr, // - expected_detail::enable_from_other_void_expected_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 {}) @@ -2242,7 +2280,8 @@ class expected class G, // std::enable_if_t, expected>> * = nullptr, // std::enable_if_t> * = nullptr, // - expected_detail::enable_from_other_void_expected_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 {}) @@ -2263,7 +2302,8 @@ class expected template< class G, // std::enable_if_t> * = nullptr, // - 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 {}) @@ -2274,7 +2314,8 @@ class expected template< class G, // std::enable_if_t> * = nullptr, // - 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 {}) @@ -2285,7 +2326,8 @@ class expected template< class G, // std::enable_if_t> * = nullptr, // - 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 {}) @@ -2296,7 +2338,8 @@ class expected template< class G, // std::enable_if_t> * = nullptr, // - 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 {}) @@ -2817,7 +2860,8 @@ class expected // standalone swap for void value type template< class E, // - std::enable_if_t && std::is_swappable_v> * = nullptr> + std::enable_if_t && std::is_swappable_v> * = nullptr +> constexpr void swap(expected &lhs, expected &rhs) noexcept(noexcept(lhs.swap(rhs))) { lhs.swap(rhs); From 6ab7d28c684b2b448cb827956640ce3e8aef06ae Mon Sep 17 00:00:00 2001 From: X1aomu Date: Tue, 14 Jul 2026 11:23:37 +0800 Subject: [PATCH 3/4] style: reformat tests --- tests/test_expected/lwg_4025_tests.cpp | 54 +++++++++++-------- tests/test_expected/lwg_4031_tests.cpp | 2 + .../test_no_exceptions/test_no_exceptions.cpp | 2 +- 3 files changed, 35 insertions(+), 23 deletions(-) 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) From a0363a853277985b73ec1a864399a7005db36505 Mon Sep 17 00:00:00 2001 From: X1aomu Date: Tue, 14 Jul 2026 11:22:47 +0800 Subject: [PATCH 4/4] style: remove manual trailing comments --- include/zeus/expected.hpp | 619 +++++++++++++++++--------------------- 1 file changed, 278 insertions(+), 341 deletions(-) diff --git a/include/zeus/expected.hpp b/include/zeus/expected.hpp index 4fa721f..bc36dcc 100644 --- a/include/zeus/expected.hpp +++ b/include/zeus/expected.hpp @@ -286,48 +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 @@ -461,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) { @@ -470,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) { @@ -541,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) { @@ -550,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) { @@ -625,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) { @@ -688,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) { @@ -724,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; @@ -776,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; @@ -793,8 +796,8 @@ 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, // + 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 @@ -825,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) @@ -848,7 +852,7 @@ 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 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 @@ -880,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) @@ -899,28 +904,27 @@ struct move_ctor_base : copy_ctor_base }; template -inline constexpr bool is_expected_copy_assignable_v = // +inline constexpr bool is_expected_copy_assignable_v = is_copy_assignable_or_void_v && - is_copy_constructible_or_void_v && // + is_copy_constructible_or_void_v && std::is_copy_assignable_v && - std::is_copy_constructible_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 Enabled = is_expected_copy_assignable_v, bool Trivially = is_expected_trivially_copy_assignable_v > struct copy_assign_base : move_ctor_base @@ -958,13 +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) { @@ -999,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) { @@ -1027,28 +1031,27 @@ struct copy_assign_base : move_ctor_base }; template -inline constexpr bool is_expected_move_assignable_v = // +inline constexpr bool is_expected_move_assignable_v = is_move_assignable_or_void_v && - is_move_constructible_or_void_v && // + is_move_constructible_or_void_v && std::is_move_assignable_v && - std::is_move_constructible_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 Enabled = is_expected_move_assignable_v, bool Trivially = is_expected_trivially_move_assignable_v > struct move_assign_base : copy_assign_base @@ -1087,13 +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) { @@ -1127,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) { @@ -1238,14 +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, // + 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) + 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()) @@ -1260,14 +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, // + 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) + 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()) @@ -1282,14 +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, // + 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) + 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()) @@ -1304,14 +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, // + 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) + 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()) @@ -1353,8 +1358,8 @@ class expected // explicit const unexpected & template< - class G, // - 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) @@ -1365,8 +1370,8 @@ class expected // implicit const unexpected & template< - class G, // - 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) @@ -1377,8 +1382,8 @@ class expected // explicit unexpected && template< - class G, // - 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) @@ -1389,8 +1394,8 @@ class expected // implicit unexpected && template< - class G, // - 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) @@ -1403,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 {}) { @@ -1414,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 {}) { @@ -1423,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 {}) { @@ -1434,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 {}) { @@ -1445,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 {}) { @@ -1454,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 {}) { @@ -1470,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()) { @@ -1496,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()) { @@ -1522,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()) { @@ -1598,18 +1603,17 @@ class expected template constexpr std::enable_if_t< std::is_swappable_v && - std::is_swappable_v && // + std::is_swappable_v && std::is_move_constructible_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 - ) + 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) @@ -1678,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; } @@ -1729,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"); @@ -1762,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"); @@ -1778,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"); @@ -1793,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"); @@ -2061,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()) { @@ -2079,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()) { @@ -2101,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()) { @@ -2139,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; } @@ -2164,11 +2134,11 @@ template< class T, class E, std::enable_if_t< - !std::is_void_v && // + !std::is_void_v && std::is_move_constructible_v && - std::is_swappable_v && // + std::is_swappable_v && std::is_move_constructible_v && - std::is_swappable_v && // + std::is_swappable_v && (std::is_nothrow_move_constructible_v || std::is_nothrow_move_constructible_v) > * = nullptr > @@ -2213,14 +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, // + 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) + constexpr expected(const expected &rhs) noexcept(std::is_nothrow_constructible_v) : ctor_base(expected_detail::default_constructor_tag {}) { if (rhs.has_value()) @@ -2234,14 +2203,13 @@ class expected } template< - class U, // - class G, // - std::enable_if_t, expected>> * = nullptr, // - std::enable_if_t> * = nullptr, // + 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) + constexpr explicit expected(const expected &rhs) noexcept(std::is_nothrow_constructible_v) : ctor_base(expected_detail::default_constructor_tag {}) { if (rhs.has_value()) @@ -2255,14 +2223,13 @@ class expected } template< - class U, // - class G, // - std::enable_if_t, expected>> * = nullptr, // - std::enable_if_t> * = nullptr, // + 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) + constexpr expected(expected &&rhs) noexcept(std::is_nothrow_constructible_v) : ctor_base(expected_detail::default_constructor_tag {}) { if (rhs.has_value()) @@ -2276,14 +2243,13 @@ class expected } template< - class U, // - class G, // - std::enable_if_t, expected>> * = nullptr, // - std::enable_if_t> * = nullptr, // + 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) + constexpr explicit expected(expected &&rhs) noexcept(std::is_nothrow_constructible_v) : ctor_base(expected_detail::default_constructor_tag {}) { if (rhs.has_value()) @@ -2300,8 +2266,8 @@ class expected // explicit const unexpected & template< - class G, // - 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) @@ -2312,8 +2278,8 @@ class expected // implicit const unexpected & template< - class G, // - 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) @@ -2324,8 +2290,8 @@ class expected // explicit unexpected && template< - class G, // - 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) @@ -2336,8 +2302,8 @@ class expected // implicit unexpected && template< - class G, // - 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) @@ -2356,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 {}) { @@ -2366,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 {}) { @@ -2375,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 {}) { @@ -2385,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()) { @@ -2408,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()) { @@ -2444,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) @@ -2500,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"); @@ -2533,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"); @@ -2801,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()) { @@ -2815,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()) { @@ -2837,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; } @@ -2858,10 +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);