261 typedef TValue value_type;
262 typedef TError error_type;
266 template <
typename U>
281 ETL_CONSTEXPR14
expected(
const value_type& value_) ETL_NOEXCEPT
300 : storage(other.storage)
309 : storage(etl::move(other.storage))
318 template <typename G, typename etl::enable_if< !etl::is_convertible<const G&, TError>::value,
bool>
::type =
false>
320 : storage(
etl::in_place_index_t<Error_Type>(), ue.error())
324 template <typename G, typename etl::enable_if< etl::is_convertible<const G&, TError>::value,
bool>::type =
false>
325 ETL_CONSTEXPR14
expected(
const etl::unexpected<G>& ue)
326 : storage(etl::in_place_index_t<Error_Type>(), ue.error())
330 template <
typename G>
331 explicit expected(
const etl::unexpected<G>& ue)
332 : storage(etl::in_place_index_t<Error_Type>(), ue.error())
341 template <typename G, typename etl::enable_if< !etl::is_convertible<const G&, TError>::value,
bool>::type =
false>
342 ETL_CONSTEXPR14
explicit expected(etl::unexpected<G>&& ue)
343 : storage(etl::in_place_index_t<Error_Type>(), etl::move(ue.error()))
347 template <typename G, typename etl::enable_if< etl::is_convertible<const G&, TError>::value,
bool>::type =
false>
348 ETL_CONSTEXPR14
expected(etl::unexpected<G>&& ue)
349 : storage(etl::in_place_index_t<Error_Type>(), etl::move(ue.error()))
358 : storage(value_type())
366 template <
typename... Args>
372 #if ETL_HAS_INITIALIZER_LIST
376 template <
typename U,
typename... Args>
378 : storage(
etl::in_place_index_t<Value_Type>(), il,
etl::forward<Args>(args)...)
386 template <
typename... Args>
387 ETL_CONSTEXPR14
explicit expected(etl::unexpect_t, Args&&... args)
388 : storage(error_type(etl::forward<Args>(args)...))
392 #if ETL_HAS_INITIALIZER_LIST
396 template <
typename U,
typename... Args>
397 ETL_CONSTEXPR14
explicit expected(etl::unexpect_t, std::initializer_list<U> il, Args&&... args)
398 : storage(error_type(il, etl::forward<Args>(args)...))
409 ETL_STATIC_ASSERT(etl::is_copy_constructible<TValue>::value && etl::is_copy_constructible<TError>::value,
"Not copy assignable");
411 storage = other.storage;
422 ETL_STATIC_ASSERT(etl::is_move_constructible<TValue>::value && etl::is_move_constructible<TError>::value,
"Not move assignable");
424 storage = etl::move(other.storage);
435 ETL_STATIC_ASSERT(etl::is_copy_constructible<TValue>::value,
"Value not copy assignable");
437 storage.template emplace<Value_Type>(
value);
448 ETL_STATIC_ASSERT(etl::is_move_constructible<TValue>::value,
"Value not move assignable");
450 storage.template emplace<Value_Type>(etl::move(value));
462 ETL_STATIC_ASSERT(etl::is_copy_constructible<TError>::value,
"Error not copy assignable");
465 storage.template emplace<Error_Type>(ue.
error());
476 ETL_STATIC_ASSERT(etl::is_move_constructible<TError>::value,
"Error not move assignable");
478 storage.template emplace<Error_Type>(etl::move(ue.error()));
488 ETL_CONSTEXPR14 value_type&
value() &
496 ETL_CONSTEXPR14
const value_type&
value() const&
504 ETL_CONSTEXPR14 value_type&&
value() &&
512 ETL_CONSTEXPR14
const value_type&&
value() const&&
529 ETL_NODISCARD ETL_CONSTEXPR14
bool has_value() const ETL_NOEXCEPT
531 return (storage.
index() == Value_Type);
537 ETL_NODISCARD ETL_CONSTEXPR14 ETL_EXPLICIT
operator bool() const ETL_NOEXCEPT
546 template <
typename U>
547 ETL_NODISCARD ETL_CONSTEXPR14 etl::enable_if_t<etl::is_convertible<U, value_type>::value, value_type> value_or(U&& default_value)
const&
555 return static_cast<value_type
>(etl::forward<U>(default_value));
562 template <
typename U>
563 ETL_NODISCARD ETL_CONSTEXPR14 etl::enable_if_t<etl::is_convertible<U, value_type>::value, value_type> value_or(U&& default_value) &&
567 return etl::move(
value());
571 return static_cast<value_type
>(etl::forward<U>(default_value));
578 ETL_NODISCARD ETL_CONSTEXPR14 error_type& error() & ETL_NOEXCEPT
586 ETL_NODISCARD ETL_CONSTEXPR14
const error_type& error() const& ETL_NOEXCEPT
594 ETL_NODISCARD ETL_CONSTEXPR14 error_type&& error() && ETL_NOEXCEPT
602 ETL_NODISCARD ETL_CONSTEXPR14
const error_type&& error() const&& ETL_NOEXCEPT
610 void swap(this_type& other)
612 using ETL_OR_STD::swap;
614 swap(storage, other.storage);
620 template <
typename... Args>
621 ETL_CONSTEXPR14 value_type& emplace(Args&&... args) ETL_NOEXCEPT
623 storage.template emplace<value_type>(etl::forward<Args>(args)...);
631 #if ETL_HAS_INITIALIZER_LIST
632 template <
typename U,
typename... Args>
633 ETL_CONSTEXPR14 value_type& emplace(std::initializer_list<U> il, Args&&... args) ETL_NOEXCEPT
635 storage.template emplace<value_type>(il, etl::forward<Args>(args)...);
644 template <
typename U>
645 value_type value_or(
const U& default_value)
const
653 return default_value;
660 const error_type& error()
const
669 value_type* operator->()
671 ETL_ASSERT_OR_RETURN_VALUE(has_value(), ETL_ERROR(expected_invalid), ETL_NULLPTR);
679 const value_type* operator->()
const
681 ETL_ASSERT_OR_RETURN_VALUE(has_value(), ETL_ERROR(expected_invalid), ETL_NULLPTR);
689 value_type& operator*() ETL_LVALUE_REF_QUALIFIER
691 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
699 const value_type& operator*() const ETL_LVALUE_REF_QUALIFIER
701 ETL_ASSERT_OR_RETURN_VALUE(has_value(), ETL_ERROR(expected_invalid), ETL_NULLPTR);
710 value_type&& operator*() &&
712 ETL_ASSERT_OR_RETURN_VALUE(has_value(), ETL_ERROR(expected_invalid), ETL_NULLPTR);
720 const value_type&& operator*() const&&
722 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
729 template <typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void, TValue&>::type>::type>
732 return transform_impl<F, this_type&, U, TValue&>(etl::forward<F>(f), *
this);
735 template < typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void, const TValue&>::type>::type>
738 return transform_impl<F, const this_type&, U, const TValue&>(etl::forward<F>(f), *
this);
741 template <typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void, TValue&&>::type>::type>
744 return transform_impl<F, this_type&&, U, TValue&&>(etl::forward<F>(f), etl::move(*
this));
747 template < typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void, const TValue&&>::type>::type>
750 return transform_impl<F, const this_type&&, U, const TValue&&>(etl::forward<F>(f), etl::move(*
this));
753 template <typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void, TValue&>::type>::type>
754 auto and_then(F&& f) & -> U
756 return and_then_impl<F, this_type&, U, TValue&>(etl::forward<F>(f), *
this);
759 template < typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void, const TValue&>::type>::type>
760 auto and_then(F&& f)
const& -> U
762 return and_then_impl<F, const this_type&, U, const TValue&>(etl::forward<F>(f), *
this);
765 template <typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void, TValue&&>::type>::type>
766 auto and_then(F&& f) && -> U
768 return and_then_impl<F, this_type&&, U, TValue&&>(etl::forward<F>(f), etl::move(*
this));
771 template < typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void, const TValue&&>::type>::type>
772 auto and_then(F&& f)
const&& -> U
774 return and_then_impl<F, const this_type&&, U, const TValue&&>(etl::forward<F>(f), etl::move(*
this));
777 template <typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void, TError&>::type>::type>
778 auto or_else(F&& f) & -> U
780 return or_else_impl<F, this_type&, U, TError&>(etl::forward<F>(f), *
this);
783 template < typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void, const TError&>::type>::type>
784 auto or_else(F&& f)
const& -> U
786 return or_else_impl<F, const this_type&, U, const TError&>(etl::forward<F>(f), *
this);
789 template <typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void, TError&&>::type>::type>
790 auto or_else(F&& f) && -> U
792 return or_else_impl<F, this_type&&, U, TError&&>(etl::forward<F>(f), etl::move(*
this));
795 template < typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void, const TError&&>::type>::type>
796 auto or_else(F&& f)
const&& -> U
798 return or_else_impl<F, const this_type&&, U, const TError&&>(etl::forward<F>(f), etl::move(*
this));
801 template <typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void, TError&>::type>::type>
804 return transform_error_impl<F, this_type&, U, TError&>(etl::forward<F>(f), *
this);
807 template < typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void, const TError&>::type>::type>
810 return transform_error_impl<F, const this_type&, U, const TError&>(etl::forward<F>(f), *
this);
813 template <typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void, TError&&>::type>::type>
816 return transform_error_impl<F, this_type&&, U, TError&&>(etl::forward<F>(f), etl::move(*
this));
819 template < typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void, const TError&&>::type>::type>
822 return transform_error_impl<F, const this_type&&, U, const TError&&>(etl::forward<F>(f), etl::move(*
this));
835 typedef etl::variant<etl::monostate, value_type, error_type> storage_type;
836 storage_type storage;
839 template < typename F, typename TExp, typename TRet, typename TValueRef, typename = typename etl::enable_if<!etl::is_void<TRet>::value>::type>
852 template < typename F, typename TExp, typename TRet, typename TValueRef, typename = typename etl::enable_if<etl::is_void<TRet>::value>::type>
866 template <
typename F,
typename TExp,
typename TRet,
typename TValueRef,
867 typename =
typename etl::enable_if< !etl::is_void<TRet>::value && etl::is_expected<TRet>::value
868 && etl::is_same<typename TRet::error_type, TError>::value>::type>
869 auto and_then_impl(F&& f, TExp&& exp)
const -> TRet
873 return etl::invoke(etl::forward<F>(f), etl::forward<TValueRef>(
etl::get<Value_Type>(exp.storage)));
877 return TRet(unexpected<TError>(etl::forward<TExp>(exp).error()));
881 template <
typename F,
typename TExp,
typename TRet,
typename TErrorRef,
882 typename =
typename etl::enable_if< !etl::is_void<TRet>::value && etl::is_expected<TRet>::value
883 && etl::is_same<typename TRet::value_type, TValue>::value>::type>
884 auto or_else_impl(F&& f, TExp&& exp)
const -> TRet
888 return TRet(etl::forward<TExp>(exp).
value());
892 return etl::invoke(etl::forward<F>(f), etl::forward<TErrorRef>(
etl::get<Error_Type>(exp.storage)));
896 template < typename F, typename TExp, typename TRet, typename TErrorRef, typename = typename etl::enable_if<!etl::is_void<TRet>::value>::type>
920 typedef void value_type;
921 typedef TError error_type;
934 ETL_CONSTEXPR14
expected(
const unexpected_type& ue_)
935 : storage(ue_.
error())
943 ETL_CONSTEXPR14
expected(unexpected_type&& ue_)
944 : storage(
etl::move(ue_.error()))
953 : storage(other.storage)
961 ETL_CONSTEXPR14
expected(this_type&& other)
962 : storage(
etl::move(other.storage))
972 ETL_STATIC_ASSERT(etl::is_copy_constructible<TError>::value,
"Not copy assignable");
974 storage = other.storage;
984 ETL_STATIC_ASSERT(etl::is_move_constructible<TError>::value,
"Not move assignable");
986 storage = etl::move(other.storage);
997 ETL_STATIC_ASSERT(etl::is_copy_constructible<TError>::value,
"Error not copy assignable");
1000 storage.template emplace<Error_Type>(ue.
error());
1010 ETL_STATIC_ASSERT(etl::is_move_constructible<TError>::value,
"Error not move assignable");
1012 storage.template emplace<Error_Type>(etl::move(ue.error()));
1020 ETL_NODISCARD ETL_CONSTEXPR14
bool has_value() const ETL_NOEXCEPT
1022 return (storage.index() != Error_Type);
1028 ETL_NODISCARD ETL_CONSTEXPR14 ETL_EXPLICIT
operator bool() const ETL_NOEXCEPT
1038 ETL_NODISCARD ETL_CONSTEXPR14 error_type& error() & ETL_NOEXCEPT
1047 ETL_NODISCARD ETL_CONSTEXPR14
const error_type& error() const& ETL_NOEXCEPT
1056 ETL_NODISCARD ETL_CONSTEXPR14 error_type&& error() && ETL_NOEXCEPT
1065 ETL_NODISCARD ETL_CONSTEXPR14
const error_type&& error() const&& ETL_NOEXCEPT
1085 using ETL_OR_STD::swap;
1087 swap(storage, other.storage);
1091 template <typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void>::type>
::type>
1094 return transform_impl<F, this_type&, U>(etl::forward<F>(f), *
this);
1097 template <typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void>::type>
::type>
1100 return transform_impl<F, const this_type&, U>(etl::forward<F>(f), *
this);
1103 template <typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void>::type>::type>
1106 return transform_impl<F, this_type&&, U>(etl::forward<F>(f), etl::move(*
this));
1109 template <typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void>::type>::type>
1112 return transform_impl<F, const this_type&&, U>(etl::forward<F>(f), etl::move(*
this));
1115 template <typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void>::type>::type>
1116 auto and_then(F&& f) & -> U
1118 return and_then_impl<F, this_type&, U>(etl::forward<F>(f), *
this);
1121 template <typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void>::type>::type>
1122 auto and_then(F&& f)
const& -> U
1124 return and_then_impl<F, const this_type&, U>(etl::forward<F>(f), *
this);
1127 template <typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void>::type>::type>
1128 auto and_then(F&& f) && -> U
1130 return and_then_impl<F, this_type&&, U>(etl::forward<F>(f), etl::move(*
this));
1133 template <typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void>::type>::type>
1134 auto and_then(F&& f)
const&& -> U
1136 return and_then_impl<F, const this_type&&, U>(etl::forward<F>(f), etl::move(*
this));
1139 template <typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void, TError&>::type>::type>
1140 auto or_else(F&& f) & -> U
1142 return or_else_impl<F, this_type&, U, TError&>(etl::forward<F>(f), *
this);
1145 template < typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void, const TError&>::type>::type>
1146 auto or_else(F&& f)
const& -> U
1148 return or_else_impl<F, const this_type&, U, const TError&>(etl::forward<F>(f), *
this);
1151 template <typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void, TError&&>::type>::type>
1152 auto or_else(F&& f) && -> U
1154 return or_else_impl<F, this_type&&, U, TError&&>(etl::forward<F>(f), etl::move(*
this));
1157 template < typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void, const TError&&>::type>::type>
1158 auto or_else(F&& f)
const&& -> U
1160 return or_else_impl<F, const this_type&&, U, const TError&&>(etl::forward<F>(f), etl::move(*
this));
1163 template <typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void, TError&>::type>::type>
1166 return transform_error_impl<F, this_type&, U, TError&>(etl::forward<F>(f), *
this);
1169 template < typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void, const TError&>::type>::type>
1172 return transform_error_impl<F, const this_type&, U, const TError&>(etl::forward<F>(f), *
this);
1175 template <typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void, TError&&>::type>::type>
1178 return transform_error_impl<F, this_type&&, U, TError&&>(etl::forward<F>(f), etl::move(*
this));
1181 template < typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void, const TError&&>::type>::type>
1184 return transform_error_impl<F, const this_type&&, U, const TError&&>(etl::forward<F>(f), *
this);
1196 etl::variant<etl::monostate, error_type> storage;
1199 template < typename F, typename TExp, typename TRet, typename = typename etl::enable_if<!etl::is_void<TRet>::value>::type>
1202 if (exp.has_value())
1212 template < typename F, typename TExp, typename TRet, typename = typename etl::enable_if<etl::is_void<TRet>::value>::type>
1215 if (exp.has_value())
1217 etl::invoke(etl::forward<F>(f));
1226 template <
typename F,
typename TExp,
typename TRet,
1227 typename =
typename etl::enable_if< !etl::is_void<TRet>::value && etl::is_expected<TRet>::value
1228 && etl::is_same<typename TRet::error_type, TError>::value>::type>
1229 auto and_then_impl(F&& f, TExp&& exp)
const -> TRet
1231 if (exp.has_value())
1233 return etl::invoke(etl::forward<F>(f));
1237 return TRet(unexpected<TError>(etl::forward<TExp>(exp).error()));
1241 template <
typename F,
typename TExp,
typename TRet,
typename TErrorRef,
1242 typename =
typename etl::enable_if< !etl::is_void<TRet>::value && etl::is_expected<TRet>::value
1243 && etl::is_same<typename TRet::value_type, void>::value>::type>
1244 auto or_else_impl(F&& f, TExp&& exp)
const -> TRet
1246 if (exp.has_value())
1252 return etl::invoke(etl::forward<F>(f), etl::forward<TErrorRef>(
etl::get<Error_Type>(exp.storage)));
1256 template < typename F, typename TExp, typename TRet, typename TErrorRef, typename = typename etl::enable_if<!etl::is_void<TRet>::value>::type>
1259 if (exp.has_value())