forked from TartanLlama/expected
Docs
This commit is contained in:
116
docs/index.md
116
docs/index.md
@@ -336,43 +336,31 @@ public:
|
||||
|
||||
void <a href='doc_expected.html#tl::expected-T,E-'>swap</a>(<a href='doc_expected.html#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.html#tl::expected-T,E-'>operator-></a>() const;
|
||||
constexpr const T* <a href='doc_expected.html#tl::expected-T,E-::operator--()const'>operator-></a>() const;
|
||||
T* <a href='doc_expected.html#tl::expected-T,E-::operator--()const'>operator-></a>();
|
||||
|
||||
T* <a href='doc_expected.html#tl::expected-T,E-'>operator-></a>();
|
||||
constexpr const T& <a href='doc_expected.html#tl::expected-T,E-::operator*()const&'>operator*</a>() const &;
|
||||
T& <a href='doc_expected.html#tl::expected-T,E-::operator*()const&'>operator*</a>() &;
|
||||
constexpr const T&& <a href='doc_expected.html#tl::expected-T,E-::operator*()const&'>operator*</a>() const &&;
|
||||
T&& <a href='doc_expected.html#tl::expected-T,E-::operator*()const&'>operator*</a>() &&;
|
||||
|
||||
constexpr const T& <a href='doc_expected.html#tl::expected-T,E-'>operator*</a>() const &;
|
||||
constexpr bool <a href='doc_expected.html#tl::expected-T,E-::has_value()const'>has_value</a>() const noexcept;
|
||||
constexpr <a href='doc_expected.html#tl::expected-T,E-::has_value()const'>operator bool</a>() const noexcept;
|
||||
|
||||
T& <a href='doc_expected.html#tl::expected-T,E-'>operator*</a>() &;
|
||||
constexpr const T& <a href='doc_expected.html#tl::expected-T,E-::value()const&'>value</a>() const &;
|
||||
T& <a href='doc_expected.html#tl::expected-T,E-::value()const&'>value</a>() &;
|
||||
constexpr const T&& <a href='doc_expected.html#tl::expected-T,E-::value()const&'>value</a>() const &&;
|
||||
T&& <a href='doc_expected.html#tl::expected-T,E-::value()const&'>value</a>() &&;
|
||||
|
||||
constexpr const T&& <a href='doc_expected.html#tl::expected-T,E-'>operator*</a>() const &&;
|
||||
|
||||
T&& <a href='doc_expected.html#tl::expected-T,E-'>operator*</a>() &&;
|
||||
|
||||
constexpr <a href='doc_expected.html#tl::expected-T,E-'>operator bool</a>() const noexcept;
|
||||
|
||||
constexpr bool <a href='doc_expected.html#tl::expected-T,E-'>has_value</a>() const noexcept;
|
||||
|
||||
constexpr const T& <a href='doc_expected.html#tl::expected-T,E-'>value</a>() const &;
|
||||
|
||||
T& <a href='doc_expected.html#tl::expected-T,E-'>value</a>() &;
|
||||
|
||||
constexpr const T&& <a href='doc_expected.html#tl::expected-T,E-'>value</a>() const &&;
|
||||
|
||||
T&& <a href='doc_expected.html#tl::expected-T,E-'>value</a>() &&;
|
||||
|
||||
constexpr const E& <a href='doc_expected.html#tl::expected-T,E-'>error</a>() const &;
|
||||
|
||||
E& <a href='doc_expected.html#tl::expected-T,E-'>error</a>() &;
|
||||
|
||||
constexpr const E&& <a href='doc_expected.html#tl::expected-T,E-'>error</a>() const &&;
|
||||
|
||||
E&& <a href='doc_expected.html#tl::expected-T,E-'>error</a>() &&;
|
||||
constexpr const E& <a href='doc_expected.html#tl::expected-T,E-::error()const&'>error</a>() const &;
|
||||
E& <a href='doc_expected.html#tl::expected-T,E-::error()const&'>error</a>() &;
|
||||
constexpr const E&& <a href='doc_expected.html#tl::expected-T,E-::error()const&'>error</a>() const &&;
|
||||
E&& <a href='doc_expected.html#tl::expected-T,E-::error()const&'>error</a>() &&;
|
||||
|
||||
template <class U>
|
||||
constexpr T <a href='doc_expected.html#tl::expected-T,E-'>value_or</a>(U&& v) const &;
|
||||
|
||||
constexpr T <a href='doc_expected.html#tl::expected-T,E-::value_or(U&&)const&'>value_or</a>(U&& v) const &;
|
||||
template <class U>
|
||||
T <a href='doc_expected.html#tl::expected-T,E-'>value_or</a>(U&& v) &&;
|
||||
T <a href='doc_expected.html#tl::expected-T,E-::value_or(U&&)const&'>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.
|
||||
@@ -438,6 +426,74 @@ Calls `f` if the expectd is in the unexpected state
|
||||
|
||||
(2) EXPLICIT constexpr expected(unexpected<G> &&e);</code></pre>
|
||||
|
||||
### Operator `tl::expected::operator->`<a id="tl::expected-T,E-::operator--()const"></a>
|
||||
|
||||
<pre><code class="language-cpp">(1) constexpr const T* operator->() const;
|
||||
|
||||
(2) T* operator->();</code></pre>
|
||||
|
||||
*Returns*: a pointer to the stored value
|
||||
|
||||
*Requires*: a value is stored
|
||||
|
||||
### Operator `tl::expected::operator*`<a id="tl::expected-T,E-::operator*()const&"></a>
|
||||
|
||||
<pre><code class="language-cpp">(1) constexpr const T& operator*() const &;
|
||||
|
||||
(2) T& operator*() &;
|
||||
|
||||
(3) constexpr const T&& operator*() const &&;
|
||||
|
||||
(4) T&& operator*() &&;</code></pre>
|
||||
|
||||
*Returns*: the stored value
|
||||
|
||||
*Requires*: a value is stored
|
||||
|
||||
### Function `tl::expected::has_value`<a id="tl::expected-T,E-::has_value()const"></a>
|
||||
|
||||
<pre><code class="language-cpp">(1) constexpr bool has_value() const noexcept;
|
||||
|
||||
(2) constexpr operator bool() const noexcept;</code></pre>
|
||||
|
||||
*Returns*: whether or not the optional has a value
|
||||
|
||||
### Function `tl::expected::value`<a id="tl::expected-T,E-::value()const&"></a>
|
||||
|
||||
<pre><code class="language-cpp">(1) constexpr const T& value() const &;
|
||||
|
||||
(2) T& value() &;
|
||||
|
||||
(3) constexpr const T&& value() const &&;
|
||||
|
||||
(4) T&& value() &&;</code></pre>
|
||||
|
||||
*Returns*: the contained value if there is one, otherwise throws \[bad\_expected\_access\]
|
||||
|
||||
### Function `tl::expected::error`<a id="tl::expected-T,E-::error()const&"></a>
|
||||
|
||||
<pre><code class="language-cpp">(1) constexpr const E& error() const &;
|
||||
|
||||
(2) E& error() &;
|
||||
|
||||
(3) constexpr const E&& error() const &&;
|
||||
|
||||
(4) E&& error() &&;</code></pre>
|
||||
|
||||
*Returns*: the unexpected value
|
||||
|
||||
*Requires*: there is an unexpected value
|
||||
|
||||
### Function template `tl::expected::value_or`<a id="tl::expected-T,E-::value_or(U&&)const&"></a>
|
||||
|
||||
<pre><code class="language-cpp">(1) template <class U>
|
||||
constexpr T value_or(U&& v) const &;
|
||||
|
||||
(2) template <class U>
|
||||
T value_or(U&& v) &&;</code></pre>
|
||||
|
||||
*Returns*: the stored value if there is one, otherwise returns `u`
|
||||
|
||||
-----
|
||||
|
||||
-----
|
||||
|
35
expected.hpp
35
expected.hpp
@@ -1541,44 +1541,77 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/// \returns a pointer to the stored value
|
||||
/// \requires a value is stored
|
||||
/// \group pointer
|
||||
constexpr const T *operator->() const { return valptr(); }
|
||||
/// \group pointer
|
||||
TL_EXPECTED_11_CONSTEXPR T *operator->() { return valptr(); }
|
||||
|
||||
/// \returns the stored value
|
||||
/// \requires a value is stored
|
||||
/// \group deref
|
||||
constexpr const T &operator*() const & { return val(); }
|
||||
/// \group deref
|
||||
TL_EXPECTED_11_CONSTEXPR T &operator*() & { return val(); }
|
||||
/// \group deref
|
||||
constexpr const T &&operator*() const && { return std::move(val()); }
|
||||
/// \group deref
|
||||
TL_EXPECTED_11_CONSTEXPR T &&operator*() && { return std::move(val()); }
|
||||
constexpr explicit operator bool() const noexcept { return this->m_has_val; }
|
||||
|
||||
/// \returns whether or not the optional has a value
|
||||
/// \group has_value
|
||||
constexpr bool has_value() const noexcept { return this->m_has_val; }
|
||||
/// \group has_value
|
||||
constexpr explicit operator bool() const noexcept { return this->m_has_val; }
|
||||
|
||||
|
||||
/// \returns the contained value if there is one, otherwise throws [bad_expected_access]
|
||||
/// \group value
|
||||
constexpr const T &value() const & {
|
||||
if (!has_value())
|
||||
throw bad_expected_access<E>(err().value());
|
||||
return val();
|
||||
}
|
||||
/// \group value
|
||||
TL_EXPECTED_11_CONSTEXPR T &value() & {
|
||||
if (!has_value())
|
||||
throw bad_expected_access<E>(err().value());
|
||||
return val();
|
||||
}
|
||||
/// \group value
|
||||
constexpr const T &&value() const && {
|
||||
if (!has_value())
|
||||
throw bad_expected_access<E>(err().value());
|
||||
return std::move(val());
|
||||
}
|
||||
/// \group value
|
||||
TL_EXPECTED_11_CONSTEXPR T &&value() && {
|
||||
if (!has_value())
|
||||
throw bad_expected_access<E>(err().value());
|
||||
return std::move(val());
|
||||
}
|
||||
|
||||
/// \returns the unexpected value
|
||||
/// \requires there is an unexpected value
|
||||
/// \group error
|
||||
constexpr const E &error() const & { return err().value(); }
|
||||
/// \group error
|
||||
TL_EXPECTED_11_CONSTEXPR E &error() & { return err().value(); }
|
||||
/// \group error
|
||||
constexpr const E &&error() const && { return std::move(err().value()); }
|
||||
/// \group error
|
||||
TL_EXPECTED_11_CONSTEXPR E &&error() && { return std::move(err().value()); }
|
||||
|
||||
/// \returns the stored value if there is one, otherwise returns `u`
|
||||
/// \group value_or
|
||||
template <class U> constexpr T value_or(U &&v) const & {
|
||||
static_assert(std::is_copy_constructible<T>::value &&
|
||||
std::is_convertible<U &&, T>::value,
|
||||
"T must be copy-constructible and convertible to from U&&");
|
||||
return bool(*this) ? **this : static_cast<T>(std::forward<U>(v));
|
||||
}
|
||||
/// \group value_or
|
||||
template <class U> TL_EXPECTED_11_CONSTEXPR T value_or(U &&v) && {
|
||||
static_assert(std::is_move_constructible<T>::value &&
|
||||
std::is_convertible<U &&, T>::value,
|
||||
|
Reference in New Issue
Block a user