diff --git a/include/etl/expected.h b/include/etl/expected.h index 2c1b96ef..013d97d2 100644 --- a/include/etl/expected.h +++ b/include/etl/expected.h @@ -117,19 +117,20 @@ namespace etl //******************************************* /// Construct from argument. //******************************************* - template ::type, etl::unexpected>::value && + template ::type, unexpected>::value && !etl::is_same::type, etl::in_place_t>::value, int>::type> constexpr explicit unexpected(TErr&& e) : error_value(etl::forward(e)) { } + #else //******************************************* /// Construct from argument. //******************************************* template - explicit unexpected(const TErr& e, typename etl::enable_if::type, etl::unexpected>::value && - !etl::is_same::type, etl::in_place_t>::value, int>::type = 0) + explicit unexpected(const TErr& e, typename = typename etl::enable_if::type, unexpected>::value && + !etl::is_same::type, etl::in_place_t>::value, int>::type = 0) : error_value(e) { } @@ -161,7 +162,7 @@ namespace etl /// Assign from etl::unexpected. //******************************************* ETL_CONSTEXPR14 - etl::unexpected& operator =(const etl::unexpected& rhs) + etl::unexpected& operator =(const etl::unexpected& rhs) { ETL_STATIC_ASSERT(etl::is_copy_constructible::value, "Error not copy assignable"); @@ -174,7 +175,7 @@ namespace etl /// Move assign from etl::unexpected. //******************************************* ETL_CONSTEXPR14 - etl::unexpected& operator =(etl::unexpected&& rhs) + etl::unexpected& operator =(etl::unexpected&& rhs) { ETL_STATIC_ASSERT(etl::is_move_constructible::value, "Error not move assignable"); @@ -211,7 +212,7 @@ namespace etl //******************************************* /// Get the error. //******************************************* - constexpr TError&& error() const && noexcept + constexpr TError&& error() const&& noexcept { return etl::move(error_value); } @@ -240,25 +241,10 @@ namespace etl TError error_value; }; - template - bool operator ==(const etl::unexpected& lhs, const etl::unexpected& rhs) - { - return lhs.error_value == rhs.error_value; - } - - //******************************************* - /// Swap etl::unexpected. - //******************************************* - template - void swap(etl::unexpected& lhs, etl::unexpected& rhs) - { - lhs.swap(rhs); - } - //***************************************************************************** /// unexpect_t //***************************************************************************** - struct unexpect_t + struct unexpect_t { ETL_CONSTEXPR14 explicit unexpect_t() { @@ -492,7 +478,7 @@ namespace etl /// //******************************************* ETL_NODISCARD - ETL_CONSTEXPR14 + ETL_CONSTEXPR14 bool has_value() const { return (storage.index() == Value_Type); @@ -502,7 +488,7 @@ namespace etl /// //******************************************* ETL_NODISCARD - ETL_CONSTEXPR14 + ETL_CONSTEXPR14 operator bool() const { return has_value(); @@ -513,7 +499,7 @@ namespace etl //******************************************* template ETL_NODISCARD - ETL_CONSTEXPR14 + ETL_CONSTEXPR14 value_type value_or(U&& default_value) const& { if (has_value()) @@ -548,7 +534,7 @@ namespace etl /// //******************************************* ETL_NODISCARD - ETL_CONSTEXPR14 + ETL_CONSTEXPR14 error_type& error()& ETL_NOEXCEPT { return etl::get(storage); @@ -671,16 +657,16 @@ namespace etl { public: - typedef etl::expected this_type; + typedef etl::expected this_type; typedef void value_type; typedef TError error_type; typedef etl::unexpected unexpected_type; - + //******************************************* /// Default constructor //******************************************* ETL_CONSTEXPR14 - expected() + expected() { } @@ -688,7 +674,7 @@ namespace etl /// Copy construct from unexpected //******************************************* ETL_CONSTEXPR14 - expected(const unexpected_type& ue_) + expected(const unexpected_type& ue_) : storage(ue_.error()) { } @@ -697,7 +683,7 @@ namespace etl /// Move construct from unexpected //******************************************* ETL_CONSTEXPR14 - expected(unexpected_type&& ue_) + expected(unexpected_type&& ue_) : storage(etl::move(ue_.error())) { } @@ -768,8 +754,8 @@ namespace etl /// Returns true if expected has a value //******************************************* ETL_NODISCARD - ETL_CONSTEXPR14 - bool has_value() const + ETL_CONSTEXPR14 + bool has_value() const { return (storage.index() != Error_Type); } @@ -778,8 +764,8 @@ namespace etl /// Returns true if expected has a value //******************************************* ETL_NODISCARD - ETL_CONSTEXPR14 - operator bool() const + ETL_CONSTEXPR14 + operator bool() const { return has_value(); } @@ -789,8 +775,8 @@ namespace etl /// Undefined behaviour if an error has not been set. //******************************************* ETL_NODISCARD - ETL_CONSTEXPR14 - error_type& error()& ETL_NOEXCEPT + ETL_CONSTEXPR14 + error_type& error()& ETL_NOEXCEPT { return etl::get(storage); } @@ -800,8 +786,8 @@ namespace etl /// Undefined behaviour if an error has not been set. //******************************************* ETL_NODISCARD - ETL_CONSTEXPR14 - const error_type& error() const& ETL_NOEXCEPT + ETL_CONSTEXPR14 + const error_type& error() const& ETL_NOEXCEPT { return etl::get(storage); } @@ -811,8 +797,8 @@ namespace etl /// Undefined behaviour if an error has not been set. //******************************************* ETL_NODISCARD - ETL_CONSTEXPR14 - error_type&& error() && ETL_NOEXCEPT + ETL_CONSTEXPR14 + error_type&& error() && ETL_NOEXCEPT { return etl::move(etl::get(storage)); } @@ -822,8 +808,8 @@ namespace etl /// Undefined behaviour if an error has not been set. //******************************************* ETL_NODISCARD - ETL_CONSTEXPR14 - const error_type&& error() const&& ETL_NOEXCEPT + ETL_CONSTEXPR14 + const error_type&& error() const&& ETL_NOEXCEPT { return etl::move(etl::get(storage)); } @@ -861,3 +847,4 @@ void swap(etl::unexpected& lhs, etl::unexpected& rhs) } #endif +