| 1 | // Copyright 2021 Peter Dimov. |
|---|---|
| 2 | // Distributed under the Boost Software License, Version 1.0. |
| 3 | // http://www.boost.org/LICENSE_1_0.txt |
| 4 | |
| 5 | #include <boost/system/error_code.hpp> |
| 6 | #include <boost/core/lightweight_test.hpp> |
| 7 | #include <boost/config.hpp> |
| 8 | #include <cerrno> |
| 9 | #include <system_error> |
| 10 | |
| 11 | enum my_errc |
| 12 | { |
| 13 | my_enoent = ENOENT |
| 14 | }; |
| 15 | |
| 16 | #if defined(BOOST_GCC) && BOOST_GCC < 70000 |
| 17 | |
| 18 | // g++ 6 and earlier do not allow specializations outside the namespace |
| 19 | |
| 20 | namespace boost |
| 21 | { |
| 22 | namespace system |
| 23 | { |
| 24 | |
| 25 | template<> struct is_error_condition_enum<my_errc>: std::true_type {}; |
| 26 | |
| 27 | } // namespace system |
| 28 | } // namespace boost |
| 29 | |
| 30 | namespace std |
| 31 | { |
| 32 | |
| 33 | template<> struct is_error_condition_enum<my_errc>: std::true_type {}; |
| 34 | |
| 35 | } // namespace std |
| 36 | |
| 37 | #else |
| 38 | |
| 39 | template<> struct boost::system::is_error_condition_enum<my_errc>: std::true_type {}; |
| 40 | template<> struct std::is_error_condition_enum<my_errc>: std::true_type {}; |
| 41 | |
| 42 | #endif |
| 43 | |
| 44 | boost::system::error_condition make_error_condition( my_errc e ) |
| 45 | { |
| 46 | return boost::system::error_condition( e, boost::system::generic_category() ); |
| 47 | } |
| 48 | |
| 49 | boost::system::error_code make_error_code( my_errc e ) |
| 50 | { |
| 51 | return boost::system::error_code( e, boost::system::generic_category() ); |
| 52 | } |
| 53 | |
| 54 | int main() |
| 55 | { |
| 56 | { |
| 57 | boost::system::error_code e1 = make_error_code( e: my_enoent ); |
| 58 | |
| 59 | BOOST_TEST( e1 == my_enoent ); |
| 60 | BOOST_TEST_NOT( e1 != my_enoent ); |
| 61 | } |
| 62 | |
| 63 | { |
| 64 | std::error_code e1 = make_error_code( e: my_enoent ); |
| 65 | |
| 66 | BOOST_TEST( e1 == my_enoent ); |
| 67 | BOOST_TEST_NOT( e1 != my_enoent ); |
| 68 | } |
| 69 | |
| 70 | return boost::report_errors(); |
| 71 | } |
| 72 |
