From 4e34749d87c0fd3113631c0dfe76d2d61f8988be Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sat, 3 Jun 2017 14:43:21 +0300 Subject: [PATCH] Add doc/expected.md --- doc/expected.md | 131 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 doc/expected.md diff --git a/doc/expected.md b/doc/expected.md new file mode 100644 index 0000000..e1355f1 --- /dev/null +++ b/doc/expected.md @@ -0,0 +1,131 @@ +# expected + +## Synopsis + + // unexpected_ + + template using unexpected_ = variant; + + // bad_expected_access + + template class bad_expected_access; + + template<> class bad_expected_access: public std::exception + { + public: + + bad_expected_access() noexcept; + char const * what() const noexcept; + }; + + template class bad_expected_access: public bad_expected_access + { + public: + + explicit bad_expected_access( E const& e ); + E error() const; + }; + + // throw_on_unexpected + + template void throw_on_unexpected( E const& e ); + void throw_on_unexpected( std::error_code const & e ); + void throw_on_unexpected( std::exception_ptr const & e ); + + // expected + + template class expected + { + public: + + // value constructors + + constexpr expected() noexcept( /*see below*/ ); + + constexpr expected( T const& t ) noexcept( /*see below*/ ); + constexpr expected( T && t ) noexcept( /*see below*/ ); + + // unexpected constructor + + template + constexpr expected( unexpected_ const & x ); + + template + constexpr expected( unexpected_ && x ); + + // conversion constructor + + template + constexpr expected( expected const & x ); + + template + constexpr expected( expected && x ); + + // emplace + + template void emplace( A&&... a ); + template void emplace( std::initializer_list il, A&&... a ); + + // swap + + void swap( expected & r ) noexcept( /*see below*/ ); + + // value queries + + constexpr bool has_value() const noexcept; + constexpr explicit operator bool() const noexcept; + + // checked value access + + constexpr T& value() &; + constexpr T const& value() const&; + constexpr T&& value() &&; + constexpr T const&& value() const&&; + + // unchecked value access + + T* operator->() noexcept; + T const* operator->() const noexcept; + + T& operator*() & noexcept; + T const& operator*() const & noexcept; + T&& operator*() && noexcept; + T const&& operator*() const && noexcept; + + // error queries + + template constexpr bool has_error() const noexcept; + constexpr bool has_error() const noexcept; + + // error access + + unexpected_ unexpected() const; + + template constexpr E2 error() const noexcept; + constexpr mp_first error() const noexcept; + + // error mapping + + template /*see below*/ remap_errors( F && f ) const; + expected remap_errors(); + + // then + + template /*see below*/ operator>>( F && f ) const; + }; + + template inline constexpr bool operator==( expected const & x1, expected const & x2 ); + template inline constexpr bool operator!=( expected const & x1, expected const & x2 ); + + template inline void swap( expected & x1, expected & x2 ) noexcept( /*see below*/ ); + + } // namespace variant2 + } // namespace boost + + // is_expected + + template struct is_expected; + +## Reference + +...