diff --git a/doc/system/changes.adoc b/doc/system/changes.adoc index e9ffd23..c1616bb 100644 --- a/doc/system/changes.adoc +++ b/doc/system/changes.adoc @@ -1,16 +1,19 @@ //// Copyright 2018-2021 Peter Dimov - Distributed under the Boost Software License, Version 1.0. - -See accompanying file LICENSE_1_0.txt or copy at -http://www.boost.org/LICENSE_1_0.txt +https://www.boost.org/LICENSE_1_0.txt //// [#changes] # Revision History :idprefix: +## Changes in Boost 1.78 + +* Added support for source locations to `error_code`. +* Added `error_code::to_string`. +* `system_error::what` now contains the source location, if present. + ## Changes in Boost 1.77 * The conversion operator from `error_category` to `std::error_category` diff --git a/doc/system/reference.adoc b/doc/system/reference.adoc index f5be6ab..52fe2fe 100644 --- a/doc/system/reference.adoc +++ b/doc/system/reference.adoc @@ -567,12 +567,18 @@ namespace boost { template constexpr error_code( ErrorCodeEnum e ) noexcept; + error_code( int val, const error_category & cat, + boost::source_location const * loc ) noexcept; + error_code( std::error_code const& ec ) noexcept; // modifiers: constexpr void assign( int val, const error_category & cat ) noexcept; + void assign( int val, const error_category & cat, + boost::source_location const * loc ) noexcept; + template constexpr error_code & operator=( ErrorCodeEnum e ) noexcept; @@ -591,6 +597,9 @@ namespace boost { constexpr bool failed() const noexcept; constexpr explicit operator bool() const noexcept; + bool has_location() const noexcept; + boost::source_location const & location() const noexcept; + // comparisons: friend constexpr bool operator==( const error_code & lhs, @@ -638,6 +647,10 @@ namespace boost { operator std::error_code(); template operator T& (); // only when T=std::error_code + // to_string + + std::string to_string() const; + // stream insertion: template @@ -661,7 +674,7 @@ constexpr error_code() noexcept; [none] * {blank} + -Ensures: :: `value() == 0`; `category() == system_category()`. +Ensures: :: `value() == 0`; `category() == system_category()`; `!has_location()`. ``` constexpr error_code( int val, const error_category & cat ) noexcept; @@ -669,7 +682,7 @@ constexpr error_code( int val, const error_category & cat ) noexcept; [none] * {blank} + -Ensures: :: `value() == val`; `category() == cat`. +Ensures: :: `value() == val`; `category() == cat`; `!has_location()`. ``` template @@ -681,6 +694,16 @@ template Ensures: :: `*this == make_error_code( e )`. Remarks: :: This constructor is only enabled when `is_error_code_enum::value` is `true`. +``` +error_code( int val, const error_category & cat, + boost::source_location const * loc ) noexcept; +``` +[none] +* {blank} ++ +Requires: :: `loc` points to a valid `boost::source_location` object with static storage duration. +Ensures: :: `value() == val`; `category() == cat`; `has_location()`; `&location() == loc`. + ``` error_code( std::error_code const & ec ) noexcept; ``` @@ -688,7 +711,7 @@ error_code( std::error_code const & ec ) noexcept; * {blank} + Effects: :: Construct an `error_code` that wraps `ec`. -Remarks: :: `value()` and `category()` are unspecified. +Remarks: :: `value()` and `category()` are unspecified. `has_location()` is `false`. #### Modifiers @@ -698,7 +721,17 @@ constexpr void assign( int val, const error_category & cat ) noexcept; [none] * {blank} + -Ensures: :: `value() == val`; `category() == cat`. +Ensures: :: `value() == val`; `category() == cat`; `!has_location()`. + +``` +void assign( int val, const error_category & cat, + boost::source_location const * loc ) noexcept; +``` +[none] +* {blank} ++ +Requires: :: `loc` points to a valid `boost::source_location` object with static storage duration. +Ensures: :: `value() == val`; `category() == cat`; `has_location()`; `&location() == loc`. ``` template @@ -782,6 +815,24 @@ constexpr explicit operator bool() const noexcept; Returns: :: `failed()`. +``` +bool has_location() const noexcept; +``` +[none] +* {blank} ++ +Returns: :: `true` if `*this` has been constructed with a pointer to a source + location, `false` otherwise. + +``` +boost::source_location const & location() const noexcept; +``` +[none] +* {blank} ++ +Returns: :: `*loc` if `*this` has been constructed with a pointer to a source + location `loc`, a reference to a default-constructed `boost::source_location` otherwise. + #### Comparisons ``` @@ -941,6 +992,19 @@ Effects: :: If `*this` wraps a `std::error_code` object `ec`, Remarks: :: This operator is only enabled when `T` is `std::error_code`. +#### to_string + +``` +std::string to_string() const; +``` +[none] +* {blank} ++ +Returns: :: If `*this` wraps a `std::error_code` object `e2`, a string that + is the concatenation of `"std:"`, `e2.category().name()`, `':'`, and the + string representation of `e2.value()`. Otherwise, the concatenation of + `category().name()`, `':'`, and the string representation of `value()`. + #### Stream Insertion ``` @@ -951,10 +1015,8 @@ template [none] * {blank} + -Effects: :: If `ec` wraps a `std::error_code` object `e2`, `os << "std:" << e2`. - Otherwise, `os << ec.category().name() << ':' << ec.value()`. -Returns: :: - `os`. +Effects: :: `os << to_string()`. +Returns: :: `os`. #### Nonmembers