diff --git a/include/nonstd/expected.hpp b/include/nonstd/expected.hpp index 773a69a..f272145 100644 --- a/include/nonstd/expected.hpp +++ b/include/nonstd/expected.hpp @@ -248,6 +248,19 @@ namespace nonstd { { return unexpected< typename std::decay::type >( std::forward(value) ); } + + template + < + typename E, typename... Args, + typename = std::enable_if< + std::is_constructible::value + > + > + constexpr auto + make_unexpected( std::in_place_t inplace, Args &&... args ) -> unexpected_type< typename std::decay::type > + { + return unexpected_type< typename std::decay::type >( inplace, std::forward(args)...); + } } // namespace nonstd #else // nsel_USES_STD_EXPECTED @@ -1575,9 +1588,11 @@ template > > nsel_constexpr14 auto -make_unexpected( in_place_t inplace, Args... args ) -> unexpected_type< typename std::decay > +make_unexpected( nonstd_lite_in_place_t(E), Args &&... args ) -> unexpected_type< typename std::decay::type > { - return unexpected_type< typename std::decay::type >( inplace, std::forward(args)...); + return std::forward< unexpected_type< typename std::decay::type > >( + unexpected_type< typename std::decay::type >( nonstd_lite_in_place(E), std::forward(args)...) + ); } #if nsel_P0323R <= 3 diff --git a/test/expected.t.cpp b/test/expected.t.cpp index 51dbae8..9b0d4fa 100644 --- a/test/expected.t.cpp +++ b/test/expected.t.cpp @@ -566,6 +566,17 @@ CASE( "make_unexpected(): Allows to create an unexpected_type from an E" ) EXPECT( u.error() == error ); } +CASE( "make_unexpected(): Allows to in-place create an unexpected_type from an E" ) +{ + const auto a = 'a'; + const auto b = 7; + + auto u = make_unexpected< std::pair >( in_place, a, b ); + + EXPECT( u.error().first == a ); + EXPECT( u.error().second == b ); +} + CASE( "make_unexpected_from_current_exception(): Allows to create an unexpected_type from the current exception" "[.deprecated]" ) { #if nsel_P0323R <= 2