Skip to content

Commit

Permalink
Add some more test cases exercising result initialization from {}
Browse files Browse the repository at this point in the history
  • Loading branch information
pdimov committed Oct 20, 2023
1 parent eb78861 commit 61a0e24
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
46 changes: 46 additions & 0 deletions test/result_default_construct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,66 @@ int main()
BOOST_TEST_EQ( r.value(), 0 );
}

{
result<int> r{};

BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );

BOOST_TEST_EQ( r.value(), 0 );
}

{
result<int> r = {};

BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );

BOOST_TEST_EQ( r.value(), 0 );
}

{
result<X> r;

BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
}

{
result<X> r{};

BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
}

{
result<X> r = {};

BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
}

{
result<void> r;

BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
}

{
result<void> r{};

BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
}

{
result<void> r = {};

BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
}

{
BOOST_TEST_TRAIT_TRUE((std::is_default_constructible<result<int>>));
BOOST_TEST_TRAIT_TRUE((std::is_default_constructible<result<int, int>>));
Expand Down
12 changes: 12 additions & 0 deletions test/result_value_construct2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ result<std::vector<int>> fv2()
return {{ 1, 2 }};
}

result<void> fw0()
{
return {};
}

int main()
{
{
Expand Down Expand Up @@ -148,5 +153,12 @@ int main()
BOOST_TEST_EQ( r->at(1), 2 );
}

{
result<void> r = fw0();

BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
}

return boost::report_errors();
}

0 comments on commit 61a0e24

Please sign in to comment.