mirror of
https://github.com/TartanLlama/expected.git
synced 2025-08-03 10:54:31 +02:00
More docs
This commit is contained in:
407
docs/index.md
Normal file
407
docs/index.md
Normal file
@@ -0,0 +1,407 @@
|
||||
# Header file `expected.hpp`<a id="expected.hpp"></a>
|
||||
|
||||
<pre><code class="language-cpp">#define <a href='doc_expected.md#expected.hpp'>TL_EXPECTED_HPP</a>
|
||||
|
||||
#define <a href='doc_expected.md#expected.hpp'>TL_EXPECTED_GCC49</a>
|
||||
|
||||
#define <a href='doc_expected.md#expected.hpp'>TL_EXPECTED_NO_CONSTRR</a>
|
||||
|
||||
#define <a href='doc_expected.md#expected.hpp'>TL_EXPECTED_CXX14</a>
|
||||
|
||||
#define <a href='doc_expected.md#expected.hpp'>TL_IN_PLACE_MONOSTATE_DEFINED</a>
|
||||
|
||||
namespace <a href='doc_expected.md#expected.hpp'>tl</a>
|
||||
{
|
||||
class <a href='doc_expected.md#tl::monostate'>monostate</a>;
|
||||
|
||||
struct <a href='doc_expected.md#tl::in_place_t'>in_place_t</a>;
|
||||
|
||||
constexpr <a href='doc_expected.md#tl::in_place_t'>in_place_t{}</a> <a href='doc_expected.md#tl::in_place'>in_place</a>;
|
||||
|
||||
template <class E>
|
||||
class <a href='doc_expected.md#tl::unexpected-E-'>unexpected</a>;
|
||||
|
||||
template <class E>
|
||||
constexpr bool <a href='doc_expected.md#tl::operator==(constunexpected-E-&,constunexpected-E-&)'>operator==</a>(const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& lhs, const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& rhs);
|
||||
template <class E>
|
||||
constexpr bool <a href='doc_expected.md#tl::operator==(constunexpected-E-&,constunexpected-E-&)'>operator!=</a>(const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& lhs, const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& rhs);
|
||||
template <class E>
|
||||
constexpr bool <a href='doc_expected.md#tl::operator==(constunexpected-E-&,constunexpected-E-&)'>operator<</a>(const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& lhs, const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& rhs);
|
||||
template <class E>
|
||||
constexpr bool <a href='doc_expected.md#tl::operator==(constunexpected-E-&,constunexpected-E-&)'>operator<=</a>(const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& lhs, const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& rhs);
|
||||
template <class E>
|
||||
constexpr bool <a href='doc_expected.md#tl::operator==(constunexpected-E-&,constunexpected-E-&)'>operator></a>(const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& lhs, const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& rhs);
|
||||
template <class E>
|
||||
constexpr bool <a href='doc_expected.md#tl::operator==(constunexpected-E-&,constunexpected-E-&)'>operator>=</a>(const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& lhs, const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& rhs);
|
||||
|
||||
template <class E>
|
||||
<a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a> <a href='doc_expected.md#tl::make_unexpected(E&&)'>make_unexpected</a>(E&& e);
|
||||
|
||||
struct <a href='doc_expected.md#tl::unexpect_t'>unexpect_t</a>;
|
||||
|
||||
constexpr <a href='doc_expected.md#tl::unexpect_t'>unexpect_t{}</a> <a href='doc_expected.md#tl::unexpect'>unexpect</a>;
|
||||
|
||||
template <class E>
|
||||
class <a href='doc_expected.md#expected.hpp'>bad_expected_access</a>;
|
||||
|
||||
template <class T, class E>
|
||||
class <a href='doc_expected.md#tl::expected-T,E-'>expected</a>;
|
||||
|
||||
template <class T, class E, class U, class F>
|
||||
constexpr bool <a href='doc_expected.md#expected.hpp'>operator==</a>(const <a href='doc_expected.md#tl::expected-T,E-'>expected<T, E></a>& lhs, const <a href='doc_expected.md#tl::expected-T,E-'>expected<U, F></a>& rhs);
|
||||
|
||||
template <class T, class E, class U, class F>
|
||||
constexpr bool <a href='doc_expected.md#expected.hpp'>operator!=</a>(const <a href='doc_expected.md#tl::expected-T,E-'>expected<T, E></a>& lhs, const <a href='doc_expected.md#tl::expected-T,E-'>expected<U, F></a>& rhs);
|
||||
|
||||
template <class T, class E, class U, class F>
|
||||
constexpr bool <a href='doc_expected.md#expected.hpp'>operator<</a>(const <a href='doc_expected.md#tl::expected-T,E-'>expected<T, E></a>& lhs, const <a href='doc_expected.md#tl::expected-T,E-'>expected<U, F></a>& rhs);
|
||||
|
||||
template <class T, class E, class U, class F>
|
||||
constexpr bool <a href='doc_expected.md#expected.hpp'>operator></a>(const <a href='doc_expected.md#tl::expected-T,E-'>expected<T, E></a>& lhs, const <a href='doc_expected.md#tl::expected-T,E-'>expected<U, F></a>& rhs);
|
||||
|
||||
template <class T, class E, class U, class F>
|
||||
constexpr bool <a href='doc_expected.md#expected.hpp'>operator<=</a>(const <a href='doc_expected.md#tl::expected-T,E-'>expected<T, E></a>& lhs, const <a href='doc_expected.md#tl::expected-T,E-'>expected<U, F></a>& rhs);
|
||||
|
||||
template <class T, class E, class U, class F>
|
||||
constexpr bool <a href='doc_expected.md#expected.hpp'>operator>=</a>(const <a href='doc_expected.md#tl::expected-T,E-'>expected<T, E></a>& lhs, const <a href='doc_expected.md#tl::expected-T,E-'>expected<U, F></a>& rhs);
|
||||
|
||||
template <class T, class E, class U>
|
||||
constexpr bool <a href='doc_expected.md#expected.hpp'>operator==</a>(const <a href='doc_expected.md#tl::expected-T,E-'>expected<T, E></a>& x, const U& v);
|
||||
|
||||
template <class T, class E, class U>
|
||||
constexpr bool <a href='doc_expected.md#expected.hpp'>operator==</a>(const U& v, const <a href='doc_expected.md#tl::expected-T,E-'>expected<T, E></a>& x);
|
||||
|
||||
template <class T, class E, class U>
|
||||
constexpr bool <a href='doc_expected.md#expected.hpp'>operator!=</a>(const <a href='doc_expected.md#tl::expected-T,E-'>expected<T, E></a>& x, const U& v);
|
||||
|
||||
template <class T, class E, class U>
|
||||
constexpr bool <a href='doc_expected.md#expected.hpp'>operator!=</a>(const U& v, const <a href='doc_expected.md#tl::expected-T,E-'>expected<T, E></a>& x);
|
||||
|
||||
template <class T, class E, class U>
|
||||
constexpr bool <a href='doc_expected.md#expected.hpp'>operator<</a>(const <a href='doc_expected.md#tl::expected-T,E-'>expected<T, E></a>& x, const U& v);
|
||||
|
||||
template <class T, class E, class U>
|
||||
constexpr bool <a href='doc_expected.md#expected.hpp'>operator<</a>(const U& v, const <a href='doc_expected.md#tl::expected-T,E-'>expected<T, E></a>& x);
|
||||
|
||||
template <class T, class E, class U>
|
||||
constexpr bool <a href='doc_expected.md#expected.hpp'>operator<=</a>(const <a href='doc_expected.md#tl::expected-T,E-'>expected<T, E></a>& x, const U& v);
|
||||
|
||||
template <class T, class E, class U>
|
||||
constexpr bool <a href='doc_expected.md#expected.hpp'>operator<=</a>(const U& v, const <a href='doc_expected.md#tl::expected-T,E-'>expected<T, E></a>& x);
|
||||
|
||||
template <class T, class E, class U>
|
||||
constexpr bool <a href='doc_expected.md#expected.hpp'>operator></a>(const <a href='doc_expected.md#tl::expected-T,E-'>expected<T, E></a>& x, const U& v);
|
||||
|
||||
template <class T, class E, class U>
|
||||
constexpr bool <a href='doc_expected.md#expected.hpp'>operator></a>(const U& v, const <a href='doc_expected.md#tl::expected-T,E-'>expected<T, E></a>& x);
|
||||
|
||||
template <class T, class E, class U>
|
||||
constexpr bool <a href='doc_expected.md#expected.hpp'>operator>=</a>(const <a href='doc_expected.md#tl::expected-T,E-'>expected<T, E></a>& x, const U& v);
|
||||
|
||||
template <class T, class E, class U>
|
||||
constexpr bool <a href='doc_expected.md#expected.hpp'>operator>=</a>(const U& v, const <a href='doc_expected.md#tl::expected-T,E-'>expected<T, E></a>& x);
|
||||
|
||||
template <class T, class E>
|
||||
constexpr bool <a href='doc_expected.md#expected.hpp'>operator==</a>(const <a href='doc_expected.md#tl::expected-T,E-'>expected<T, E></a>& x, const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& e);
|
||||
|
||||
template <class T, class E>
|
||||
constexpr bool <a href='doc_expected.md#expected.hpp'>operator==</a>(const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& e, const <a href='doc_expected.md#tl::expected-T,E-'>expected<T, E></a>& x);
|
||||
|
||||
template <class T, class E>
|
||||
constexpr bool <a href='doc_expected.md#expected.hpp'>operator!=</a>(const <a href='doc_expected.md#tl::expected-T,E-'>expected<T, E></a>& x, const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& e);
|
||||
|
||||
template <class T, class E>
|
||||
constexpr bool <a href='doc_expected.md#expected.hpp'>operator!=</a>(const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& e, const <a href='doc_expected.md#tl::expected-T,E-'>expected<T, E></a>& x);
|
||||
|
||||
template <class T, class E>
|
||||
constexpr bool <a href='doc_expected.md#expected.hpp'>operator<</a>(const <a href='doc_expected.md#tl::expected-T,E-'>expected<T, E></a>& x, const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& e);
|
||||
|
||||
template <class T, class E>
|
||||
constexpr bool <a href='doc_expected.md#expected.hpp'>operator<</a>(const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& e, const <a href='doc_expected.md#tl::expected-T,E-'>expected<T, E></a>& x);
|
||||
|
||||
template <class T, class E>
|
||||
constexpr bool <a href='doc_expected.md#expected.hpp'>operator<=</a>(const <a href='doc_expected.md#tl::expected-T,E-'>expected<T, E></a>& x, const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& e);
|
||||
|
||||
template <class T, class E>
|
||||
constexpr bool <a href='doc_expected.md#expected.hpp'>operator<=</a>(const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& e, const <a href='doc_expected.md#tl::expected-T,E-'>expected<T, E></a>& x);
|
||||
|
||||
template <class T, class E>
|
||||
constexpr bool <a href='doc_expected.md#expected.hpp'>operator></a>(const <a href='doc_expected.md#tl::expected-T,E-'>expected<T, E></a>& x, const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& e);
|
||||
|
||||
template <class T, class E>
|
||||
constexpr bool <a href='doc_expected.md#expected.hpp'>operator></a>(const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& e, const <a href='doc_expected.md#tl::expected-T,E-'>expected<T, E></a>& x);
|
||||
|
||||
template <class T, class E>
|
||||
constexpr bool <a href='doc_expected.md#expected.hpp'>operator>=</a>(const <a href='doc_expected.md#tl::expected-T,E-'>expected<T, E></a>& x, const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& e);
|
||||
|
||||
template <class T, class E>
|
||||
constexpr bool <a href='doc_expected.md#expected.hpp'>operator>=</a>(const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& e, const <a href='doc_expected.md#tl::expected-T,E-'>expected<T, E></a>& x);
|
||||
|
||||
template <class T, class E, 'hidden'>
|
||||
void <a href='doc_expected.md#expected.hpp'>swap</a>(<a href='doc_expected.md#tl::expected-T,E-'>expected<T, E></a>& lhs, <a href='doc_expected.md#tl::expected-T,E-'>expected<T, E></a>& rhs) noexcept(noexcept(lhs.swap(rhs)));
|
||||
}</code></pre>
|
||||
|
||||
## Class `tl::monostate`<a id="tl::monostate"></a>
|
||||
|
||||
<pre><code class="language-cpp">class monostate
|
||||
{
|
||||
};</code></pre>
|
||||
|
||||
Used to represent an expected with no data
|
||||
|
||||
## Struct `tl::in_place_t`<a id="tl::in_place_t"></a>
|
||||
|
||||
<pre><code class="language-cpp">struct in_place_t
|
||||
{
|
||||
<a href='doc_expected.md#tl::in_place_t'>in_place_t</a>() = default;
|
||||
};</code></pre>
|
||||
|
||||
A tag type to tell expected to construct its value in-place
|
||||
|
||||
## Variable `tl::in_place`<a id="tl::in_place"></a>
|
||||
|
||||
<pre><code class="language-cpp">constexpr <a href='doc_expected.md#tl::in_place_t'>in_place_t{}</a> in_place;</code></pre>
|
||||
|
||||
A tag to tell expected to construct its value in-place
|
||||
|
||||
## Class template `tl::unexpected`<a id="tl::unexpected-E-"></a>
|
||||
|
||||
<pre><code class="language-cpp">template <class E>
|
||||
class unexpected
|
||||
{
|
||||
public:
|
||||
<a href='doc_expected.md#tl::unexpected-E-'>unexpected</a>() = delete;
|
||||
|
||||
constexpr <a href='doc_expected.md#tl::unexpected-E-'>unexpected</a>(const E& e);
|
||||
|
||||
constexpr <a href='doc_expected.md#tl::unexpected-E-'>unexpected</a>(E&& e);
|
||||
|
||||
constexpr const E& <a href='doc_expected.md#tl::unexpected-E-::value()const&'>value</a>() const &;
|
||||
constexpr E& <a href='doc_expected.md#tl::unexpected-E-::value()const&'>value</a>() &;
|
||||
constexpr E&& <a href='doc_expected.md#tl::unexpected-E-::value()const&'>value</a>() &&;
|
||||
};</code></pre>
|
||||
|
||||
Used as a wrapper to store the unexpected value
|
||||
|
||||
### Function `tl::unexpected::value`<a id="tl::unexpected-E-::value()const&"></a>
|
||||
|
||||
<pre><code class="language-cpp">(1) constexpr const E& value() const &;
|
||||
|
||||
(2) constexpr E& value() &;
|
||||
|
||||
(3) constexpr E&& value() &&;</code></pre>
|
||||
|
||||
*Returns*: the contained value
|
||||
|
||||
-----
|
||||
|
||||
## Comparison operator `tl::operator==`<a id="tl::operator==(constunexpected-E-&,constunexpected-E-&)"></a>
|
||||
|
||||
<pre><code class="language-cpp">(1) template <class E>
|
||||
constexpr bool operator==(const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& lhs, const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& rhs);
|
||||
|
||||
(2) template <class E>
|
||||
constexpr bool operator!=(const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& lhs, const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& rhs);
|
||||
|
||||
(3) template <class E>
|
||||
constexpr bool operator<(const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& lhs, const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& rhs);
|
||||
|
||||
(4) template <class E>
|
||||
constexpr bool operator<=(const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& lhs, const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& rhs);
|
||||
|
||||
(5) template <class E>
|
||||
constexpr bool operator>(const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& lhs, const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& rhs);
|
||||
|
||||
(6) template <class E>
|
||||
constexpr bool operator>=(const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& lhs, const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>& rhs);</code></pre>
|
||||
|
||||
Compares two unexpected objects
|
||||
|
||||
Simply compares lhs.value() to rhs.value()
|
||||
|
||||
## Function template `tl::make_unexpected`<a id="tl::make_unexpected(E&&)"></a>
|
||||
|
||||
<pre><code class="language-cpp">template <class E>
|
||||
<a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a> make_unexpected(E&& e);</code></pre>
|
||||
|
||||
Create an `unexpected` from `e`, deducing the return type
|
||||
|
||||
*Example:* auto e1 = tl::make\_unexpected(42); unexpected\<int\> e2 (42); //same semantics
|
||||
|
||||
## Struct `tl::unexpect_t`<a id="tl::unexpect_t"></a>
|
||||
|
||||
<pre><code class="language-cpp">struct unexpect_t
|
||||
{
|
||||
<a href='doc_expected.md#tl::unexpect_t'>unexpect_t</a>() = default;
|
||||
};</code></pre>
|
||||
|
||||
A tag type to tell expected to construct the unexpected value
|
||||
|
||||
## Variable `tl::unexpect`<a id="tl::unexpect"></a>
|
||||
|
||||
<pre><code class="language-cpp">constexpr <a href='doc_expected.md#tl::unexpect_t'>unexpect_t{}</a> unexpect;</code></pre>
|
||||
|
||||
A tag to tell expected to construct the unexpected value
|
||||
|
||||
## Class template `tl::expected`<a id="tl::expected-T,E-"></a>
|
||||
|
||||
<pre><code class="language-cpp">template <class T, class E>
|
||||
class expected
|
||||
{
|
||||
public:
|
||||
using <a href='doc_expected.md#tl::expected-T,E-'>value_type</a> = T;
|
||||
|
||||
using <a href='doc_expected.md#tl::expected-T,E-'>error_type</a> = E;
|
||||
|
||||
using <a href='doc_expected.md#tl::expected-T,E-'>unexpected_type</a> = <a href='doc_expected.md#tl::unexpected-E-'>unexpected<E></a>;
|
||||
|
||||
template <class F>
|
||||
'hidden' <a href='doc_expected.md#tl::expected-T,E-::and_then(F&&)&'>and_then</a>(F&& f) &;
|
||||
template <class F>
|
||||
constexpr auto and_then(F &&f) &&;
|
||||
template <class F>
|
||||
constexpr auto and_then(F &&f) const &;
|
||||
|
||||
template <class F> constexpr auto map(F &&f) &;
|
||||
template <class F> constexpr auto map(F &&f) &&;
|
||||
template <class F> constexpr auto map(F &&f) const &;
|
||||
|
||||
template <class F> constexpr auto map_error(F &&f) &;
|
||||
template <class F> constexpr auto map_error(F &&f) &&;
|
||||
template <class F> constexpr auto map_error(F &&f) const &;
|
||||
|
||||
constexpr <a href='doc_expected.md#tl::expected-T,E-'>expected</a>() = default;
|
||||
|
||||
constexpr <a href='doc_expected.md#tl::expected-T,E-'>expected</a>(const <a href='doc_expected.md#tl::expected-T,E-'>expected</a>& rhs) = default;
|
||||
|
||||
constexpr <a href='doc_expected.md#tl::expected-T,E-'>expected</a>(<a href='doc_expected.md#tl::expected-T,E-'>expected</a>&& rhs) = default;
|
||||
|
||||
constexpr <a href='doc_expected.md#tl::expected-T,E-'>expected</a>& <a href='doc_expected.md#tl::expected-T,E-'>operator=</a>(const <a href='doc_expected.md#tl::expected-T,E-'>expected</a>& rhs) = default;
|
||||
|
||||
constexpr <a href='doc_expected.md#tl::expected-T,E-'>expected</a>& <a href='doc_expected.md#tl::expected-T,E-'>operator=</a>(<a href='doc_expected.md#tl::expected-T,E-'>expected</a>&& rhs) = default;
|
||||
|
||||
template <class ... Args, 'hidden' ... = nullptr>
|
||||
constexpr <a href='doc_expected.md#tl::expected-T,E-'>expected</a>(<a href='doc_expected.md#tl::in_place_t'>in_place_t</a>, Args&&... args);
|
||||
|
||||
template <class U, class ... Args, 'hidden' ... = nullptr>
|
||||
constexpr <a href='doc_expected.md#tl::expected-T,E-'>expected</a>(<a href='doc_expected.md#tl::in_place_t'>in_place_t</a>, <a href='http://en.cppreference.com/mwiki/index.php?title=Special%3ASearch&search=std::initializer_list%3cU%3e'>std::initializer_list<U></a> il, Args&&... args);
|
||||
|
||||
EXPLICIT constexpr expected(const unexpected<G> &e);
|
||||
EXPLICIT constexpr expected(unexpected<G> &&e);
|
||||
|
||||
template <class ... Args, 'hidden' ... = nullptr>
|
||||
constexpr <a href='doc_expected.md#tl::expected-T,E-'>expected</a>(<a href='doc_expected.md#tl::unexpect_t'>unexpect_t</a>, Args&&... args);
|
||||
|
||||
template <class U, class G, 'hidden'>
|
||||
constexpr <a href='doc_expected.md#tl::expected-T,E-'>expected</a>(const <a href='doc_expected.md#tl::expected-T,E-'>expected<U, G></a>& rhs);
|
||||
|
||||
template <class U, class G, 'hidden'>
|
||||
constexpr <a href='doc_expected.md#tl::expected-T,E-'>expected</a>(<a href='doc_expected.md#tl::expected-T,E-'>expected<U, G></a>&& rhs);
|
||||
|
||||
template <class U = T, 'hidden'>
|
||||
constexpr <a href='doc_expected.md#tl::expected-T,E-'>expected</a>(U&& v);
|
||||
|
||||
template <class U = T, 'hidden', 'hidden'>
|
||||
<a href='doc_expected.md#tl::expected-T,E-'>expected</a>& <a href='doc_expected.md#tl::expected-T,E-'>operator=</a>(U&& v);
|
||||
|
||||
template <class G = E, 'hidden'>
|
||||
<a href='doc_expected.md#tl::expected-T,E-'>expected</a>& <a href='doc_expected.md#tl::expected-T,E-'>operator=</a>(const <a href='doc_expected.md#tl::unexpected-E-'>unexpected<G></a>& rhs);
|
||||
|
||||
template <class G = E, 'hidden'>
|
||||
<a href='doc_expected.md#tl::expected-T,E-'>expected</a>& <a href='doc_expected.md#tl::expected-T,E-'>operator=</a>(<a href='doc_expected.md#tl::unexpected-E-'>unexpected<G></a>&& rhs) noexcept;
|
||||
|
||||
template <class ... Args, 'hidden' ... = nullptr>
|
||||
void <a href='doc_expected.md#tl::expected-T,E-'>emplace</a>(Args&&... args);
|
||||
|
||||
template <class U, class ... Args, 'hidden' ... = nullptr>
|
||||
void <a href='doc_expected.md#tl::expected-T,E-'>emplace</a>(<a href='http://en.cppreference.com/mwiki/index.php?title=Special%3ASearch&search=std::initializer_list%3cU%3e'>std::initializer_list<U></a> il, Args&&... args);
|
||||
|
||||
void <a href='doc_expected.md#tl::expected-T,E-'>swap</a>(<a href='doc_expected.md#tl::expected-T,E-'>expected</a>& rhs) noexcept(std::is_nothrow_move_constructible<T>::value&&noexcept(swap(std::declval<T&>(), std::declval<T&>()))&&std::is_nothrow_move_constructible<E>::value&&noexcept(swap(std::declval<E&>(), std::declval<E&>())));
|
||||
|
||||
constexpr const T* <a href='doc_expected.md#tl::expected-T,E-'>operator-></a>() const;
|
||||
|
||||
constexpr T* <a href='doc_expected.md#tl::expected-T,E-'>operator-></a>();
|
||||
|
||||
constexpr const T& <a href='doc_expected.md#tl::expected-T,E-'>operator*</a>() const &;
|
||||
|
||||
constexpr T& <a href='doc_expected.md#tl::expected-T,E-'>operator*</a>() &;
|
||||
|
||||
constexpr const T&& <a href='doc_expected.md#tl::expected-T,E-'>operator*</a>() const &&;
|
||||
|
||||
constexpr T&& <a href='doc_expected.md#tl::expected-T,E-'>operator*</a>() &&;
|
||||
|
||||
constexpr <a href='doc_expected.md#tl::expected-T,E-'>operator bool</a>() const noexcept;
|
||||
|
||||
constexpr bool <a href='doc_expected.md#tl::expected-T,E-'>has_value</a>() const noexcept;
|
||||
|
||||
constexpr const T& <a href='doc_expected.md#tl::expected-T,E-'>value</a>() const &;
|
||||
|
||||
constexpr T& <a href='doc_expected.md#tl::expected-T,E-'>value</a>() &;
|
||||
|
||||
constexpr const T&& <a href='doc_expected.md#tl::expected-T,E-'>value</a>() const &&;
|
||||
|
||||
constexpr T&& <a href='doc_expected.md#tl::expected-T,E-'>value</a>() &&;
|
||||
|
||||
constexpr const E& <a href='doc_expected.md#tl::expected-T,E-'>error</a>() const &;
|
||||
|
||||
constexpr E& <a href='doc_expected.md#tl::expected-T,E-'>error</a>() &;
|
||||
|
||||
constexpr const E&& <a href='doc_expected.md#tl::expected-T,E-'>error</a>() const &&;
|
||||
|
||||
constexpr E&& <a href='doc_expected.md#tl::expected-T,E-'>error</a>() &&;
|
||||
|
||||
template <class U>
|
||||
constexpr T <a href='doc_expected.md#tl::expected-T,E-'>value_or</a>(U&& v) const &;
|
||||
|
||||
template <class U>
|
||||
T <a href='doc_expected.md#tl::expected-T,E-'>value_or</a>(U&& v) &&;
|
||||
};</code></pre>
|
||||
|
||||
An `expected<T, E>` object is an object that contains the storage for another object and manages the lifetime of this contained object `T`. Alternatively it could contain the storage for another unexpected object `E`. The contained object may not be initialized after the expected object has been initialized, and may not be destroyed before the expected object has been destroyed. The initialization state of the contained object is tracked by the expected object.
|
||||
|
||||
### Function template `tl::expected::and_then`<a id="tl::expected-T,E-::and_then(F&&)&"></a>
|
||||
|
||||
<pre><code class="language-cpp">(1) template <class F>
|
||||
'hidden' and_then(F&& f) &;
|
||||
|
||||
(2) template <class F>
|
||||
constexpr auto and_then(F &&f) &&;
|
||||
|
||||
(3) template <class F>
|
||||
constexpr auto and_then(F &&f) const &;</code></pre>
|
||||
|
||||
Carries out some operation which returns an optional on the stored object if there is one. \\requires `std::invoke(std::forward<F>(f), value())` returns a `std::optional<U>` for some `U`. \\returns Let `U` be the result of `std::invoke(std::forward<F>(f), value())`. Returns a `std::optional<U>`. The return value is empty if `*this` is empty, otherwise the return value of `std::invoke(std::forward<F>(f), value())` is returned. \\group and\_then \\synopsis template \<class F\>\\nconstexpr auto and\_then(F &\&f) &;
|
||||
|
||||
### Function template `tl::expected::map`<a id="tl::expected-T,E-::map(F&&)&"></a>
|
||||
|
||||
<pre><code class="language-cpp">(1) template <class F> constexpr auto map(F &&f) &;
|
||||
|
||||
(2) template <class F> constexpr auto map(F &&f) &&;
|
||||
|
||||
(3) template <class F> constexpr auto map(F &&f) const &;</code></pre>
|
||||
|
||||
Carries out some operation on the stored object if there is one.
|
||||
|
||||
*Returns*: Let `U` be the result of `std::invoke(std::forward<F>(f), value())`. Returns a `std::expected<U,E>`. If `*this` is unexpected, the result is `*this`, otherwise an `expected<U,E>` is constructed from the return value of `std::invoke(std::forward<F>(f), value())` and is returned.
|
||||
|
||||
### Function template `tl::expected::map_error`<a id="tl::expected-T,E-::map_error(F&&)&"></a>
|
||||
|
||||
<pre><code class="language-cpp">(1) template <class F> constexpr auto map_error(F &&f) &;
|
||||
|
||||
(2) template <class F> constexpr auto map_error(F &&f) &&;
|
||||
|
||||
(3) template <class F> constexpr auto map_error(F &&f) const &;</code></pre>
|
||||
|
||||
Carries out some operation on the stored unexpected object if there is one.
|
||||
|
||||
*Returns*: Let `U` be the result of `std::invoke(std::forward<F>(f), value())`. Returns a `std::expected<T,U>`. If `*this` has an expected value, the result is `*this`, otherwise an `expected<T,U>` is constructed from `make_unexpected(std::invoke(std::forward<F>(f), value()))` and is returned.
|
||||
|
||||
### Function template `tl::expected::expected`<a id="tl::expected-T,E-::expected(constunexpected-G-&)"></a>
|
||||
|
||||
<pre><code class="language-cpp">(1) EXPLICIT constexpr expected(const unexpected<G> &e);
|
||||
|
||||
(2) EXPLICIT constexpr expected(unexpected<G> &&e);</code></pre>
|
||||
|
||||
-----
|
||||
|
||||
-----
|
132
expected.hpp
132
expected.hpp
@@ -139,8 +139,8 @@ public:
|
||||
constexpr E &value() & { return m_val; }
|
||||
/// \group unexpected_value
|
||||
constexpr E &&value() && { return std::move(m_val); }
|
||||
/// \group unexpected_value
|
||||
constexpr E const &&value() const && { return std::move(m_val); }
|
||||
/// \exclude
|
||||
constexpr const E &&value() const && { return std::move(m_val); }
|
||||
|
||||
private:
|
||||
E m_val;
|
||||
@@ -374,7 +374,8 @@ template <class T, class E> struct expected_storage_base<T, E, false, true> {
|
||||
|
||||
// expected_copy_move_base is used to conditionally delete the move/copy
|
||||
// constructors/assignment operators depending on the traits of T and E.
|
||||
// TODO these could be reduced a bit by splitting construction and assignment into different bases
|
||||
// TODO these could be reduced a bit by splitting construction and assignment
|
||||
// into different bases
|
||||
template <
|
||||
class T, class E,
|
||||
bool EnableCopy = (std::is_copy_constructible<T>::value &&
|
||||
@@ -869,8 +870,7 @@ public:
|
||||
"F must return an expected");
|
||||
|
||||
return has_value() ? detail::invoke(std::forward<F>(f), std::move(**this))
|
||||
: result(unexpect, std::
|
||||
: move(this->error()));
|
||||
: result(unexpect, std::move(this->error()));
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -937,32 +937,44 @@ public:
|
||||
!defined(TL_EXPECTED_GCC54)
|
||||
/// \brief Carries out some operation on the stored object if there is one.
|
||||
/// \returns Let `U` be the result of `std::invoke(std::forward<F>(f),
|
||||
/// value())`. Returns a `std::expected<U>`. The return value is empty if
|
||||
/// `*this` is empty, otherwise an `expected<U>` is constructed from the
|
||||
/// value())`. Returns a `std::expected<U,E>`. If `*this` is unexpected, the
|
||||
/// result is `*this`, otherwise an `expected<U,E>` is constructed from the
|
||||
/// return value of `std::invoke(std::forward<F>(f), value())` and is
|
||||
/// returned. \group map \synopsis template <class F> auto map(F &&f) &;
|
||||
/// returned.
|
||||
///
|
||||
/// \group map
|
||||
/// \synopsis template <class F> constexpr auto map(F &&f) &;
|
||||
template <class F> TL_EXPECTED_11_CONSTEXPR auto map(F &&f) & {
|
||||
return map_impl(*this, std::forward<F>(f));
|
||||
}
|
||||
|
||||
/// \group map
|
||||
/// \synopsis template <class F> constexpr auto map(F &&f) &&;
|
||||
template <class F> TL_EXPECTED_11_CONSTEXPR auto map(F &&f) && {
|
||||
return map_impl(std::move(*this), std::forward<F>(f));
|
||||
}
|
||||
|
||||
/// \group map
|
||||
/// \synopsis template <class F> constexpr auto map(F &&f) const &;
|
||||
template <class F> constexpr auto map(F &&f) const & {
|
||||
return map_impl(*this, std::forward<F>(f));
|
||||
}
|
||||
|
||||
/// \group map
|
||||
/// \synopsis template <class F> constexpr auto map(F &&f) const &&;
|
||||
template <class F> constexpr auto map(F &&f) const && {
|
||||
return map_impl(std::move(*this), std::forward<F>(f));
|
||||
}
|
||||
#else
|
||||
/// \brief Carries out some operation on the stored object if there is one.
|
||||
/// \returns Let `U` be the result of `std::invoke(std::forward<F>(f),
|
||||
/// value())`. Returns a `std::expected<U>`. The return value is empty if
|
||||
/// `*this` is empty, otherwise an `expected<U>` is constructed from the
|
||||
/// value())`. Returns a `std::expected<U,E>`. If `*this` is unexpected, the
|
||||
/// result is `*this`, otherwise an `expected<U,E>` is constructed from the
|
||||
/// return value of `std::invoke(std::forward<F>(f), value())` and is
|
||||
/// returned. \group map \synopsis template <class F> auto map(F &&f) &;
|
||||
/// returned.
|
||||
///
|
||||
/// \group map
|
||||
/// \synopsis template <class F> constexpr auto map(F &&f) &;
|
||||
template <class F>
|
||||
TL_EXPECTED_11_CONSTEXPR decltype(map_impl(std::declval<expected &>(),
|
||||
std::declval<F &&>()))
|
||||
@@ -970,13 +982,17 @@ public:
|
||||
return map_impl(*this, std::forward<F>(f));
|
||||
}
|
||||
|
||||
/// \group map
|
||||
/// \synopsis template <class F> constexpr auto map(F &&f) &&;
|
||||
template <class F>
|
||||
TL_EXPECTED_11_CONSTEXPR decltype(map_impl(std::declval<expected &&>(),
|
||||
TL_EXPECTED_11_CONSTEXPR decltype(map_impl(std::declval<expected &>(),
|
||||
std::declval<F &&>()))
|
||||
map(F &&f) && {
|
||||
return map_impl(std::move(*this), std::forward<F>(f));
|
||||
}
|
||||
|
||||
/// \group map
|
||||
/// \synopsis template <class F> constexpr auto map(F &&f) const &;
|
||||
template <class F>
|
||||
constexpr decltype(map_impl(std::declval<const expected &>(),
|
||||
std::declval<F &&>()))
|
||||
@@ -985,6 +1001,8 @@ public:
|
||||
}
|
||||
|
||||
#ifndef TL_EXPECTED_NO_CONSTRR
|
||||
/// \group map
|
||||
/// \synopsis template <class F> constexpr auto map(F &&f) const &&;
|
||||
template <class F>
|
||||
constexpr decltype(map_impl(std::declval<const expected &&>(),
|
||||
std::declval<F &&>()))
|
||||
@@ -996,36 +1014,48 @@ public:
|
||||
|
||||
#if defined(TL_EXPECTED_CXX14) && !defined(TL_EXPECTED_GCC49) && \
|
||||
!defined(TL_EXPECTED_GCC54)
|
||||
/// \brief Carries out some operation on the stored object if there is one.
|
||||
/// \brief Carries out some operation on the stored unexpected object if there
|
||||
/// is one.
|
||||
/// \returns Let `U` be the result of `std::invoke(std::forward<F>(f),
|
||||
/// value())`. Returns a `std::expected<U>`. The return value is empty if
|
||||
/// `*this` is empty, otherwise an `expected<U>` is constructed from the
|
||||
/// return value of `std::invoke(std::forward<F>(f), value())` and is
|
||||
/// returned. \group map_error \synopsis template <class F> auto map_error(F
|
||||
/// &&f) &;
|
||||
/// value())`. Returns a `std::expected<T,U>`. If `*this` has an expected
|
||||
/// value, the result is `*this`, otherwise an `expected<T,U>` is constructed
|
||||
/// from `make_unexpected(std::invoke(std::forward<F>(f), value()))` and is
|
||||
/// returned.
|
||||
///
|
||||
/// \group map_error
|
||||
/// \synopsis template <class F> constexpr auto map_error(F &&f) &;
|
||||
template <class F> TL_EXPECTED_11_CONSTEXPR auto map_error(F &&f) & {
|
||||
return map_error_impl(*this, std::forward<F>(f));
|
||||
}
|
||||
|
||||
/// \group map_error
|
||||
/// \synopsis template <class F> constexpr auto map_error(F &&f) &&;
|
||||
template <class F> TL_EXPECTED_11_CONSTEXPR auto map_error(F &&f) && {
|
||||
return map_error_impl(std::move(*this), std::forward<F>(f));
|
||||
}
|
||||
|
||||
/// \group map_error
|
||||
/// \synopsis template <class F> constexpr auto map_error(F &&f) const &;
|
||||
template <class F> constexpr auto map_error(F &&f) const & {
|
||||
return map_error_impl(*this, std::forward<F>(f));
|
||||
}
|
||||
|
||||
/// \group map_error
|
||||
/// \synopsis template <class F> constexpr auto map_error(F &&f) const &&;
|
||||
template <class F> constexpr auto map_error(F &&f) const && {
|
||||
return map_error_impl(std::move(*this), std::forward<F>(f));
|
||||
}
|
||||
#else
|
||||
/// \brief Carries out some operation on the stored object if there is one.
|
||||
/// \brief Carries out some operation on the stored unexpected object if there
|
||||
/// is one.
|
||||
/// \returns Let `U` be the result of `std::invoke(std::forward<F>(f),
|
||||
/// value())`. Returns a `std::expected<U>`. The return value is empty if
|
||||
/// `*this` is empty, otherwise an `expected<U>` is constructed from the
|
||||
/// return value of `std::invoke(std::forward<F>(f), value())` and is
|
||||
/// returned. \group map_error \synopsis template <class F> auto map_error(F
|
||||
/// &&f) &;
|
||||
/// value())`. Returns a `std::expected<T,U>`. If `*this` has an expected
|
||||
/// value, the result is `*this`, otherwise an `expected<T,U>` is constructed
|
||||
/// from `make_unexpected(std::invoke(std::forward<F>(f), value()))` and is
|
||||
/// returned.
|
||||
///
|
||||
/// \group map_error
|
||||
/// \synopsis template <class F> constexpr auto map_error(F &&f) &;
|
||||
template <class F>
|
||||
TL_EXPECTED_11_CONSTEXPR decltype(map_error_impl(std::declval<expected &>(),
|
||||
std::declval<F &&>()))
|
||||
@@ -1033,6 +1063,8 @@ public:
|
||||
return map_error_impl(*this, std::forward<F>(f));
|
||||
}
|
||||
|
||||
/// \group map_error
|
||||
/// \synopsis template <class F> constexpr auto map_error(F &&f) &&;
|
||||
template <class F>
|
||||
TL_EXPECTED_11_CONSTEXPR decltype(map_error_impl(std::declval<expected &&>(),
|
||||
std::declval<F &&>()))
|
||||
@@ -1040,6 +1072,8 @@ public:
|
||||
return map_error_impl(std::move(*this), std::forward<F>(f));
|
||||
}
|
||||
|
||||
/// \group map_error
|
||||
/// \synopsis template <class F> constexpr auto map_error(F &&f) const &;
|
||||
template <class F>
|
||||
constexpr decltype(map_error_impl(std::declval<const expected &>(),
|
||||
std::declval<F &&>()))
|
||||
@@ -1048,6 +1082,8 @@ public:
|
||||
}
|
||||
|
||||
#ifndef TL_EXPECTED_NO_CONSTRR
|
||||
/// \group map_error
|
||||
/// \synopsis template <class F> constexpr auto map_error(F &&f) const &&;
|
||||
template <class F>
|
||||
constexpr decltype(map_error_impl(std::declval<const expected &&>(),
|
||||
std::declval<F &&>()))
|
||||
@@ -1077,15 +1113,18 @@ public:
|
||||
: impl_base(in_place, il, std::forward<Args>(args)...),
|
||||
ctor_base(detail::default_constructor_tag{}) {}
|
||||
|
||||
/// \group unexpected_ctor
|
||||
/// \synopsis EXPLICIT constexpr expected(const unexpected<G> &e);
|
||||
template <class G = E,
|
||||
detail::enable_if_t<std::is_constructible<E, const G &>::value> * =
|
||||
nullptr,
|
||||
detail::enable_if_t<!std::is_convertible<const G &, E>::value> * =
|
||||
nullptr>
|
||||
explicit constexpr expected(unexpected<G> const &e)
|
||||
explicit constexpr expected(const unexpected<G> &e)
|
||||
: impl_base(unexpect, e.value()),
|
||||
ctor_base(detail::default_constructor_tag{}) {}
|
||||
|
||||
/// \exclude
|
||||
template <
|
||||
class G = E,
|
||||
detail::enable_if_t<std::is_constructible<E, const G &>::value> * =
|
||||
@@ -1095,6 +1134,8 @@ public:
|
||||
: impl_base(unexpect, e.value()),
|
||||
ctor_base(detail::default_constructor_tag{}) {}
|
||||
|
||||
/// \group unexpected_ctor
|
||||
/// \synopsis EXPLICIT constexpr expected(unexpected<G> &&e);
|
||||
template <
|
||||
class G = E,
|
||||
detail::enable_if_t<std::is_constructible<E, G &&>::value> * = nullptr,
|
||||
@@ -1104,6 +1145,7 @@ public:
|
||||
: impl_base(unexpect, std::move(e.value())),
|
||||
ctor_base(detail::default_constructor_tag{}) {}
|
||||
|
||||
/// \exclude
|
||||
template <
|
||||
class G = E,
|
||||
detail::enable_if_t<std::is_constructible<E, G &&>::value> * = nullptr,
|
||||
@@ -1120,6 +1162,7 @@ public:
|
||||
: impl_base(unexpect, std::forward<Args>(args)...),
|
||||
ctor_base(detail::default_constructor_tag{}) {}
|
||||
|
||||
/// \exclude
|
||||
template <class U, class... Args,
|
||||
detail::enable_if_t<std::is_constructible<
|
||||
E, std::initializer_list<U> &, Args &&...>::value> * = nullptr>
|
||||
@@ -1130,8 +1173,8 @@ public:
|
||||
|
||||
// TODO SFINAE
|
||||
template <class U, class G,
|
||||
detail::enable_if_t<(!std::is_convertible<U const &, T>::value ||
|
||||
!std::is_convertible<G const &, E>::value)> * =
|
||||
detail::enable_if_t<!(std::is_convertible<U const &, T>::value &&
|
||||
std::is_convertible<G const &, E>::value)> * =
|
||||
nullptr>
|
||||
explicit constexpr expected(const expected<U, G> &rhs)
|
||||
: ctor_base(detail::default_constructor_tag{}) {
|
||||
@@ -1143,11 +1186,12 @@ public:
|
||||
}
|
||||
|
||||
// TODO SFINAE
|
||||
template <
|
||||
class U, class G,
|
||||
detail::enable_if_t<(!std::is_convertible<U &&, T>::value ||
|
||||
!std::is_convertible<G &&, E>::value)> * = nullptr>
|
||||
explicit constexpr expected(const expected<U, G> &rhs)
|
||||
/// \exclude
|
||||
template <class U, class G,
|
||||
detail::enable_if_t<(std::is_convertible<U const &, T>::value &&
|
||||
std::is_convertible<G const &, E>::value)> * =
|
||||
nullptr>
|
||||
constexpr expected(const expected<U, G> &rhs)
|
||||
: ctor_base(detail::default_constructor_tag{}) {
|
||||
if (rhs.has_value()) {
|
||||
::new (valptr()) T(*rhs);
|
||||
@@ -1159,7 +1203,22 @@ public:
|
||||
// TODO SFINAE
|
||||
template <
|
||||
class U, class G,
|
||||
detail::enable_if_t<(std::is_convertible<U &&, T>::value ||
|
||||
detail::enable_if_t<!(std::is_convertible<U &&, T>::value &&
|
||||
std::is_convertible<G &&, E>::value)> * = nullptr>
|
||||
explicit constexpr expected(expected<U, G> &&rhs)
|
||||
: ctor_base(detail::default_constructor_tag{}) {
|
||||
if (rhs.has_value()) {
|
||||
::new (valptr()) T(std::move(*rhs));
|
||||
} else {
|
||||
::new (errptr()) unexpected_type(unexpected<E>(std::move(rhs.error())));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO SFINAE
|
||||
/// \exclude
|
||||
template <
|
||||
class U, class G,
|
||||
detail::enable_if_t<(std::is_convertible<U &&, T>::value &&
|
||||
std::is_convertible<G &&, E>::value)> * = nullptr>
|
||||
constexpr expected(expected<U, G> &&rhs)
|
||||
: ctor_base(detail::default_constructor_tag{}) {
|
||||
@@ -1176,6 +1235,7 @@ public:
|
||||
explicit constexpr expected(U &&v) : expected(in_place, std::forward<U>(v)) {}
|
||||
|
||||
// TODO SFINAE
|
||||
/// \exclude
|
||||
template <class U = T, detail::enable_if_t<
|
||||
std::is_convertible<U &&, T>::value> * = nullptr>
|
||||
constexpr expected(U &&v) : expected(in_place, std::forward<U>(v)) {}
|
||||
@@ -1203,6 +1263,7 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// \exclude
|
||||
template <
|
||||
class U = T,
|
||||
detail::enable_if_t<
|
||||
@@ -1274,6 +1335,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/// \exclude
|
||||
template <class... Args, detail::enable_if_t<!std::is_nothrow_constructible<
|
||||
T, Args &&...>::value> * = nullptr>
|
||||
void emplace(Args &&... args) {
|
||||
@@ -1307,6 +1369,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/// \exclude
|
||||
template <class U, class... Args,
|
||||
detail::enable_if_t<!std::is_nothrow_constructible<
|
||||
T, std::initializer_list<U> &, Args &&...>::value> * = nullptr>
|
||||
@@ -1397,10 +1460,9 @@ public:
|
||||
"T must be move-constructible and convertible to from U&&");
|
||||
return bool(*this) ? std::move(**this) : static_cast<T>(std::forward<U>(v));
|
||||
}
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
/// \exclude
|
||||
namespace detail {
|
||||
template <class Exp> using err_t = typename detail::decay_t<Exp>::error_type;
|
||||
template <class Exp, class Ret> using ret_t = expected<Ret, err_t<Exp>>;
|
||||
|
Reference in New Issue
Block a user