From abd62362efa350abe5507d4eee578cd10e3671e1 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Wed, 9 Feb 2022 20:52:23 +0200 Subject: [PATCH] Update documentation --- doc/system/changes.adoc | 1 + doc/system/reference.adoc | 38 ++++++++++++++++++++++++++++++++++- include/boost/system/errc.hpp | 2 +- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/doc/system/changes.adoc b/doc/system/changes.adoc index 7be2227..08673e3 100644 --- a/doc/system/changes.adoc +++ b/doc/system/changes.adoc @@ -14,6 +14,7 @@ https://www.boost.org/LICENSE_1_0.txt * Added a `boost::source_location` parameter to `throw_exception_from_error`. * `result::value` now automatically supplies `BOOST_CURRENT_LOCATION` to `throw_exception_from_error` via a default argument. +* Added an `errc::make_error_code` overload taking a source location. ## Changes in Boost 1.78 diff --git a/doc/system/reference.adoc b/doc/system/reference.adoc index 3497b68..3067cd7 100644 --- a/doc/system/reference.adoc +++ b/doc/system/reference.adoc @@ -185,9 +185,13 @@ namespace errc { template<> struct is_error_condition_enum { static const bool value = true; }; -constexpr error_code make_error_code( errc::errc_t e ) noexcept; constexpr error_condition make_error_condition( errc::errc_t e ) noexcept; +constexpr error_code make_error_code( errc::errc_t e ) noexcept; + +error_code make_error_code( errc::errc_t e, + boost::source_location const * loc ) noexcept; + } // namespace system } // namespace boost ``` @@ -256,6 +260,38 @@ void my_api_function( boost::system::error_code& ec ) } ``` +``` +constexpr error_code make_error_code( errc::errc_t e, + boost::source_location const * loc ) noexcept; +``` +[none] +* {blank} ++ +Returns: :: `error_code( e, generic_category(), loc )`. + +Same as the above overload, but takes a source location. +* {blank} ++ +``` +void my_api_function( boost::system::error_code& ec ) +{ + void* p = std::malloc( 16 ); + + if( p == 0 ) + { + // return ENOMEM + + BOOST_STATIC_CONSTEXPR boost::source_location loc = + BOOST_CURRENT_LOCATION; + + ec = make_error_code( boost::system::errc::out_of_memory, &loc ); + return; + } + + // use p +} +``` + ## ### error_category diff --git a/include/boost/system/errc.hpp b/include/boost/system/errc.hpp index 0cdccbc..2b642cd 100644 --- a/include/boost/system/errc.hpp +++ b/include/boost/system/errc.hpp @@ -37,7 +37,7 @@ BOOST_SYSTEM_CONSTEXPR inline error_code make_error_code( errc_t e ) BOOST_NOEXC } // explicit conversion: -inline error_code make_error_code( errc_t e, boost::source_location const* loc ) BOOST_NOEXCEPT +inline error_code make_error_code( errc_t e, boost::source_location const * loc ) BOOST_NOEXCEPT { return error_code( e, generic_category(), loc ); }