Skip to content

Commit

Permalink
Added conditionally explicit etl::expected constructors that work in …
Browse files Browse the repository at this point in the history
…C++11 (#719)
  • Loading branch information
Vitmark97 committed Jun 26, 2023
1 parent 96092d8 commit 70fd6fd
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions include/etl/expected.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,25 +312,41 @@ namespace etl
}
#endif

#if ETL_USING_CPP11
//*******************************************
/// Copy construct from unexpected type.
//*******************************************
template <typename G, typename etl::enable_if<!etl::is_convertible<const G&, TError>::value, bool>::type = false>
ETL_CONSTEXPR14 explicit expected(const etl::unexpected<G>& ue)
: storage(etl::in_place_index_t<Error_Type>(), ue.error())
{
}

template <typename G, typename etl::enable_if<etl::is_convertible<const G&, TError>::value, bool>::type = false>
ETL_CONSTEXPR14 expected(const etl::unexpected<G>& ue)
: storage(etl::in_place_index_t<Error_Type>(), ue.error())
{
}
#else
template <typename G>
ETL_CONSTEXPR14
ETL_EXPLICIT_EXPR(!etl::is_convertible_v<const G&, TError>)
expected(const etl::unexpected<G>& ue)
explicit expected(const etl::unexpected<G>& ue)
: storage(etl::in_place_index_t<Error_Type>(), ue.error())
{
}
#endif

#if ETL_USING_CPP11
//*******************************************
/// Move construct from unexpected type.
//*******************************************
template <typename G>
ETL_CONSTEXPR14
ETL_EXPLICIT_EXPR(!etl::is_convertible_v<G, TError>)
expected(etl::unexpected<G>&& ue)
template <typename G, typename etl::enable_if<!etl::is_convertible<const G&, TError>::value, bool>::type = false>
ETL_CONSTEXPR14 explicit expected(etl::unexpected<G>&& ue)
: storage(etl::in_place_index_t<Error_Type>(), etl::move(ue.error()))
{
}

template <typename G, typename etl::enable_if<etl::is_convertible<const G&, TError>::value, bool>::type = false>
ETL_CONSTEXPR14 expected(etl::unexpected<G>&& ue)
: storage(etl::in_place_index_t<Error_Type>(), etl::move(ue.error()))
{
}
Expand Down

0 comments on commit 70fd6fd

Please sign in to comment.