2
0
mirror of https://github.com/boostorg/leaf.git synced 2026-01-19 04:22:08 +00:00
This commit is contained in:
Emil Dotchevski
2020-10-20 12:23:13 -07:00
parent c20262d1f8
commit 44eec77cf0
103 changed files with 15900 additions and 15900 deletions

View File

@@ -15,72 +15,72 @@ namespace leaf = boost::leaf;
template <int A>
struct info
{
int value;
int value;
};
leaf::result<void> f12()
{
return leaf::new_error( info<1>{1}, info<2>{2} );
return leaf::new_error( info<1>{1}, info<2>{2} );
}
leaf::result<void> f23()
{
return leaf::new_error( info<2>{2}, info<3>{3} );
return leaf::new_error( info<2>{2}, info<3>{3} );
}
int main()
{
{
int r = leaf::try_handle_all(
[]() -> leaf::result<int>
{
leaf::result<void> r1 = f12();
(void) r1;
leaf::result<void> r2 = f23();
return r2.error();
},
[]( info<1> )
{
return 1;
},
[]( info<2> const & x, info<3> const & y )
{
BOOST_TEST_EQ(x.value, 2);
BOOST_TEST_EQ(y.value, 3);
return 2;
},
[]
{
return 3;
} );
BOOST_TEST_EQ(r, 2);
}
{
int r = leaf::try_handle_all(
[]() -> leaf::result<int>
{
leaf::result<void> r1 = f12();
(void) r1;
leaf::result<void> r2 = f23();
return r2.error();
},
[]( info<1> )
{
return 1;
},
[]( info<2> const & x, info<3> const & y )
{
BOOST_TEST_EQ(x.value, 2);
BOOST_TEST_EQ(y.value, 3);
return 2;
},
[]
{
return 3;
} );
BOOST_TEST_EQ(r, 2);
}
#ifndef BOOST_LEAF_NO_EXCEPTIONS
{
int r = leaf::try_catch(
[]() -> int
{
try
{
throw leaf::exception(info<4>{4});
}
catch(...)
{
}
throw std::exception{};
},
[]( std::exception const &, info<4> )
{
return 1;
},
[]( std::exception const & )
{
return 2;
} );
BOOST_TEST_EQ(r, 2);
}
{
int r = leaf::try_catch(
[]() -> int
{
try
{
throw leaf::exception(info<4>{4});
}
catch(...)
{
}
throw std::exception{};
},
[]( std::exception const &, info<4> )
{
return 1;
},
[]( std::exception const & )
{
return 2;
} );
BOOST_TEST_EQ(r, 2);
}
#endif
return boost::report_errors();
return boost::report_errors();
}