31#ifndef ETL_EXPECTED_INCLUDED
32#define ETL_EXPECTED_INCLUDED
75 template <
typename TError>
86 : error_value(
other.error_value)
95 : error_value(
etl::move(
other.error_value))
120 template <
typename... Args >
122 : error_value(
etl::forward<Args>(args)...)
127#if ETL_HAS_INITIALIZER_LIST
131 template <
typename U,
typename... Args>
133 : error_value(init,
etl::forward<Args>(args)...)
146 error_value =
rhs.error_value;
159 error_value = etl::move(
rhs.error_value);
168 ETL_CONSTEXPR14 TError&
error()& ETL_NOEXCEPT
176 ETL_CONSTEXPR14
const TError&
error() const& ETL_NOEXCEPT
184 ETL_CONSTEXPR14 TError&&
error()&& ETL_NOEXCEPT
186 return etl::move(error_value);
192 ETL_CONSTEXPR14 TError&&
error() const&& ETL_NOEXCEPT
194 return etl::move(error_value);
211 using ETL_OR_STD::swap;
234 static const unexpect_t unexpect;
240 template <
typename TValue,
typename TError>
251 template <
typename U>
285 : storage(
other.storage)
294 : storage(etl::move(
other.storage))
303 template <typename G, typename etl::enable_if<!etl::is_convertible<const G&, TError>::value,
bool>::type =
false>
305 : storage(
etl::in_place_index_t<Error_Type>(), ue.error())
309 template <typename G, typename etl::enable_if<etl::is_convertible<const G&, TError>::value,
bool>::type =
false>
311 : storage(
etl::in_place_index_t<Error_Type>(), ue.error())
315 template <
typename G>
317 : storage(
etl::in_place_index_t<Error_Type>(), ue.error())
326 template <typename G, typename etl::enable_if<!etl::is_convertible<const G&, TError>::value,
bool>::type =
false>
328 : storage(
etl::in_place_index_t<Error_Type>(),
etl::move(ue.error()))
332 template <typename G, typename etl::enable_if<etl::is_convertible<const G&, TError>::value,
bool>::type =
false>
334 : storage(
etl::in_place_index_t<Error_Type>(),
etl::move(ue.error()))
351 template <
typename...
Args>
357#if ETL_HAS_INITIALIZER_LIST
361 template <
typename U,
typename... Args>
363 : storage(
etl::in_place_index_t<Value_Type>(), il,
etl::forward<Args>(args)...)
371 template <
typename... Args>
373 : storage(error_type(
etl::forward<Args>(args)...))
377#if ETL_HAS_INITIALIZER_LIST
381 template <
typename U,
typename... Args>
383 : storage(error_type(il,
etl::forward<Args>(args)...))
396 storage =
other.storage;
409 storage = etl::move(
other.storage);
471 ETL_CONSTEXPR14 value_type&
value()&
479 ETL_CONSTEXPR14
const value_type&
value() const&
487 ETL_CONSTEXPR14 value_type&&
value()&&
495 ETL_CONSTEXPR14
const value_type&&
value() const&&
514 bool has_value()
const ETL_NOEXCEPT
516 return (storage.
index() == Value_Type);
525 operator bool() const ETL_NOEXCEPT
534 template <
typename U>
538 value_or(U&& default_value)
const&
553 template <
typename U>
557 value_or(U&& default_value)&&
561 return etl::move(
value());
574 error_type& error()& ETL_NOEXCEPT
584 const error_type& error() const& ETL_NOEXCEPT
594 error_type&& error()&& ETL_NOEXCEPT
604 const error_type&& error() const&& ETL_NOEXCEPT
613 void swap(this_type& other)
615 using ETL_OR_STD::swap;
617 swap(storage, other.storage);
623 template <
typename... Args>
624 ETL_CONSTEXPR14 value_type& emplace(Args&&... args) ETL_NOEXCEPT
634#if ETL_HAS_INITIALIZER_LIST
635 template <
typename U,
typename... Args>
636 ETL_CONSTEXPR14 value_type& emplace(std::initializer_list<U> il, Args&&... args) ETL_NOEXCEPT
647 template <
typename U>
648 value_type value_or(
const U& default_value)
const
656 return default_value;
663 error_type& error()
const
672 value_type* operator ->()
674#if ETL_IS_DEBUG_BUILD
675 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
684 const value_type* operator ->()
const
686#if ETL_IS_DEBUG_BUILD
687 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
696 value_type& operator *() ETL_LVALUE_REF_QUALIFIER
698#if ETL_IS_DEBUG_BUILD
699 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
708 const value_type& operator *() const ETL_LVALUE_REF_QUALIFIER
710#if ETL_IS_DEBUG_BUILD
711 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
721 value_type&& operator *()&&
723#if ETL_IS_DEBUG_BUILD
724 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
733 const value_type&& operator *() const&&
735#if ETL_IS_DEBUG_BUILD
736 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
753 storage_type storage;
759 template<
typename TError>
766 typedef TError error_type;
782 : storage(
ue_.error())
792 : storage(
etl::move(
ue_.error()))
802 : storage(
other.storage)
824 storage =
other.storage;
836 storage = etl::move(
other.storage);
872 return (storage.
index() != Error_Type);
893 error_type& error()& ETL_NOEXCEPT
904 const error_type& error() const& ETL_NOEXCEPT
915 error_type&& error() && ETL_NOEXCEPT
926 const error_type&& error() const&& ETL_NOEXCEPT
946 using ETL_OR_STD::swap;
966template <
typename TValue,
typename TError,
typename TValue2,
typename TError2>
970 if (lhs.has_value() != rhs.has_value())
976 return lhs.value() == rhs.value();
978 return lhs.error() == rhs.error();
982template <
typename TValue,
typename TError,
typename TValue2>
986 if (!lhs.has_value())
990 return lhs.value() == rhs;
994template <
typename TValue,
typename TError,
typename TError2>
1002 return lhs.error() == rhs.error();
1006template <
typename TError,
typename TError2>
1010 if (lhs.has_value() != rhs.has_value())
1014 if (lhs.has_value())
1018 return lhs.error() == rhs.error();
1022template <
typename TError,
typename TError2>
1026 if (lhs.has_value())
1030 return lhs.error() == rhs.error();
1034template <
typename TError,
typename TError2>
1038 return lhs.error() == rhs.error();
1042template <
typename TValue,
typename TError,
typename TValue2,
typename TError2>
1046 return !(lhs == rhs);
1050template <
typename TValue,
typename TError,
typename TValue2>
1054 return !(lhs == rhs);
1058template <
typename TValue,
typename TError,
typename TError2>
1062 return !(lhs == rhs);
1066template <
typename TError,
typename TError2>
1070 return !(lhs == rhs);
1074template <
typename TError,
typename TError2>
1078 return !(lhs == rhs);
1082template <
typename TError,
typename TError2>
1086 return !(lhs == rhs);
1092template <
typename TValue,
typename TError>
1102template <
typename TError>
Specialisation for void value type.
Definition expected.h:761
error_type & error() const
Definition expected.h:935
ETL_CONSTEXPR14 expected()
Default constructor.
Definition expected.h:773
ETL_NODISCARD ETL_CONSTEXPR14 bool has_value() const ETL_NOEXCEPT
Returns true if expected has a value.
Definition expected.h:870
ETL_CONSTEXPR14 expected(const unexpected_type &ue_)
Copy construct from unexpected.
Definition expected.h:781
void swap(this_type &other)
Swap with another etl::expected.
Definition expected.h:944
ETL_CONSTEXPR14 expected(const this_type &other)
Copy construct.
Definition expected.h:801
Base exception for et::expected.
Definition expected.h:49
expected_invalid
Definition expected.h:62
Expected type.
Definition expected.h:242
ETL_CONSTEXPR14 expected() ETL_NOEXCEPT
Default constructor.
Definition expected.h:258
ETL_CONSTEXPR14 expected(const value_type &value_) ETL_NOEXCEPT
Constructor.
Definition expected.h:266
this_type & operator=(const this_type &other)
Copy assign from etl::expected.
Definition expected.h:392
ETL_CONSTEXPR14 expected(etl::in_place_t) ETL_NOEXCEPT
Construct with default value type.
Definition expected.h:342
value_type & value() const
Get the value.
Definition expected.h:503
ETL_CONSTEXPR14 expected(const expected &other) ETL_NOEXCEPT
Copy constructor.
Definition expected.h:284
const TError & error() const
Get the error.
Definition expected.h:200
void swap(etl::unexpected< TError > &other)
Swap with another etl::unexpected.
Definition expected.h:209
ETL_CONSTEXPR unexpected(const unexpected &other)
Copy constructor.
Definition expected.h:85
ETL_CONSTEXPR unexpected(const TError &e)
Construct from an lvalue.
Definition expected.h:103
ETL_CONSTEXPR14 etl::unexpected< TError > & operator=(const etl::unexpected< TError > &rhs)
Assign from etl::unexpected.
Definition expected.h:142
ETL_CONSTEXPR14 bool operator==(const etl::expected< TValue, TError > &lhs, const etl::expected< TValue2, TError2 > &rhs)
Equivalence operators.
Definition expected.h:968
#define ETL_ASSERT(b, e)
Definition error_handler.h:356
Definition exception.h:47
ETL_CONSTEXPR17 etl::enable_if<!etl::is_same< T, etl::nullptr_t >::value, T >::type * addressof(T &t)
Definition addressof.h:52
size_t index() const
Gets the index of the type currently stored or UNSUPPORTED_TYPE_ID.
Definition variant_legacy.h:735
bitset_ext
Definition absolute.h:38
void swap(etl::array< T, SIZE > &lhs, etl::array< T, SIZE > &rhs)
Template deduction guides.
Definition array.h:630
in_place disambiguation tags.
Definition utility.h:572
Definition type_traits_generator.h:2067
Definition type_traits_generator.h:2074
pair holds two objects of arbitrary type
Definition utility.h:164
unexpect_t
Definition expected.h:225