Skip to content

Commit

Permalink
Make constructor from arguments (one without std::in_place) non-`ex…
Browse files Browse the repository at this point in the history
…plicit`
  • Loading branch information
NUCLEAR-BOMB committed Nov 21, 2024
1 parent 334fe12 commit a08c901
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/opt/option.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2851,7 +2851,7 @@ class OPTION_DECLSPEC_EMPTY_BASES OPTION_CONSUMABLE(unconsumed) option
template<class First, class Second, class... Args,
class = typename checks::template from_args_ctor<T, First, Second, Args...>::type>
OPTION_RETURN_TYPESTATE(consumed)
constexpr explicit option(First&& first, Second&& second, Args&&... args)
constexpr option(First&& first, Second&& second, Args&&... args)
: base(std::in_place, std::bool_constant<std::is_aggregate_v<T>>{}, static_cast<First&&>(first), static_cast<Second&&>(second), static_cast<Args&&>(args)...) {}

template<class InPlaceT, class... Args,
Expand Down
22 changes: 22 additions & 0 deletions test/special.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1740,6 +1740,28 @@ TEST_CASE("value_or") {
#endif
}

TEST_CASE("non-explicit from arguments constructor") {
struct type {
int x;
float y;

bool operator==(const type& other) const { return x == other.x && y == other.y; }
};
const auto fn1 = []() -> type {
return {1, 2.f};
};
CHECK_EQ(fn1(), type{1, 2.f});
const auto fn2 = []() -> opt::option<type> {
return {3, 4.f};
};
CHECK_EQ(fn2(), type{3, 4.f});

const auto fn3 = [](type) {};
fn3({5, 6.f});
const auto fn4 = [](opt::option<type>) {};
fn4({7, 8.f});
}

TEST_SUITE_END();

struct struct1 {
Expand Down

0 comments on commit a08c901

Please sign in to comment.