248 typedef TValue value_type;
249 typedef TError error_type;
253 template <
typename U>
268 ETL_CONSTEXPR14
expected(
const value_type& value_) ETL_NOEXCEPT
287 : storage(other.storage)
296 : storage(etl::move(other.storage))
305 template <typename G, typename etl::enable_if<!etl::is_convertible<const G&, TError>::value,
bool>::type =
false>
307 : storage(
etl::in_place_index_t<Error_Type>(), ue.error())
311 template <typename G, typename etl::enable_if<etl::is_convertible<const G&, TError>::value,
bool>::type =
false>
312 ETL_CONSTEXPR14
expected(
const etl::unexpected<G>& ue)
313 : storage(etl::in_place_index_t<Error_Type>(), ue.error())
317 template <
typename G>
318 explicit expected(
const etl::unexpected<G>& ue)
319 : storage(etl::in_place_index_t<Error_Type>(), ue.error())
328 template <typename G, typename etl::enable_if<!etl::is_convertible<const G&, TError>::value,
bool>::type =
false>
329 ETL_CONSTEXPR14
explicit expected(etl::unexpected<G>&& ue)
330 : storage(etl::in_place_index_t<Error_Type>(), etl::move(ue.error()))
334 template <typename G, typename etl::enable_if<etl::is_convertible<const G&, TError>::value,
bool>::type =
false>
335 ETL_CONSTEXPR14
expected(etl::unexpected<G>&& ue)
336 : storage(etl::in_place_index_t<Error_Type>(), etl::move(ue.error()))
345 : storage(value_type())
353 template <
typename... Args>
359#if ETL_HAS_INITIALIZER_LIST
363 template <
typename U,
typename... Args>
365 : storage(
etl::in_place_index_t<Value_Type>(), il,
etl::forward<Args>(args)...)
373 template <
typename... Args>
374 ETL_CONSTEXPR14
explicit expected(etl::unexpect_t, Args&&... args)
375 : storage(error_type(etl::forward<Args>(args)...))
379#if ETL_HAS_INITIALIZER_LIST
383 template <
typename U,
typename... Args>
384 ETL_CONSTEXPR14
explicit expected(etl::unexpect_t, std::initializer_list<U> il, Args&&... args)
385 : storage(error_type(il, etl::forward<Args>(args)...))
396 ETL_STATIC_ASSERT(etl::is_copy_constructible<TValue>::value && etl::is_copy_constructible<TError>::value,
"Not copy assignable");
398 storage = other.storage;
409 ETL_STATIC_ASSERT(etl::is_move_constructible<TValue>::value && etl::is_move_constructible<TError>::value,
"Not move assignable");
411 storage = etl::move(other.storage);
422 ETL_STATIC_ASSERT(etl::is_copy_constructible<TValue>::value,
"Value not copy assignable");
424 storage.template emplace<Value_Type>(
value);
435 ETL_STATIC_ASSERT(etl::is_move_constructible<TValue>::value,
"Value not move assignable");
437 storage.template emplace<Value_Type>(etl::move(value));
449 ETL_STATIC_ASSERT(etl::is_copy_constructible<TError>::value,
"Error not copy assignable");
452 storage.template emplace<Error_Type>(ue.
error());
463 ETL_STATIC_ASSERT(etl::is_move_constructible<TError>::value,
"Error not move assignable");
465 storage.template emplace<Error_Type>(etl::move(ue.error()));
475 ETL_CONSTEXPR14 value_type&
value()&
483 ETL_CONSTEXPR14
const value_type&
value() const&
491 ETL_CONSTEXPR14 value_type&&
value()&&
499 ETL_CONSTEXPR14
const value_type&&
value() const&&
518 bool has_value() const ETL_NOEXCEPT
520 return (storage.
index() == Value_Type);
529 operator bool() const ETL_NOEXCEPT
538 template <
typename U>
541 etl::enable_if_t<etl::is_convertible<U, value_type>::value, value_type>
542 value_or(U&& default_value)
const&
550 return static_cast<value_type
>(etl::forward<U>(default_value));
557 template <
typename U>
560 etl::enable_if_t<etl::is_convertible<U, value_type>::value, value_type>
561 value_or(U&& default_value)&&
565 return etl::move(
value());
569 return static_cast<value_type
>(etl::forward<U>(default_value));
578 error_type& error()& ETL_NOEXCEPT
588 const error_type& error() const& ETL_NOEXCEPT
598 error_type&& error()&& ETL_NOEXCEPT
608 const error_type&& error() const&& ETL_NOEXCEPT
617 void swap(this_type& other)
619 using ETL_OR_STD::swap;
621 swap(storage, other.storage);
627 template <
typename... Args>
628 ETL_CONSTEXPR14 value_type& emplace(Args&&... args) ETL_NOEXCEPT
630 storage.template emplace<value_type>(etl::forward<Args>(args)...);
638#if ETL_HAS_INITIALIZER_LIST
639 template <
typename U,
typename... Args>
640 ETL_CONSTEXPR14 value_type& emplace(std::initializer_list<U> il, Args&&... args) ETL_NOEXCEPT
642 storage.template emplace<value_type>(il, etl::forward<Args>(args)...);
651 template <
typename U>
652 value_type value_or(
const U& default_value)
const
660 return default_value;
667 const error_type& error()
const
676 value_type* operator ->()
678 ETL_ASSERT_OR_RETURN_VALUE(has_value(), ETL_ERROR(expected_invalid), ETL_NULLPTR);
686 const value_type* operator ->()
const
688 ETL_ASSERT_OR_RETURN_VALUE(has_value(), ETL_ERROR(expected_invalid), ETL_NULLPTR);
696 value_type& operator *() ETL_LVALUE_REF_QUALIFIER
698 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
706 const value_type& operator *() const ETL_LVALUE_REF_QUALIFIER
708 ETL_ASSERT_OR_RETURN_VALUE(has_value(), ETL_ERROR(expected_invalid), ETL_NULLPTR);
717 value_type&& operator *()&&
719 ETL_ASSERT_OR_RETURN_VALUE(has_value(), ETL_ERROR(expected_invalid), ETL_NULLPTR);
727 const value_type&& operator *() const&&
729 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
744 typedef etl::variant<etl::monostate, value_type, error_type> storage_type;
745 storage_type storage;