From 947bdc4b7ad2e9cdd07726567d9f104a7456c962 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 6 Aug 2026 19:27:57 +0100 Subject: [PATCH] Convert to C++11 style type traits --- include/etl/optional.h | 110 ++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 61 deletions(-) diff --git a/include/etl/optional.h b/include/etl/optional.h index 3b3ed50b..a68bdc0f 100644 --- a/include/etl/optional.h +++ b/include/etl/optional.h @@ -185,10 +185,9 @@ namespace etl /// Constructs T in-place from U&&, without requiring T to be /// copy/move constructible. //*************************************************************************** - template ::value && !etl::is_same::type, etl::in_place_t>::value - && !etl::is_same::type, optional_impl>::value, - int>::type = 0> + template ::value && !etl::is_same, etl::in_place_t>::value + && !etl::is_same, optional_impl>::value, + int> = 0> ETL_CONSTEXPR20_STL optional_impl(U&& value_) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible::value)) { storage.construct(etl::forward(value_)); @@ -287,9 +286,7 @@ namespace etl /// Assignment operator from value type. //*************************************************************************** #if ETL_USING_CPP11 - template ::value && !etl::is_same::type, optional_impl>::value, - int>::type = 0> + template ::value && !etl::is_same, optional_impl>::value, int> = 0> ETL_CONSTEXPR20_STL optional_impl& operator=(U&& value_) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible::value)) { storage.construct(etl::forward(value_)); @@ -522,8 +519,7 @@ namespace etl //******************************************* /// Emplaces a value from initializer_list and arbitrary constructor arguments. //******************************************* - template &, Args...>::value, int>::type = 0 > + template &, Args...>::value, int> = 0 > ETL_CONSTEXPR20_STL T& emplace(std::initializer_list ilist, Args&&... args) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible&, Args...>::value)) { @@ -1228,8 +1224,8 @@ namespace etl }; } // namespace private_optional -#define ETL_OPTIONAL_ENABLE_CPP14 typename etl::enable_if< etl::is_pod::type>::value, int>::type = 0 -#define ETL_OPTIONAL_ENABLE_CPP20_STL typename etl::enable_if< !etl::is_pod::type>::value, int>::type = 0 +#define ETL_OPTIONAL_ENABLE_CPP14 etl::enable_if_t< etl::is_pod::type>::value, int> = 0 +#define ETL_OPTIONAL_ENABLE_CPP20_STL etl::enable_if_t< !etl::is_pod::type>::value, int> = 0 #define ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 \ ETL_CONSTEXPR14 typename etl::enable_if< etl::is_pod::type>::value, bool>::type @@ -1330,12 +1326,10 @@ namespace etl /// Constructs T in-place from U&&, without requiring T to be /// copy/move constructible. //*************************************************************************** - template < typename U, - typename etl::enable_if< etl::is_constructible::value && !etl::is_same::type, etl::optional>::value - && !etl::is_same::type, etl::in_place_t>::value - && !etl::is_same::type, etl::nullopt_t>::value - && etl::is_pod::type>::value, - int>::type = 0> + template < typename U, etl::enable_if_t< etl::is_constructible::value && !etl::is_same, etl::optional>::value + && !etl::is_same, etl::in_place_t>::value + && !etl::is_same, etl::nullopt_t>::value && etl::is_pod>::value, + int> = 0> ETL_CONSTEXPR14 optional(U&& value_) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible::value)) : impl_t(etl::forward(value_)) { @@ -1344,12 +1338,10 @@ namespace etl //*************************************************************************** /// Converting constructor from value type. //*************************************************************************** - template < typename U, - typename etl::enable_if< etl::is_constructible::value && !etl::is_same::type, etl::optional>::value - && !etl::is_same::type, etl::in_place_t>::value - && !etl::is_same::type, etl::nullopt_t>::value - && !etl::is_pod::type>::value, - int>::type = 0> + template < typename U, etl::enable_if_t< etl::is_constructible::value && !etl::is_same, etl::optional>::value + && !etl::is_same, etl::in_place_t>::value + && !etl::is_same, etl::nullopt_t>::value && !etl::is_pod>::value, + int> = 0> ETL_CONSTEXPR20_STL optional(U&& value_) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible::value)) : impl_t(etl::forward(value_)) { @@ -1457,11 +1449,9 @@ namespace etl //*************************************************************************** /// Converting assignment operator from value type. //*************************************************************************** - template < typename U, - typename etl::enable_if< etl::is_constructible::value && !etl::is_same::type, etl::optional>::value - && !etl::is_same::type, etl::nullopt_t>::value - && etl::is_pod::type>::value, - int>::type = 0> + template < typename U, etl::enable_if_t< etl::is_constructible::value && !etl::is_same, etl::optional>::value + && !etl::is_same, etl::nullopt_t>::value && etl::is_pod>::value, + int> = 0> ETL_CONSTEXPR14 optional& operator=(U&& value_) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible::value)) { impl_t::operator=(etl::forward(value_)); @@ -1472,11 +1462,9 @@ namespace etl //*************************************************************************** /// Converting assignment operator from value type. //*************************************************************************** - template < typename U, - typename etl::enable_if< etl::is_constructible::value && !etl::is_same::type, etl::optional>::value - && !etl::is_same::type, etl::nullopt_t>::value - && !etl::is_pod::type>::value, - int>::type = 0> + template < typename U, etl::enable_if_t< etl::is_constructible::value && !etl::is_same, etl::optional>::value + && !etl::is_same, etl::nullopt_t>::value && !etl::is_pod>::value, + int> = 0> ETL_CONSTEXPR20_STL optional& operator=(U&& value_) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible::value)) { impl_t::operator=(etl::forward(value_)); @@ -1532,73 +1520,73 @@ namespace etl } #if ETL_USING_CPP11 - template ::type>::type> + template >> auto transform(F&& f) & -> etl::optional { return transform_impl(etl::forward(f), *this); } - template < typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result::type>::type> + template < typename F, typename U = etl::remove_cv_t< etl::invoke_result_t>> auto transform(F&& f) const& -> etl::optional { return transform_impl(etl::forward(f), *this); } - template ::type>::type> + template >> auto transform(F&& f) && -> etl::optional { return transform_impl(etl::forward(f), etl::move(*this)); } - template < typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result::type>::type> + template < typename F, typename U = etl::remove_cv_t< etl::invoke_result_t>> auto transform(F&& f) const&& -> etl::optional { return transform_impl(etl::forward(f), etl::move(*this)); } - template ::type>::type> + template >> auto and_then(F&& f) & -> U { return and_then_impl(etl::forward(f), *this); } - template < typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result::type>::type> + template < typename F, typename U = etl::remove_cv_t< etl::invoke_result_t>> auto and_then(F&& f) const& -> U { return and_then_impl(etl::forward(f), *this); } - template ::type>::type> + template >> auto and_then(F&& f) && -> U { return and_then_impl(etl::forward(f), etl::move(*this)); } - template < typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result::type>::type> + template < typename F, typename U = etl::remove_cv_t< etl::invoke_result_t>> auto and_then(F&& f) const&& -> U { return and_then_impl(etl::forward(f), etl::move(*this)); } - template ::type>::type> + template >> auto or_else(F&& f) & -> U { return or_else_impl(etl::forward(f), *this); } - template < typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result::type>::type> + template < typename F, typename U = etl::remove_cv_t>> auto or_else(F&& f) const& -> U { return or_else_impl(etl::forward(f), *this); } - template ::type>::type> + template >> auto or_else(F&& f) && -> U { return or_else_impl(etl::forward(f), etl::move(*this)); } - template < typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result::type>::type> + template < typename F, typename U = etl::remove_cv_t< etl::invoke_result_t>> auto or_else(F&& f) const&& -> U { return or_else_impl(etl::forward(f), etl::move(*this)); @@ -1606,7 +1594,7 @@ namespace etl private: - template < typename F, typename TOpt, typename TRet, typename TValueRef, typename = typename etl::enable_if::value>::type> + template < typename F, typename TOpt, typename TRet, typename TValueRef, typename = etl::enable_if_t::value>> auto transform_impl(F&& f, TOpt&& opt) const -> etl::optional { if (opt.has_value()) @@ -1620,7 +1608,7 @@ namespace etl } template < typename F, typename TOpt, typename TRet, typename TValueRef, - typename = typename etl::enable_if::value && etl::is_optional::value>::type> + typename = etl::enable_if_t::value && etl::is_optional::value>> auto and_then_impl(F&& f, TOpt&& opt) const -> TRet { if (opt.has_value()) @@ -1633,9 +1621,9 @@ namespace etl } } - template < typename F, typename TOpt, typename TRet, - typename = typename etl::enable_if< !etl::is_void::value && etl::is_optional::value - && etl::is_same::value>::type> + template < + typename F, typename TOpt, typename TRet, + typename = etl::enable_if_t< !etl::is_void::value && etl::is_optional::value && etl::is_same::value>> auto or_else_impl(F&& f, TOpt&& opt) const -> TRet { if (opt.has_value()) @@ -2261,17 +2249,17 @@ namespace etl /// This overload participates in overload resolution only if /// `etl::is_constructible_v` is true. //*************************************************************************** - template ::value, int>::type = 0, // + template ::value, int> = 0, // typename U = T, ETL_OPTIONAL_ENABLE_CPP14> - ETL_CONSTEXPR14 etl::optional make_optional(Args&&... args) // + ETL_CONSTEXPR14 etl::optional make_optional(Args&&... args) // ETL_NOEXCEPT_IF((etl::is_nothrow_constructible::value)) { return etl::optional(etl::in_place_t{}, etl::forward(args)...); } - template ::value, int>::type = 0, // - typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL> + template ::value, int> = 0, // + typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL> ETL_CONSTEXPR20_STL etl::optional make_optional(Args&&... args) // ETL_NOEXCEPT_IF((etl::is_nothrow_constructible::value)) { @@ -2285,17 +2273,17 @@ namespace etl /// This overload participates in overload resolution only if /// `etl::is_constructible_v&, Args...>` is true. //*************************************************************************** - template &, Args...>::value, int>::type = 0, // + template &, Args...>::value, int> = 0, // typename U = T, ETL_OPTIONAL_ENABLE_CPP14> ETL_CONSTEXPR14 etl::optional make_optional(std::initializer_list ilist, Args&&... args) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible&, Args...>::value)) { return etl::optional(etl::in_place_t{}, ilist, etl::forward(args)...); } - template &, Args...>::value, int>::type = 0, // - typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL> + template &, Args...>::value, int> = 0, // + typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL> ETL_CONSTEXPR20_STL etl::optional make_optional(std::initializer_list ilist, Args&&... args) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible&, Args...>::value)) {