From 5e69b8ba5bcea6f53ced6212dc8f9fe03a77fd3b Mon Sep 17 00:00:00 2001 From: NUCLEAR-BOMB <61628949+NUCLEAR-BOMB@users.noreply.github.com> Date: Sat, 30 Nov 2024 13:25:44 +0500 Subject: [PATCH] Don't need to dispatch direct-list-initialization and list-initialization for `impl::construct_from_invoke_tag` constructors --- include/opt/option.hpp | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/include/opt/option.hpp b/include/opt/option.hpp index c0df591..3154630 100644 --- a/include/opt/option.hpp +++ b/include/opt/option.hpp @@ -1925,13 +1925,9 @@ namespace impl { : value(static_cast(args)...), has_value_flag(true) {} template - constexpr option_destruct_base(construct_from_invoke_tag, std::true_type, F&& f, Arg&& arg) + constexpr option_destruct_base(construct_from_invoke_tag, F&& f, Arg&& arg) : value{impl::invoke(static_cast(f), static_cast(arg))}, has_value_flag(true) {} - template - constexpr option_destruct_base(construct_from_invoke_tag, std::false_type, F&& f, Arg&& arg) - : value(impl::invoke(static_cast(f), static_cast(arg))), has_value_flag(true) {} - constexpr void reset() noexcept { has_value_flag = false; } @@ -1964,13 +1960,9 @@ namespace impl { : value(static_cast(args)...), has_value_flag(true) {} template - constexpr option_destruct_base(construct_from_invoke_tag, std::true_type, F&& f, Arg&& arg) + constexpr option_destruct_base(construct_from_invoke_tag, F&& f, Arg&& arg) : value{impl::invoke(static_cast(f), static_cast(arg))}, has_value_flag(true) {} - template - constexpr option_destruct_base(construct_from_invoke_tag, std::false_type, F&& f, Arg&& arg) - : value(impl::invoke(static_cast(f), static_cast(arg))), has_value_flag(true) {} - OPTION_CONSTEXPR_CXX20 ~option_destruct_base() { if (has_value_flag) { value.~T(); @@ -2024,15 +2016,10 @@ namespace impl { } template - constexpr option_destruct_base(construct_from_invoke_tag, std::true_type, F&& f, Arg&& arg) + constexpr option_destruct_base(construct_from_invoke_tag, F&& f, Arg&& arg) : value{impl::invoke(static_cast(f), static_cast(arg))} { OPTION_VERIFY(has_value(), "After the construction, the value is in an empty state. Possibly because of the constructor arguments"); } - template - constexpr option_destruct_base(construct_from_invoke_tag, std::false_type, F&& f, Arg&& arg) - : value(impl::invoke(static_cast(f), static_cast(arg))) { - OPTION_VERIFY(has_value(), "After the construction, the value is in an empty state. Possibly because of the constructor arguments"); - } constexpr void reset() noexcept { traits::set_level(OPTION_ADDRESSOF(value), 0); @@ -2074,15 +2061,10 @@ namespace impl { OPTION_VERIFY(has_value(), "After the construction, the value is in an empty state. Possibly because of the constructor arguments"); } template - constexpr option_destruct_base(construct_from_invoke_tag, std::true_type, F&& f, Arg&& arg) + constexpr option_destruct_base(construct_from_invoke_tag, F&& f, Arg&& arg) : value{impl::invoke(static_cast(f), static_cast(arg))} { OPTION_VERIFY(has_value(), "After the construction, the value is in an empty state. Possibly because of the constructor arguments"); } - template - constexpr option_destruct_base(construct_from_invoke_tag, std::false_type, F&& f, Arg&& arg) - : value(impl::invoke(static_cast(f), static_cast(arg))) { - OPTION_VERIFY(has_value(), "After the construction, the value is in an empty state. Possibly because of the constructor arguments"); - } OPTION_CONSTEXPR_CXX20 ~option_destruct_base() { if (has_value()) { value.~T(); @@ -2307,8 +2289,8 @@ namespace impl { constexpr option_base(const std::in_place_t, std::bool_constant, Arg&& arg) noexcept : value{ref_to_ptr(static_cast(arg))} {} - template - constexpr option_base(construct_from_invoke_tag, std::bool_constant, F&& f, Arg&& arg) + template + constexpr option_base(construct_from_invoke_tag, F&& f, Arg&& arg) : value{ref_to_ptr(impl::invoke(static_cast(f), static_cast(arg)))} { using fn_result = decltype(impl::invoke(static_cast(f), static_cast(arg))); static_assert(std::is_reference_v || is_reference_wrapper_v, @@ -2868,7 +2850,7 @@ class OPTION_DECLSPEC_EMPTY_BASES OPTION_CONSUMABLE(unconsumed) option template OPTION_RETURN_TYPESTATE(consumed) constexpr explicit option(const impl::construct_from_invoke_tag, F&& f, Arg&& arg) - : base(impl::construct_from_invoke_tag{}, std::bool_constant>{}, static_cast(f), static_cast(arg)) {} + : base(impl::construct_from_invoke_tag{}, static_cast(f), static_cast(arg)) {} template::template constructor_is_explicit::type = 0>