From 08c12e8ad54e8879adc6539757398a002a25f0b7 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Fri, 17 Sep 2021 20:16:01 +0300 Subject: [PATCH] Document result --- doc/system/reference.adoc | 244 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 244 insertions(+) diff --git a/doc/system/reference.adoc b/doc/system/reference.adoc index 6b545be..854be96 100644 --- a/doc/system/reference.adoc +++ b/doc/system/reference.adoc @@ -1403,6 +1403,7 @@ constexpr in_place_error_t in_place_error{}; // result template class result; +template class result; } // namespace system } // namespace boost @@ -1704,6 +1705,249 @@ Effects: :: Returns: :: `os`. +### result + +``` +namespace boost { +namespace system { + +template class result +{ +public: + + // constructors + + constexpr result() noexcept; + + template + constexpr result( A&&... a ); + + constexpr result( in_place_value_t ) noexcept; + + template + constexpr result( in_place_error_t, A&&... a ); + + // queries + + constexpr bool has_value() const noexcept; + constexpr bool has_error() const noexcept; + constexpr explicit operator bool() const noexcept; + + // checked value access + + constexpr void value() const; + + // unchecked value access + + constexpr void* operator->() noexcept; + constexpr void const* operator->() const noexcept; + + constexpr void operator*() const noexcept; + + // error access + + constexpr E error() const; + + // swap + + constexpr void swap( result& r ); + friend constexpr void swap( result & r1, result & r2 ); + + // equality + + friend constexpr bool operator==( result const & r1, result const & r2 ); + friend constexpr bool operator!=( result const & r1, result const & r2 ); +}; + +// stream insertion + +template + std::basic_ostream& + operator<<( std::basic_ostream& os, result const & r ); + +} // namespace system +} // namespace boost +``` + +#### Constructors + +``` +constexpr result() noexcept; +``` +[none] +* {blank} ++ +Ensures: :: + `*this` holds an unspecified value. + +``` +template + constexpr result( A&&... a ); +``` +[none] +* {blank} ++ +Effects: :: + - If `std::is_constructible::value`, + ensures that `*this` holds the error `E( std::forward(a)... )`. + - Otherwise, this constructor does not participate in overload resolution. +Remarks: :: + This constructor is only enabled when `sizeof...(T) > 0`. + +``` +template + constexpr result( in_place_value_t ) noexcept; +``` +[none] +* {blank} ++ +Ensures: :: + `*this` holds an unspecified value. + +``` +template + constexpr result( in_place_error_t, A&&... a ); +``` +[none] +* {blank} ++ +Ensures: :: + `*this` holds the error `E( std::forward(a)... )`. +Remarks: :: + This constructor is only enabled when `std::is_constructible::value` is `true`. + +#### Queries + +``` +constexpr bool has_value() const noexcept; +``` +[none] +* {blank} ++ +Returns: :: + `true` when `*this` holds a value, `false` otherwise. + +``` +constexpr bool has_error() const noexcept; +``` +[none] +* {blank} ++ +Returns: :: + `!has_value()`. + +``` +constexpr explicit operator bool() const noexcept; +``` +[none] +* {blank} ++ +Returns: :: + `has_value()`. + +#### Checked Value Access + +``` +constexpr void value() const; +``` +[none] +* {blank} ++ +Effects: :: + If `*this` doesn't hold a value, calls `throw_exception_from_error`, + passing it a reference to the held error. + +#### Unchecked Value Access + +``` +constexpr void* operator->() noexcept; +constexpr void const* operator->() const noexcept; +``` +[none] +* {blank} ++ +Returns: :: + If `*this` holds a value, a pointer to it. Otherwise, `nullptr`. + +``` +constexpr void operator*() const noexcept; +``` +[none] +* {blank} ++ +Requires: :: `*this` holds a value. +Effects: :: + none. + +#### Error Access + +``` +constexpr E error() const; +``` +[none] +* {blank} ++ +Effects: :: + If `*this` holds an error, returns it. Otherwise, returns `E()`. + +#### swap + +``` +constexpr void swap( result& r ); +``` +[none] +* {blank} ++ +Effects: :: + Exchanges the contents of `*this` and `r`. + +``` +friend constexpr void swap( result & r1, result & r2 ); +``` +[none] +* {blank} ++ +Effects: :: + Exchanges the contents of `r1` and `r2`. + +#### Equality + +``` +friend constexpr bool operator==( result const & r1, result const & r2 ); +``` +[none] +* {blank} ++ +Effects: :: + - If `r1` and `r2` hold values, returns `true`. + - If `r1` holds an error `e1` and `r2` holds an error `e2`, returns `e1 == e2`. + - Otherwise, returns `false`. + +``` +friend constexpr bool operator!=( result const & r1, result const & r2 ); +``` +[none] +* {blank} ++ +Returns: :: + `!( r1 == r2 )`. + +#### Stream Insertion + +``` +template + std::basic_ostream& + operator<<( std::basic_ostream& os, result const & r ); +``` +[none] +* {blank} ++ +Effects: :: + - If `*this` holds a value, `os << "value:void";`. + - If `*this` holds an error `e`, `os << "error:" << e;`. +Returns: :: + `os`. + ## This convenience header includes all the headers previously described.