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(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
516 return (storage.
index() == Value_Type);
524 operator bool()
const
533 template <
typename U>
537 value_or(U&& default_value)
const&
552 template <
typename U>
556 value_or(U&& default_value)&&
560 return etl::move(
value());
573 error_type& error()& ETL_NOEXCEPT
583 const error_type& error() const& ETL_NOEXCEPT
593 error_type&& error()&& ETL_NOEXCEPT
603 const error_type&& error() const&& ETL_NOEXCEPT
612 void swap(this_type& other)
614 using ETL_OR_STD::swap;
616 swap(storage, other.storage);
622 template <
typename... Args>
623 ETL_CONSTEXPR14 value_type& emplace(Args&&... args) ETL_NOEXCEPT
633#if ETL_HAS_INITIALIZER_LIST
634 template <
typename U,
typename... Args>
635 ETL_CONSTEXPR14 value_type& emplace(std::initializer_list<U> il, Args&&... args) ETL_NOEXCEPT
646 template <
typename U>
647 value_type value_or(
const U& default_value)
const
655 return default_value;
662 error_type& error()
const
671 value_type* operator ->()
673#if ETL_IS_DEBUG_BUILD
674 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
683 const value_type* operator ->()
const
685#if ETL_IS_DEBUG_BUILD
686 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
695 value_type& operator *() ETL_LVALUE_REF_QUALIFIER
697#if ETL_IS_DEBUG_BUILD
698 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
707 const value_type& operator *() const ETL_LVALUE_REF_QUALIFIER
709#if ETL_IS_DEBUG_BUILD
710 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
720 value_type&& operator *()&&
722#if ETL_IS_DEBUG_BUILD
723 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
732 const value_type&& operator *() const&&
734#if ETL_IS_DEBUG_BUILD
735 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
752 storage_type storage;
758 template<
typename TError>
765 typedef TError error_type;
781 : storage(
ue_.error())
791 : storage(
etl::move(
ue_.error()))
801 : storage(
other.storage)
823 storage =
other.storage;
835 storage = etl::move(
other.storage);
871 return (storage.
index() != Error_Type);
891 error_type& error()& ETL_NOEXCEPT
902 const error_type& error() const& ETL_NOEXCEPT
913 error_type&& error() && ETL_NOEXCEPT
924 const error_type&& error() const&& ETL_NOEXCEPT
944 using ETL_OR_STD::swap;
964template <
typename TValue,
typename TError,
typename TValue2,
typename TError2>
968 if (lhs.has_value() != rhs.has_value())
974 return lhs.value() == rhs.value();
976 return lhs.error() == rhs.error();
980template <
typename TValue,
typename TError,
typename TValue2>
984 if (!lhs.has_value())
988 return lhs.value() == rhs;
992template <
typename TValue,
typename TError,
typename TError2>
1000 return lhs.error() == rhs.error();
1004template <
typename TError,
typename TError2>
1008 if (lhs.has_value() != rhs.has_value())
1012 if (lhs.has_value())
1016 return lhs.error() == rhs.error();
1020template <
typename TError,
typename TError2>
1024 if (lhs.has_value())
1028 return lhs.error() == rhs.error();
1032template <
typename TError,
typename TError2>
1036 return lhs.error() == rhs.error();
1040template <
typename TValue,
typename TError,
typename TValue2,
typename TError2>
1044 return !(lhs == rhs);
1048template <
typename TValue,
typename TError,
typename TValue2>
1052 return !(lhs == rhs);
1056template <
typename TValue,
typename TError,
typename TError2>
1060 return !(lhs == rhs);
1064template <
typename TError,
typename TError2>
1068 return !(lhs == rhs);
1072template <
typename TError,
typename TError2>
1076 return !(lhs == rhs);
1080template <
typename TError,
typename TError2>
1084 return !(lhs == rhs);
1090template <
typename TValue,
typename TError>
1100template <
typename TError>
Specialisation for void value type.
Definition expected.h:760
error_type & error() const
Definition expected.h:933
ETL_CONSTEXPR14 expected()
Default constructor.
Definition expected.h:772
ETL_NODISCARD ETL_CONSTEXPR14 bool has_value() const
Returns true if expected has a value.
Definition expected.h:869
ETL_CONSTEXPR14 expected(const unexpected_type &ue_)
Copy construct from unexpected.
Definition expected.h:780
void swap(this_type &other)
Swap with another etl::expected.
Definition expected.h:942
ETL_CONSTEXPR14 expected(const this_type &other)
Copy construct.
Definition expected.h:800
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:966
#define ETL_ASSERT(b, e)
Definition error_handler.h:316
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:722
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:2072
Definition type_traits_generator.h:2079
pair holds two objects of arbitrary type
Definition utility.h:164
unexpect_t
Definition expected.h:225