31#ifndef ETL_EXPECTED_INCLUDED
32#define ETL_EXPECTED_INCLUDED
51 expected_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
52 :
exception(reason_, file_name_, line_number_)
60 template <
typename TError>
70 :
expected_exception(ETL_ERROR_TEXT(
"expected:invalid", ETL_EXPECTED_FILE_ID
"A"), file_name_, line_number_)
76 template <
typename TError>
91 template <
typename TError>
96 typedef TError error_type;
102 : error_value(other.error_value)
111 : error_value(
etl::move(other.error_value))
129 : error_value(
etl::forward<TError>(e))
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);
229 swap(error_value, other.error_value);
250 static const unexpect_t unexpect;
256 template <
typename TValue,
typename TError>
262 typedef TValue value_type;
263 typedef TError error_type;
267 template <
typename U>
282 ETL_CONSTEXPR14
expected(
const value_type& value_) ETL_NOEXCEPT
291 ETL_CONSTEXPR14
expected(value_type&& value_) ETL_NOEXCEPT
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()))
359 : storage(value_type())
367 template <
typename... Args>
369 : storage(
etl::forward<Args>(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();
468 expected& operator =(unexpected_type&& ue)
472 storage = etl::move(ue.error());
482 ETL_CONSTEXPR14 value_type&
value()&
484 return etl::get<Value_Type>(storage);
490 ETL_CONSTEXPR14
const value_type&
value() const&
492 return etl::get<Value_Type>(storage);
498 ETL_CONSTEXPR14 value_type&&
value()&&
500 return etl::move(etl::get<Value_Type>(storage));
506 ETL_CONSTEXPR14
const value_type&&
value() const&&
508 return etl::move(etl::get<Value_Type>(storage));
516 return etl::get<Value_Type>(storage);
525 bool has_value()
const
527 return (storage.
index() == Value_Type);
535 operator bool()
const
544 template <
typename U>
547 etl::enable_if_t<etl::is_convertible<U, value_type>::value, value_type>
548 value_or(U&& default_value)
const&
556 return static_cast<value_type
>(etl::forward<U>(default_value));
563 template <
typename U>
566 etl::enable_if_t<etl::is_convertible<U, value_type>::value, value_type>
567 value_or(U&& default_value)&&
571 return etl::move(
value());
575 return static_cast<value_type
>(etl::forward<U>(default_value));
584 error_type& error()& ETL_NOEXCEPT
586 return etl::get<Error_Type>(storage);
594 const error_type& error() const& ETL_NOEXCEPT
596 return etl::get<Error_Type>(storage);
604 error_type&& error()&& ETL_NOEXCEPT
606 return etl::move(etl::get<Error_Type>(storage));
614 const error_type&& error() const&& ETL_NOEXCEPT
616 return etl::move(etl::get<Error_Type>(storage));
622 template <
typename... Args>
623 ETL_CONSTEXPR14 value_type& emplace(Args&&... args) ETL_NOEXCEPT
625 storage.
emplace(etl::forward<Args>(args)...);
631 template <
typename U,
typename... Args>
632 ETL_CONSTEXPR14 value_type& emplace(std::initializer_list<U>& il, Args&&... args) ETL_NOEXCEPT
634 storage.
emplace(il, etl::forward<Args>(args)...);
640 template <
typename U>
641 value_type value_or(
const U& default_value)
const
649 return default_value;
656 error_type& error()
const
658 return etl::get<Error_Type>(storage);
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>));
695 return etl::get<value_type>(storage);
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>));
707 return etl::get<value_type>(storage);
714 value_type&& operator *()&&
716#if ETL_IS_DEBUG_BUILD
717 ETL_ASSERT(storage.
index() == Value_Type, ETL_ERROR(expected_invalid<TError>));
720 return etl::move(etl::get<value_type>(storage));
726 const value_type&& operator *() const&&
728#if ETL_IS_DEBUG_BUILD
729 ETL_ASSERT(storage.
index() == Value_Type, ETL_ERROR(expected_invalid<TError>));
732 return etl::move(etl::get<value_type>(storage));
746 storage_type storage;
752 template<
typename TError>
758 typedef void value_type;
759 typedef TError error_type;
775 : storage(ue_.error())
785 : storage(
etl::move(ue_.error()))
795 : storage(other.storage)
805 : storage(
etl::move(other.storage))
817 storage = other.storage;
825 this_type& operator =(this_type&& other)
829 storage = etl::move(other.storage);
841 storage.template emplace<Error_Type>(ue.
error());
849 expected& operator =(unexpected_type&& ue)
853 storage.template emplace<Error_Type>(etl::move(ue.error()));
865 return (storage.
index() != Error_Type);
873 operator bool()
const
885 error_type& error()& ETL_NOEXCEPT
887 return etl::get<Error_Type>(storage);
896 const error_type& error() const& ETL_NOEXCEPT
898 return etl::get<Error_Type>(storage);
907 error_type&& error() && ETL_NOEXCEPT
909 return etl::move(etl::get<Error_Type>(storage));
918 const error_type&& error() const&& ETL_NOEXCEPT
920 return etl::move(etl::get<Error_Type>(storage));
929 return etl::get<Error_Type>(storage);
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
Definition: expected.h:66
expected_invalid
Definition: expected.h:78
Expected type.
Definition: expected.h:258
ETL_CONSTEXPR14 expected() ETL_NOEXCEPT
Default constructor.
Definition: expected.h:274
value_type & value() const
Get the value.
Definition: expected.h:514
Definition: expected.h:93
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_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
ETL_CONSTEXPR exception(string_type reason_, string_type, numeric_type line_)
Constructor.
Definition: exception.h:69
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
Definition: utility.h:591
in_place disambiguation tags.
Definition: utility.h:570
Definition: type_traits_generator.h:2026
Definition: type_traits_generator.h:2033
unexpect_t
Definition: expected.h:241