Skip to content
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.

Commit

Permalink
remove make_expected<E>() overload resulting in expected<void,E>.
Browse files Browse the repository at this point in the history
  • Loading branch information
viboes committed Mar 13, 2016
1 parent a02e248 commit 1b55372
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
2 changes: 1 addition & 1 deletion example/num_get_3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ matchedString(std::string str, ios_range<CharT, InputIterator>& r) {
return boost::make_unexpected(std::ios_base::goodbit);
}
++r.begin;
return boost::make_expected<std::ios_base::iostate>();
return boost::expected<void,std::ios_base::iostate>();
}

/**
Expand Down
20 changes: 13 additions & 7 deletions include/boost/expected/expected.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2465,22 +2465,28 @@ void swap(expected<T,E>& x, expected<T,E>& y) BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT_E

// Factories

template<typename T>
BOOST_CONSTEXPR expected<decay_t<T>, std::exception_ptr> make_expected(T&& v )
template <typename T>
BOOST_CONSTEXPR expected<decay_t<T>, std::exception_ptr> make_expected(T&& v)
{
return expected<decay_t<T>, std::exception_ptr>(constexpr_forward<T>(v));
}

//template <typename E, typename T>
//BOOST_CONSTEXPR expected<decay_t<T>, E> make_expected(T&& v)
//{
// return expected<decay_t<T>, E>(constexpr_forward<T>(v));
//}

BOOST_FORCEINLINE expected<void, std::exception_ptr> make_expected()
{
return expected<void, std::exception_ptr>(in_place2);
}

template<typename E>
BOOST_FORCEINLINE expected<void, E> make_expected()
{
return expected<void, E>(in_place2);
}
//template<typename E>
//BOOST_FORCEINLINE expected<void, E> make_expected()
//{
// return expected<void, E>(in_place2);
//}

template <typename T>
BOOST_FORCEINLINE expected<T, std::exception_ptr> make_expected_from_current_exception() BOOST_NOEXCEPT
Expand Down
22 changes: 22 additions & 0 deletions test/test_expected.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,28 @@ BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE(error_expected_constructors)

BOOST_AUTO_TEST_CASE(make_expected_E_from_value)
{
//auto e = make_expected<std::string>( 5 );
//BOOST_CHECK_EQUAL(e.valid(), false);
}
BOOST_AUTO_TEST_CASE(make_expected_from_U_value)
{
expected<short> e = make_expected<short>( 5 );
static_assert(std::is_same<decltype(e), expected<short>>{}, "");
BOOST_CHECK_EQUAL(e.valid(), true);
}
BOOST_AUTO_TEST_CASE(make_expected_from_U_value2)
{
expected<std::string> e = make_expected<std::string>( "aa" );
static_assert(std::is_same<decltype(e), expected<std::string>>{}, "");
BOOST_CHECK_EQUAL(e.valid(), true);
}

BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE(error_expected_constructors)

BOOST_AUTO_TEST_CASE(expected_from_value)
{
// From value constructor.
Expand Down

0 comments on commit 1b55372

Please sign in to comment.