Skip to content

Commit 72a60fc

Browse files
committed
Make variant's constructor implicit when the argument is the same type as exactly one of the alternatives
1 parent 35438cb commit 72a60fc

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

source/tv/variant.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ struct [[clang::trivial_abi]] variant {
9696
{
9797
}
9898

99-
constexpr explicit variant(matches_exactly_one_type<Ts...> auto && value):
99+
constexpr variant(matches_exactly_one_type<Ts...> auto && value):
100100
variant(
101101
bounded::lazy_init,
102102
bounded::value_to_function(OPERATORS_FORWARD(value))
@@ -439,4 +439,8 @@ static_assert(!std::invocable<decltype(tv::visit), decltype(variant), decltype(t
439439

440440
static_assert(std::same_as<decltype(bounded::declval<tv::variant<int> &>().emplace(0_bi, [] { return 0; })), int &>);
441441

442+
static_assert(bounded::convertible_to<int, tv::variant<int, unsigned>>);
443+
static_assert(!bounded::convertible_to<short, tv::variant<int, unsigned>>);
444+
static_assert(!bounded::convertible_to<int, tv::variant<int, int>>);
445+
442446
} // namespace

0 commit comments

Comments
 (0)