From ff18f2868459b416a8dc384fd50fa3e10fd0889a Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 27 Aug 2020 16:15:10 +0300 Subject: [PATCH] Move make_ functions for errc to errc.hpp --- include/boost/system/detail/error_code.hpp | 1 + include/boost/system/errc.hpp | 34 ++++++++++++++++++++++ include/boost/system/error_code.hpp | 31 +++----------------- test/Jamfile.v2 | 1 + test/error_condition_test2.cpp | 25 ++++++++++++++++ 5 files changed, 65 insertions(+), 27 deletions(-) create mode 100644 test/error_condition_test2.cpp diff --git a/include/boost/system/detail/error_code.hpp b/include/boost/system/detail/error_code.hpp index 832a97c..2089ecb 100644 --- a/include/boost/system/detail/error_code.hpp +++ b/include/boost/system/detail/error_code.hpp @@ -11,6 +11,7 @@ // See library home page at http://www.boost.org/libs/system #include +#include #include #include #include diff --git a/include/boost/system/errc.hpp b/include/boost/system/errc.hpp index 4b758f1..f9d1bcb 100644 --- a/include/boost/system/errc.hpp +++ b/include/boost/system/errc.hpp @@ -11,5 +11,39 @@ // See library home page at http://www.boost.org/libs/system #include +#include +#include +#include +#include +#include + +namespace boost +{ + +namespace system +{ + +// make_* functions for errc::errc_t + +namespace errc +{ + +// explicit conversion: +BOOST_SYSTEM_CONSTEXPR inline error_code make_error_code( errc_t e ) BOOST_NOEXCEPT +{ + return error_code( e, generic_category() ); +} + +// implicit conversion: +BOOST_SYSTEM_CONSTEXPR inline error_condition make_error_condition( errc_t e ) BOOST_NOEXCEPT +{ + return error_condition( e, generic_category() ); +} + +} // namespace errc + +} // namespace system + +} // namespace boost #endif // #ifndef BOOST_SYSTEM_ERRC_HPP_INCLUDED diff --git a/include/boost/system/error_code.hpp b/include/boost/system/error_code.hpp index 5ef7ae5..87f8b6a 100644 --- a/include/boost/system/error_code.hpp +++ b/include/boost/system/error_code.hpp @@ -10,17 +10,13 @@ // // See library home page at http://www.boost.org/libs/system -#include -#include -#include -#include +#include +#include +#include +#include #include #include -#include -#include -#include #include -#include #include #include #include @@ -75,25 +71,6 @@ inline bool operator!=( const error_condition & lhs, const error_code & rhs ) BO return !( lhs == rhs ); } -// make_* functions for errc::errc_t - -namespace errc -{ - -// explicit conversion: -BOOST_SYSTEM_CONSTEXPR inline error_code make_error_code( errc_t e ) BOOST_NOEXCEPT -{ - return error_code( e, generic_category() ); -} - -// implicit conversion: -BOOST_SYSTEM_CONSTEXPR inline error_condition make_error_condition( errc_t e ) BOOST_NOEXCEPT -{ - return error_condition( e, generic_category() ); -} - -} // namespace errc - } // namespace system } // namespace boost diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 780e0c2..6852590 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -79,3 +79,4 @@ run is_error_condition_enum_test.cpp ; run errc_test.cpp ; run error_category_test2.cpp ; run error_condition_test.cpp ; +run error_condition_test2.cpp ; diff --git a/test/error_condition_test2.cpp b/test/error_condition_test2.cpp new file mode 100644 index 0000000..ef2e9e4 --- /dev/null +++ b/test/error_condition_test2.cpp @@ -0,0 +1,25 @@ +// Copyright 2020 Peter Dimov. +// Distributed under the Boost Software License, Version 1.0. +// http://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include + +namespace sys = boost::system; + +int main() +{ + sys::error_condition en( sys::errc::no_such_file_or_directory ); + + BOOST_TEST_EQ( en.value(), ENOENT ); + + BOOST_TEST( en ); + BOOST_TEST( !!en ); + + BOOST_TEST( en == make_error_condition( sys::errc::no_such_file_or_directory ) ); + + BOOST_TEST( en.category() == sys::error_condition().category() ); + + return boost::report_errors(); +}