Skip to content

Commit

Permalink
Don't need to dispatch direct-list-initialization and list-initializa…
Browse files Browse the repository at this point in the history
…tion for `impl::construct_from_invoke_tag` constructors
  • Loading branch information
NUCLEAR-BOMB committed Nov 30, 2024
1 parent f06c111 commit 5e69b8b
Showing 1 changed file with 7 additions and 25 deletions.
32 changes: 7 additions & 25 deletions include/opt/option.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1925,13 +1925,9 @@ namespace impl {
: value(static_cast<Args&&>(args)...), has_value_flag(true) {}

template<class F, class Arg>
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&&>(f), static_cast<Arg&&>(arg))}, has_value_flag(true) {}

template<class F, class Arg>
constexpr option_destruct_base(construct_from_invoke_tag, std::false_type, F&& f, Arg&& arg)
: value(impl::invoke(static_cast<F&&>(f), static_cast<Arg&&>(arg))), has_value_flag(true) {}

constexpr void reset() noexcept {
has_value_flag = false;
}
Expand Down Expand Up @@ -1964,13 +1960,9 @@ namespace impl {
: value(static_cast<Args&&>(args)...), has_value_flag(true) {}

template<class F, class Arg>
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&&>(f), static_cast<Arg&&>(arg))}, has_value_flag(true) {}

template<class F, class Arg>
constexpr option_destruct_base(construct_from_invoke_tag, std::false_type, F&& f, Arg&& arg)
: value(impl::invoke(static_cast<F&&>(f), static_cast<Arg&&>(arg))), has_value_flag(true) {}

OPTION_CONSTEXPR_CXX20 ~option_destruct_base() {
if (has_value_flag) {
value.~T();
Expand Down Expand Up @@ -2024,15 +2016,10 @@ namespace impl {
}

template<class F, class Arg>
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&&>(f), static_cast<Arg&&>(arg))} {
OPTION_VERIFY(has_value(), "After the construction, the value is in an empty state. Possibly because of the constructor arguments");
}
template<class F, class Arg>
constexpr option_destruct_base(construct_from_invoke_tag, std::false_type, F&& f, Arg&& arg)
: value(impl::invoke(static_cast<F&&>(f), static_cast<Arg&&>(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);
Expand Down Expand Up @@ -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<class F, class Arg>
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&&>(f), static_cast<Arg&&>(arg))} {
OPTION_VERIFY(has_value(), "After the construction, the value is in an empty state. Possibly because of the constructor arguments");
}
template<class F, class Arg>
constexpr option_destruct_base(construct_from_invoke_tag, std::false_type, F&& f, Arg&& arg)
: value(impl::invoke(static_cast<F&&>(f), static_cast<Arg&&>(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();
Expand Down Expand Up @@ -2307,8 +2289,8 @@ namespace impl {
constexpr option_base(const std::in_place_t, std::bool_constant<IsAggregate>, Arg&& arg) noexcept
: value{ref_to_ptr(static_cast<Arg&&>(arg))} {}

template<class F, class Arg, bool IsAggregate>
constexpr option_base(construct_from_invoke_tag, std::bool_constant<IsAggregate>, F&& f, Arg&& arg)
template<class F, class Arg>
constexpr option_base(construct_from_invoke_tag, F&& f, Arg&& arg)
: value{ref_to_ptr(impl::invoke(static_cast<F&&>(f), static_cast<Arg&&>(arg)))} {
using fn_result = decltype(impl::invoke(static_cast<F&&>(f), static_cast<Arg&&>(arg)));
static_assert(std::is_reference_v<fn_result> || is_reference_wrapper_v<fn_result>,
Expand Down Expand Up @@ -2868,7 +2850,7 @@ class OPTION_DECLSPEC_EMPTY_BASES OPTION_CONSUMABLE(unconsumed) option
template<class F, class Arg>
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<std::is_aggregate_v<T>>{}, static_cast<F&&>(f), static_cast<Arg&&>(arg)) {}
: base(impl::construct_from_invoke_tag{}, static_cast<F&&>(f), static_cast<Arg&&>(arg)) {}

template<class U,
typename checks::template from_option_like_ctor<T, U, const U&>::template constructor_is_explicit<false>::type = 0>
Expand Down

0 comments on commit 5e69b8b

Please sign in to comment.