mirror of
https://github.com/TartanLlama/optional.git
synced 2025-07-30 01:47:15 +02:00
Docs
This commit is contained in:
@ -424,28 +424,24 @@ public:
|
||||
<a href='doc_optional.md#tl::optional-T-'>optional<T></a> <a href='doc_optional.md#tl::optional-T-::or_else(F&&)&&'>or_else</a>(F&& f) const &&;
|
||||
|
||||
template <class F, class U>
|
||||
U <a href='doc_optional.md#tl::optional-T-'>map_or</a>(F&& f, U&& u) &;
|
||||
U <a href='doc_optional.md#tl::optional-T-::map_or(F&&,U&&)&'>map_or</a>(F&& f, U&& u) &;
|
||||
template <class F, class U>
|
||||
U <a href='doc_optional.md#tl::optional-T-::map_or(F&&,U&&)&'>map_or</a>(F&& f, U&& u) const &;
|
||||
|
||||
template <class F, class U>
|
||||
U <a href='doc_optional.md#tl::optional-T-'>map_or</a>(F&& f, U&& u) &&;
|
||||
U <a href='doc_optional.md#tl::optional-T-::map_or(F&&,U&&)&&'>map_or</a>(F&& f, U&& u) &&;
|
||||
template <class F, class U>
|
||||
U <a href='doc_optional.md#tl::optional-T-::map_or(F&&,U&&)&&'>map_or</a>(F&& f, U&& u) const &&;
|
||||
|
||||
template <class F, class U>
|
||||
U <a href='doc_optional.md#tl::optional-T-'>map_or</a>(F&& f, U&& u) const &;
|
||||
U <a href='doc_optional.md#tl::optional-T-::map_or_else(F&&,U&&)&'>map_or_else</a>(F&& f, U&& u) &;
|
||||
template <class F, class U>
|
||||
U <a href='doc_optional.md#tl::optional-T-::map_or_else(F&&,U&&)&'>map_or_else</a>(F&& f, U&& u) const &;
|
||||
|
||||
template <class F, class U>
|
||||
U <a href='doc_optional.md#tl::optional-T-'>map_or</a>(F&& f, U&& u) const &&;
|
||||
|
||||
U <a href='doc_optional.md#tl::optional-T-::map_or_else(F&&,U&&)&&'>map_or_else</a>(F&& f, U&& u) &&;
|
||||
template <class F, class U>
|
||||
U <a href='doc_optional.md#tl::optional-T-'>map_or_else</a>(F&& f, U&& u) &;
|
||||
|
||||
template <class F, class U>
|
||||
U <a href='doc_optional.md#tl::optional-T-'>map_or_else</a>(F&& f, U&& u) &&;
|
||||
|
||||
template <class F, class U>
|
||||
U <a href='doc_optional.md#tl::optional-T-'>map_or_else</a>(F&& f, U&& u) const &;
|
||||
|
||||
template <class F, class U>
|
||||
U <a href='doc_optional.md#tl::optional-T-'>map_or_else</a>(F&& f, U&& u) const &&;
|
||||
U <a href='doc_optional.md#tl::optional-T-::map_or_else(F&&,U&&)&&'>map_or_else</a>(F&& f, U&& u) const &&;
|
||||
};</code></pre>
|
||||
|
||||
An optional object is an object that contains the storage for another object and manages the lifetime of this contained object, if any. The contained object may be initialized after the optional object has been initialized, and may be destroyed before the optional object has been destroyed. The initialization state of the contained object is tracked by the optional object.
|
||||
@ -550,6 +546,54 @@ Calls `f` if the optional is empty
|
||||
|
||||
*Effects*: If `*this` has a value, returns `std::move(*this)`. Otherwise, if `f` returns `void`, calls `std::forward<F>(f)` and returns `std::nullopt`. Otherwise, returns `std::forward<F>(f)()`.
|
||||
|
||||
### Function template `tl::optional::map_or`<a id="tl::optional-T-::map_or(F&&,U&&)&"></a>
|
||||
|
||||
<pre><code class="language-cpp">(1) template <class F, class U>
|
||||
U map_or(F&& f, U&& u) &;
|
||||
|
||||
(2) template <class F, class U>
|
||||
U map_or(F&& f, U&& u) const &;</code></pre>
|
||||
|
||||
Maps the stored value with `f` if there is one, otherwise returns `u`
|
||||
|
||||
If there is a value stored, then `f` is called with `**this` and the value is returned. Otherwise `u` is returned.
|
||||
|
||||
### Function template `tl::optional::map_or`<a id="tl::optional-T-::map_or(F&&,U&&)&&"></a>
|
||||
|
||||
<pre><code class="language-cpp">(1) template <class F, class U>
|
||||
U map_or(F&& f, U&& u) &&;
|
||||
|
||||
(2) template <class F, class U>
|
||||
U map_or(F&& f, U&& u) const &&;</code></pre>
|
||||
|
||||
Maps the stored value with `f` if there is one, otherwise returns `u`
|
||||
|
||||
If there is a value stored, then `f` is called with `std::move(**this)` and the value is returned. Otherwise `u` is returned.
|
||||
|
||||
### Function template `tl::optional::map_or_else`<a id="tl::optional-T-::map_or_else(F&&,U&&)&"></a>
|
||||
|
||||
<pre><code class="language-cpp">(1) template <class F, class U>
|
||||
U map_or_else(F&& f, U&& u) &;
|
||||
|
||||
(2) template <class F, class U>
|
||||
U map_or_else(F&& f, U&& u) const &;</code></pre>
|
||||
|
||||
Maps the stored value with `f` if there is one, otherwise calls `u` and returns the result.
|
||||
|
||||
If there is a value stored, then `f` is called with `**this` and the value is returned. Otherwise `std::forward<U>(u)()` is returned.
|
||||
|
||||
### Function template `tl::optional::map_or_else`<a id="tl::optional-T-::map_or_else(F&&,U&&)&&"></a>
|
||||
|
||||
<pre><code class="language-cpp">(1) template <class F, class U>
|
||||
U map_or_else(F&& f, U&& u) &&;
|
||||
|
||||
(2) template <class F, class U>
|
||||
U map_or_else(F&& f, U&& u) const &&;</code></pre>
|
||||
|
||||
Maps the stored value with `f` if there is one, otherwise calls `u` and returns the result.
|
||||
|
||||
If there is a value stored, then `f` is called with `std::move(**this)` and the value is returned. Otherwise `std::forward<U>(u)()` is returned.
|
||||
|
||||
-----
|
||||
|
||||
-----
|
||||
|
21
optional.hpp
21
optional.hpp
@ -1124,41 +1124,62 @@ public:
|
||||
return has_value() ? std::move(*this) : std::forward<F>(f)();
|
||||
}
|
||||
|
||||
|
||||
/// \group map_or
|
||||
/// \brief Maps the stored value with `f` if there is one, otherwise returns `u`
|
||||
/// \details If there is a value stored, then `f` is called with `**this` and the value is returned.
|
||||
/// Otherwise `u` is returned.
|
||||
template <class F, class U> U map_or(F &&f, U &&u) & {
|
||||
return has_value() ? detail::invoke(std::forward<F>(f), **this)
|
||||
: std::forward<U>(u);
|
||||
}
|
||||
|
||||
/// \group map_or_val
|
||||
/// \brief Maps the stored value with `f` if there is one, otherwise returns `u`
|
||||
/// \details If there is a value stored, then `f` is called with `std::move(**this)` and the value is returned.
|
||||
/// Otherwise `u` is returned.
|
||||
template <class F, class U> U map_or(F &&f, U &&u) && {
|
||||
return has_value() ? detail::invoke(std::forward<F>(f), std::move(**this))
|
||||
: std::forward<U>(u);
|
||||
}
|
||||
|
||||
/// \group map_or
|
||||
template <class F, class U> U map_or(F &&f, U &&u) const & {
|
||||
return has_value() ? detail::invoke(std::forward<F>(f), **this)
|
||||
: std::forward<U>(u);
|
||||
}
|
||||
|
||||
/// \group map_or_val
|
||||
template <class F, class U> U map_or(F &&f, U &&u) const && {
|
||||
return has_value() ? detail::invoke(std::forward<F>(f), std::move(**this))
|
||||
: std::forward<U>(u);
|
||||
}
|
||||
|
||||
/// \group map_or_else
|
||||
/// \brief Maps the stored value with `f` if there is one, otherwise calls `u` and returns the result.
|
||||
/// \details If there is a value stored, then `f` is called with `**this` and the value is returned.
|
||||
/// Otherwise `std::forward<U>(u)()` is returned.
|
||||
template <class F, class U> U map_or_else(F &&f, U &&u) & {
|
||||
return has_value() ? detail::invoke(std::forward<F>(f), **this)
|
||||
: std::forward<U>(u)();
|
||||
}
|
||||
|
||||
/// \group map_or_else_rval
|
||||
/// \brief Maps the stored value with `f` if there is one, otherwise calls `u` and returns the result.
|
||||
/// \details If there is a value stored, then `f` is called with `std::move(**this)` and the value is returned.
|
||||
/// Otherwise `std::forward<U>(u)()` is returned.
|
||||
template <class F, class U> U map_or_else(F &&f, U &&u) && {
|
||||
return has_value() ? detail::invoke(std::forward<F>(f), std::move(**this))
|
||||
: std::forward<U>(u)();
|
||||
}
|
||||
|
||||
/// \group map_or_else
|
||||
template <class F, class U> U map_or_else(F &&f, U &&u) const & {
|
||||
return has_value() ? detail::invoke(std::forward<F>(f), **this)
|
||||
: std::forward<U>(u)();
|
||||
}
|
||||
|
||||
/// \group map_or_else_rval
|
||||
template <class F, class U> U map_or_else(F &&f, U &&u) const && {
|
||||
return has_value() ? detail::invoke(std::forward<F>(f), std::move(**this))
|
||||
: std::forward<U>(u)();
|
||||
|
Reference in New Issue
Block a user