3#ifndef TETL_EXPECTED_EXPECTED_HPP
4#define TETL_EXPECTED_EXPECTED_HPP
26template <
typename T,
typename E>
41 template <
typename... Args>
44 : _u(in_place_index<0>,
etl::
forward<Args>(args)...)
48 template <
typename... Args>
51 : _u(in_place_index<1>,
etl::
forward<Args>(args)...)
55 [[nodiscard]]
constexpr explicit operator bool() const noexcept {
return has_value(); }
57 [[nodiscard]]
constexpr auto has_value() const noexcept ->
bool {
return _u.index() == 0; }
63 [[nodiscard]]
constexpr auto operator*() const& noexcept -> T const&
69 [[nodiscard]]
constexpr auto operator*() &
noexcept -> T&
75 [[nodiscard]]
constexpr auto operator*() const&& noexcept -> T const&&
81 [[nodiscard]]
constexpr auto operator*() &&
noexcept -> T&&
87 [[nodiscard]]
constexpr auto error() & -> E&
93 [[nodiscard]]
constexpr auto error() const& -> E const&
99 [[nodiscard]]
constexpr auto error() && -> E&&
105 [[nodiscard]]
constexpr auto error() const&& -> E const&&
111 template <
typename... Args>
113 constexpr auto emplace(Args&&... args)
noexcept -> T&
119 template <
typename U>
120 [[nodiscard]]
constexpr auto value_or(U&& fallback)
const& -> T
122 return static_cast<bool>(*this) ? **this :
static_cast<T
>(
etl::forward<U>(fallback));
125 template <
typename U>
126 [[nodiscard]]
constexpr auto value_or(U&& fallback) && -> T
131 template <
typename F>
136 return U(unexpect,
error());
139 template <
typename F>
144 return U(unexpect,
error());
147 template <
typename F>
148 [[nodiscard]]
constexpr auto and_then(F&& f)
const&
158 template <
typename F>
159 [[nodiscard]]
constexpr auto and_then(F&& f)
const&&
169 template <
typename F>
173 if (
has_value()) {
return G(etl::in_place, **
this); }
177 template <
typename F>
181 if (
has_value()) {
return G(etl::in_place, **
this); }
185 template <
typename F>
186 [[nodiscard]]
constexpr auto or_else(F&& f)
const&
191 return G(etl::in_place,
etl::move(**
this));
196 template <
typename F>
197 [[nodiscard]]
constexpr auto or_else(F&& f)
const&&
202 return G(etl::in_place,
etl::move(**
this));
#define TETL_PRECONDITION(...)
Definition check.hpp:16
constexpr auto move(InputIt first, InputIt last, OutputIt destination) -> OutputIt
Moves the elements in the range [first, last), to another range beginning at destination,...
Definition move.hpp:26
Definition adjacent_find.hpp:8
constexpr bool is_constructible_v
Definition is_constructible.hpp:24
remove_cv_t< remove_reference_t< T > > remove_cvref_t
Definition remove_cvref.hpp:23
constexpr bool is_nothrow_default_constructible_v
Definition is_nothrow_default_constructible.hpp:26
constexpr auto index_v
Definition index_constant.hpp:15
constexpr bool is_default_constructible_v
Definition is_default_constructible.hpp:26
constexpr auto invoke(F &&f, Args &&... args) -> invoke_result_t< F, Args... >
Definition invoke.hpp:45
constexpr bool is_nothrow_constructible_v
Definition is_nothrow_constructible.hpp:50
constexpr auto get_if(variant< Types... > *pv) noexcept -> add_pointer_t< T >
constexpr auto forward(remove_reference_t< T > ¶m) noexcept -> T &&
Forwards lvalues as either lvalues or as rvalues, depending on T. When t is a forwarding reference (a...
Definition forward.hpp:18
Definition expected.hpp:27
constexpr auto operator*() &noexcept -> T &
Definition expected.hpp:69
constexpr auto and_then(F &&f) &
Definition expected.hpp:132
constexpr auto or_else(F &&f) const &&
Definition expected.hpp:197
constexpr expected() noexcept(is_nothrow_default_constructible_v< T >)
Definition expected.hpp:35
etl::unexpected< E > unexpected_type
Definition expected.hpp:30
constexpr auto emplace(Args &&... args) noexcept -> T &
Definition expected.hpp:113
E error_type
Definition expected.hpp:29
constexpr auto operator->() const noexcept -> T const *
Definition expected.hpp:59
constexpr auto error() &&-> E &&
Definition expected.hpp:99
constexpr auto operator*() &&noexcept -> T &&
Definition expected.hpp:81
constexpr auto error() &-> E &
Definition expected.hpp:87
constexpr auto and_then(F &&f) &&
Definition expected.hpp:140
constexpr expected(unexpect_t, Args &&... args) noexcept(is_nothrow_constructible_v< E, Args... >)
Definition expected.hpp:50
constexpr auto and_then(F &&f) const &
Definition expected.hpp:148
constexpr auto or_else(F &&f) &&
Definition expected.hpp:178
constexpr auto value_or(U &&fallback) &&-> T
Definition expected.hpp:126
constexpr expected(in_place_t, Args &&... args) noexcept(is_nothrow_constructible_v< T, Args... >)
Definition expected.hpp:43
constexpr auto error() const &&-> E const &&
Definition expected.hpp:105
constexpr auto or_else(F &&f) const &
Definition expected.hpp:186
constexpr auto operator->() noexcept -> T *
Definition expected.hpp:61
constexpr auto error() const &-> E const &
Definition expected.hpp:93
constexpr auto operator*() const &noexcept -> T const &
Definition expected.hpp:63
constexpr auto operator*() const &&noexcept -> T const &&
Definition expected.hpp:75
constexpr auto has_value() const noexcept -> bool
Definition expected.hpp:57
constexpr auto or_else(F &&f) &
Definition expected.hpp:170
constexpr auto and_then(F &&f) const &&
Definition expected.hpp:159
etl::expected< U, error_type > rebind
Definition expected.hpp:33
T value_type
Definition expected.hpp:28
constexpr auto value_or(U &&fallback) const &-> T
Definition expected.hpp:120
Disambiguation tags that can be passed to the constructors of optional, variant, and any to indicate ...
Definition in_place.hpp:20
Definition unexpect.hpp:9
Definition unexpected.hpp:20
Definition variant.hpp:98