31#ifndef ETL_EXPECTED_INCLUDED
32#define ETL_EXPECTED_INCLUDED
60 template <
typename TError>
76 template <
typename TError>
91 template <
typename TError>
102 : error_value(
other.error_value)
111 : error_value(
etl::move(
other.error_value))
136 template <
typename... Args >
138 : error_value(
etl::forward<Args>(args)...)
143#if ETL_HAS_INITIALIZER_LIST
147 template <
typename U,
typename... Args>
149 : error_value(init,
etl::forward<Args>(args)...)
162 error_value =
rhs.error_value;
175 error_value = etl::move(
rhs.error_value);
184 ETL_CONSTEXPR14 TError&
error()& ETL_NOEXCEPT
192 ETL_CONSTEXPR14
const TError&
error() const& ETL_NOEXCEPT
200 ETL_CONSTEXPR14 TError&&
error()&& ETL_NOEXCEPT
202 return etl::move(error_value);
208 ETL_CONSTEXPR14 TError&&
error() const&& ETL_NOEXCEPT
210 return etl::move(error_value);
227 using ETL_OR_STD::swap;
250 static const unexpect_t unexpect;
256 template <
typename TValue,
typename TError>
267 template <
typename U>
301 : storage(
other.storage)
310 : storage(etl::move(
other.storage))
319 template <typename G, typename etl::enable_if<!etl::is_convertible<const G&, TError>::value,
bool>::type =
false>
321 : storage(
etl::in_place_index_t<Error_Type>(), ue.error())
325 template <typename G, typename etl::enable_if<etl::is_convertible<const G&, TError>::value,
bool>::type =
false>
327 : storage(
etl::in_place_index_t<Error_Type>(), ue.error())
331 template <
typename G>
333 : storage(
etl::in_place_index_t<Error_Type>(), ue.error())
342 template <typename G, typename etl::enable_if<!etl::is_convertible<const G&, TError>::value,
bool>::type =
false>
344 : storage(
etl::in_place_index_t<Error_Type>(),
etl::move(ue.error()))
348 template <typename G, typename etl::enable_if<etl::is_convertible<const G&, TError>::value,
bool>::type =
false>
350 : storage(
etl::in_place_index_t<Error_Type>(),
etl::move(ue.error()))
367 template <
typename...
Args>
376 template <
typename U,
typename... Args>
378 : storage(il,
etl::forward<Args>(args)...)
385 template <
typename... Args>
387 : storage(error_type(
etl::forward<Args>(args)...))
391#if ETL_HAS_INITIALIZER_LIST
395 template <
typename U,
typename... Args>
397 : storage(error_type(il,
etl::forward<Args>(args)...))
406 this_type& operator =(
const this_type& other)
410 storage = other.storage;
419 this_type& operator =(this_type&& other)
423 storage = etl::move(other.storage);
447 storage = etl::move(
value);
459 storage =
ue.error();
472 storage = etl::move(
ue.error());
482 ETL_CONSTEXPR14 value_type&
value()&
490 ETL_CONSTEXPR14
const value_type&
value() const&
498 ETL_CONSTEXPR14 value_type&&
value()&&
506 ETL_CONSTEXPR14
const value_type&&
value() const&&
525 bool has_value()
const
527 return (storage.
index() == Value_Type);
535 operator bool()
const
544 template <
typename U>
548 value_or(U&& default_value)
const&
563 template <
typename U>
567 value_or(U&& default_value)&&
571 return etl::move(
value());
584 error_type& error()& ETL_NOEXCEPT
594 const error_type& error() const& ETL_NOEXCEPT
604 error_type&& error()&& ETL_NOEXCEPT
614 const error_type&& error() const&& ETL_NOEXCEPT
622 template <
typename... Args>
623 ETL_CONSTEXPR14 value_type& emplace(Args&&... args) ETL_NOEXCEPT
631 template <
typename U,
typename... Args>
632 ETL_CONSTEXPR14 value_type& emplace(std::initializer_list<U>& il, Args&&... args) ETL_NOEXCEPT
640 template <
typename U>
641 value_type value_or(
const U& default_value)
const
649 return default_value;
656 error_type& error()
const
665 value_type* operator ->()
667#if ETL_IS_DEBUG_BUILD
668 ETL_ASSERT(storage.
index() == Value_Type, ETL_ERROR(expected_invalid<TError>));
677 const value_type* operator ->()
const
679#if ETL_IS_DEBUG_BUILD
680 ETL_ASSERT(storage.
index() == Value_Type, ETL_ERROR(expected_invalid<TError>));
689 value_type& operator *() ETL_LVALUE_REF_QUALIFIER
691#if ETL_IS_DEBUG_BUILD
692 ETL_ASSERT(storage.
index() == Value_Type, ETL_ERROR(expected_invalid<TError>));
701 const value_type& operator *() const ETL_LVALUE_REF_QUALIFIER
703#if ETL_IS_DEBUG_BUILD
704 ETL_ASSERT(storage.
index() == Value_Type, ETL_ERROR(expected_invalid<TError>));
714 value_type&& operator *()&&
716#if ETL_IS_DEBUG_BUILD
717 ETL_ASSERT(storage.
index() == Value_Type, ETL_ERROR(expected_invalid<TError>));
726 const value_type&& operator *() const&&
728#if ETL_IS_DEBUG_BUILD
729 ETL_ASSERT(storage.
index() == Value_Type, ETL_ERROR(expected_invalid<TError>));
746 storage_type storage;
752 template<
typename TError>
759 typedef TError error_type;
775 : storage(
ue_.error())
785 : storage(
etl::move(
ue_.error()))
795 : storage(
other.storage)
817 storage =
other.storage;
829 storage = etl::move(
other.storage);
865 return (storage.
index() != Error_Type);
885 error_type& error()& ETL_NOEXCEPT
896 const error_type& error() const& ETL_NOEXCEPT
907 error_type&& error() && ETL_NOEXCEPT
918 const error_type&& error() const&& ETL_NOEXCEPT
948template <
typename TError>
952 return lhs.error_value == rhs.error_value;
958template <
typename TError>
Specialisation for void value type.
Definition expected.h:754
error_type & error() const
Definition expected.h:927
ETL_CONSTEXPR14 expected()
Default constructor.
Definition expected.h:766
ETL_NODISCARD ETL_CONSTEXPR14 bool has_value() const
Returns true if expected has a value.
Definition expected.h:863
ETL_CONSTEXPR14 expected(const unexpected_type &ue_)
Copy construct from unexpected.
Definition expected.h:774
ETL_CONSTEXPR14 expected(const this_type &other)
Copy construct.
Definition expected.h:794
Base exception for et::expected.
Definition expected.h:48
expected_invalid
Definition expected.h:78
Expected type.
Definition expected.h:258
ETL_CONSTEXPR14 expected() ETL_NOEXCEPT
Default constructor.
Definition expected.h:274
ETL_CONSTEXPR14 expected(const value_type &value_) ETL_NOEXCEPT
Constructor.
Definition expected.h:282
ETL_CONSTEXPR14 expected(etl::in_place_t) ETL_NOEXCEPT
Construct with default value type.
Definition expected.h:358
value_type & value() const
Get the value.
Definition expected.h:514
ETL_CONSTEXPR14 expected(const expected &other) ETL_NOEXCEPT
Copy constructor.
Definition expected.h:300
const TError & error() const
Get the error.
Definition expected.h:216
void swap(etl::unexpected< TError > &other)
Swap with another etl::unexpected.
Definition expected.h:225
ETL_CONSTEXPR unexpected(const unexpected &other)
Copy constructor.
Definition expected.h:101
ETL_CONSTEXPR unexpected(const TError &e)
Construct from an lvalue.
Definition expected.h:119
ETL_CONSTEXPR14 etl::unexpected< TError > & operator=(const etl::unexpected< TError > &rhs)
Assign from etl::unexpected.
Definition expected.h:158
ETL_CONSTEXPR14 void swap(etl::unexpected< TError > &lhs, etl::unexpected< TError > &rhs)
Swap etl::unexpected.
Definition expected.h:960
ETL_CONSTEXPR14 bool operator==(const etl::unexpected< TError > &lhs, const etl::unexpected< TError > &rhs)
Equivalence operator.
Definition expected.h:950
#define ETL_ASSERT(b, e)
Definition error_handler.h:316
Definition exception.h:47
ETL_CONSTEXPR17 T * addressof(T &t)
Definition addressof.h:51
T & emplace(const TP1 &value1)
Emplace with one constructor parameter.
Definition variant_legacy.h:527
size_t index() const
Gets the index of the type currently stored or UNSUPPORTED_TYPE_ID.
Definition variant_legacy.h:707
bitset_ext
Definition absolute.h:38
in_place disambiguation tags.
Definition utility.h:570
Definition type_traits_generator.h:2026
Definition type_traits_generator.h:2033
pair holds two objects of arbitrary type
Definition utility.h:164
unexpect_t
Definition expected.h:241