| 1 | // Copyright 2023 Peter Dimov. |
|---|---|
| 2 | // Distributed under the Boost Software License, Version 1.0. |
| 3 | // https://www.boost.org/LICENSE_1_0.txt |
| 4 | |
| 5 | #include <boost/system/result.hpp> |
| 6 | #include <boost/core/lightweight_test.hpp> |
| 7 | |
| 8 | using namespace boost::system; |
| 9 | |
| 10 | // Eigen::Matrix4d has an explicit templated constructor |
| 11 | // https://github.com/boostorg/system/issues/103 |
| 12 | // https://github.com/boostorg/json/issues/843 |
| 13 | |
| 14 | struct X |
| 15 | { |
| 16 | X() {} |
| 17 | template<class T> explicit X( T const& ) {} |
| 18 | }; |
| 19 | |
| 20 | int main() |
| 21 | { |
| 22 | { |
| 23 | auto ec = make_error_code( e: errc::invalid_argument ); |
| 24 | |
| 25 | result<X> r = ec; |
| 26 | |
| 27 | BOOST_TEST( !r.has_value() ); |
| 28 | BOOST_TEST( r.has_error() ); |
| 29 | |
| 30 | BOOST_TEST_EQ( r.error(), ec ); |
| 31 | } |
| 32 | |
| 33 | { |
| 34 | auto ec = make_error_code( e: std::errc::invalid_argument ); |
| 35 | |
| 36 | result<X> r = ec; |
| 37 | |
| 38 | BOOST_TEST( !r.has_value() ); |
| 39 | BOOST_TEST( r.has_error() ); |
| 40 | |
| 41 | BOOST_TEST_EQ( r.error(), ec ); |
| 42 | } |
| 43 | |
| 44 | return boost::report_errors(); |
| 45 | } |
| 46 |
