Skip to content

Commit 406fffd

Browse files
committed
elle.Option: Build void options via nullptr.
1 parent 6783b30 commit 406fffd

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/elle/Option.hxx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,19 @@ namespace elle
131131

132132
template <typename T, typename A>
133133
std::enable_if_t<
134-
!std::is_same<std::remove_cv_reference_t<T>, Head>::value,
134+
std::is_same<std::remove_cv_reference_t<T>, std::nullptr_t>::value &&
135+
std::is_same<Head, void>::value,
136+
void>
137+
_emplace(A&& value)
138+
{
139+
this->_index = Index;
140+
}
141+
142+
template <typename T, typename A>
143+
std::enable_if_t<
144+
!std::is_same<std::remove_cv_reference_t<T>, Head>::value &&
145+
(!std::is_same<std::remove_cv_reference_t<T>, std::nullptr_t>::value ||
146+
!std::is_same<Head, void>::value),
135147
void>
136148
_emplace(A&& value)
137149
{

tests/elle/option.cc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,17 @@ static
390390
void
391391
void_member()
392392
{
393-
elle::Option<void, int> x(42);
394-
BOOST_TEST(x.is<int>());
395-
BOOST_TEST(!x.is<void>());
396-
BOOST_TEST(x.get<int>() == 42);
393+
{
394+
elle::Option<void, int> x(42);
395+
BOOST_TEST(x.is<int>());
396+
BOOST_TEST(!x.is<void>());
397+
BOOST_TEST(x.get<int>() == 42);
398+
}
399+
{
400+
elle::Option<void, int> x(nullptr);
401+
BOOST_TEST(!x.is<int>());
402+
BOOST_TEST(x.is<void>());
403+
}
397404
}
398405

399406
ELLE_TEST_SUITE()

0 commit comments

Comments
 (0)