Convert to C++11 style type traits

This commit is contained in:
John Wellbelove 2026-08-06 19:27:57 +01:00
parent 14f675df08
commit 947bdc4b7a

View File

@ -185,10 +185,9 @@ 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<T, U&&>::value && !etl::is_same<typename etl::decay<U>::type, etl::in_place_t>::value
&& !etl::is_same<typename etl::decay<U>::type, optional_impl>::value,
int>::type = 0>
template <typename U, etl::enable_if_t< etl::is_constructible<T, U&&>::value && !etl::is_same<etl::decay_t<U>, etl::in_place_t>::value
&& !etl::is_same<etl::decay_t<U>, optional_impl>::value,
int> = 0>
ETL_CONSTEXPR20_STL optional_impl(U&& value_) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, U&&>::value))
{
storage.construct(etl::forward<U>(value_));
@ -287,9 +286,7 @@ namespace etl
/// Assignment operator from value type.
//***************************************************************************
#if ETL_USING_CPP11
template <typename U,
typename etl::enable_if< etl::is_constructible<T, U&&>::value && !etl::is_same<typename etl::decay<U>::type, optional_impl>::value,
int>::type = 0>
template <typename U, etl::enable_if_t< etl::is_constructible<T, U&&>::value && !etl::is_same<etl::decay_t<U>, optional_impl>::value, int> = 0>
ETL_CONSTEXPR20_STL optional_impl& operator=(U&& value_) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, U&&>::value))
{
storage.construct(etl::forward<U>(value_));
@ -522,8 +519,7 @@ namespace etl
//*******************************************
/// Emplaces a value from initializer_list and arbitrary constructor arguments.
//*******************************************
template <typename U, typename... Args,
typename etl::enable_if< etl::is_constructible<T, std::initializer_list<U>&, Args...>::value, int>::type = 0 >
template <typename U, typename... Args, etl::enable_if_t< etl::is_constructible<T, std::initializer_list<U>&, Args...>::value, int> = 0 >
ETL_CONSTEXPR20_STL T& emplace(std::initializer_list<U> ilist, Args&&... args)
ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, std::initializer_list<U>&, Args...>::value))
{
@ -1228,8 +1224,8 @@ namespace etl
};
} // namespace private_optional
#define ETL_OPTIONAL_ENABLE_CPP14 typename etl::enable_if< etl::is_pod<typename etl::remove_cv<U>::type>::value, int>::type = 0
#define ETL_OPTIONAL_ENABLE_CPP20_STL typename etl::enable_if< !etl::is_pod<typename etl::remove_cv<U>::type>::value, int>::type = 0
#define ETL_OPTIONAL_ENABLE_CPP14 etl::enable_if_t< etl::is_pod<typename etl::remove_cv<U>::type>::value, int> = 0
#define ETL_OPTIONAL_ENABLE_CPP20_STL etl::enable_if_t< !etl::is_pod<typename etl::remove_cv<U>::type>::value, int> = 0
#define ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 \
ETL_CONSTEXPR14 typename etl::enable_if< etl::is_pod<typename etl::remove_cv<T>::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<T, U&&>::value && !etl::is_same<typename etl::decay<U>::type, etl::optional<T>>::value
&& !etl::is_same<typename etl::decay<U>::type, etl::in_place_t>::value
&& !etl::is_same<typename etl::decay<U>::type, etl::nullopt_t>::value
&& etl::is_pod<typename etl::remove_cv<T>::type>::value,
int>::type = 0>
template < typename U, etl::enable_if_t< etl::is_constructible<T, U&&>::value && !etl::is_same<etl::decay_t<U>, etl::optional<T>>::value
&& !etl::is_same<etl::decay_t<U>, etl::in_place_t>::value
&& !etl::is_same<etl::decay_t<U>, etl::nullopt_t>::value && etl::is_pod<etl::remove_cv_t<T>>::value,
int> = 0>
ETL_CONSTEXPR14 optional(U&& value_) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, U&&>::value))
: impl_t(etl::forward<U>(value_))
{
@ -1344,12 +1338,10 @@ namespace etl
//***************************************************************************
/// Converting constructor from value type.
//***************************************************************************
template < typename U,
typename etl::enable_if< etl::is_constructible<T, U&&>::value && !etl::is_same<typename etl::decay<U>::type, etl::optional<T>>::value
&& !etl::is_same<typename etl::decay<U>::type, etl::in_place_t>::value
&& !etl::is_same<typename etl::decay<U>::type, etl::nullopt_t>::value
&& !etl::is_pod<typename etl::remove_cv<T>::type>::value,
int>::type = 0>
template < typename U, etl::enable_if_t< etl::is_constructible<T, U&&>::value && !etl::is_same<etl::decay_t<U>, etl::optional<T>>::value
&& !etl::is_same<etl::decay_t<U>, etl::in_place_t>::value
&& !etl::is_same<etl::decay_t<U>, etl::nullopt_t>::value && !etl::is_pod<etl::remove_cv_t<T>>::value,
int> = 0>
ETL_CONSTEXPR20_STL optional(U&& value_) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, U&&>::value))
: impl_t(etl::forward<U>(value_))
{
@ -1457,11 +1449,9 @@ namespace etl
//***************************************************************************
/// Converting assignment operator from value type.
//***************************************************************************
template < typename U,
typename etl::enable_if< etl::is_constructible<T, U&&>::value && !etl::is_same<typename etl::decay<U>::type, etl::optional<T>>::value
&& !etl::is_same<typename etl::decay<U>::type, etl::nullopt_t>::value
&& etl::is_pod<typename etl::remove_cv<T>::type>::value,
int>::type = 0>
template < typename U, etl::enable_if_t< etl::is_constructible<T, U&&>::value && !etl::is_same<etl::decay_t<U>, etl::optional<T>>::value
&& !etl::is_same<etl::decay_t<U>, etl::nullopt_t>::value && etl::is_pod<etl::remove_cv_t<T>>::value,
int> = 0>
ETL_CONSTEXPR14 optional& operator=(U&& value_) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, U&&>::value))
{
impl_t::operator=(etl::forward<U>(value_));
@ -1472,11 +1462,9 @@ namespace etl
//***************************************************************************
/// Converting assignment operator from value type.
//***************************************************************************
template < typename U,
typename etl::enable_if< etl::is_constructible<T, U&&>::value && !etl::is_same<typename etl::decay<U>::type, etl::optional<T>>::value
&& !etl::is_same<typename etl::decay<U>::type, etl::nullopt_t>::value
&& !etl::is_pod<typename etl::remove_cv<T>::type>::value,
int>::type = 0>
template < typename U, etl::enable_if_t< etl::is_constructible<T, U&&>::value && !etl::is_same<etl::decay_t<U>, etl::optional<T>>::value
&& !etl::is_same<etl::decay_t<U>, etl::nullopt_t>::value && !etl::is_pod<etl::remove_cv_t<T>>::value,
int> = 0>
ETL_CONSTEXPR20_STL optional& operator=(U&& value_) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, U&&>::value))
{
impl_t::operator=(etl::forward<U>(value_));
@ -1532,73 +1520,73 @@ namespace etl
}
#if ETL_USING_CPP11
template <typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void, T&>::type>::type>
template <typename F, typename U = etl::remove_cv_t<etl::invoke_result_t<F, T&>>>
auto transform(F&& f) & -> etl::optional<U>
{
return transform_impl<F, optional&, U, T&>(etl::forward<F>(f), *this);
}
template < typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void, const T&>::type>::type>
template < typename F, typename U = etl::remove_cv_t< etl::invoke_result_t<F, const T&>>>
auto transform(F&& f) const& -> etl::optional<U>
{
return transform_impl<F, const optional&, U, const T&>(etl::forward<F>(f), *this);
}
template <typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void, T&&>::type>::type>
template <typename F, typename U = etl::remove_cv_t< etl::invoke_result_t<F, T&&>>>
auto transform(F&& f) && -> etl::optional<U>
{
return transform_impl<F, optional&&, U, T&&>(etl::forward<F>(f), etl::move(*this));
}
template < typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void, const T&&>::type>::type>
template < typename F, typename U = etl::remove_cv_t< etl::invoke_result_t<F, const T&&>>>
auto transform(F&& f) const&& -> etl::optional<U>
{
return transform_impl<F, const optional&&, U, const T&&>(etl::forward<F>(f), etl::move(*this));
}
template <typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void, T&>::type>::type>
template <typename F, typename U = etl::remove_cv_t< etl::invoke_result_t<F, T&>>>
auto and_then(F&& f) & -> U
{
return and_then_impl<F, optional&, U, T&>(etl::forward<F>(f), *this);
}
template < typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void, const T&>::type>::type>
template < typename F, typename U = etl::remove_cv_t< etl::invoke_result_t<F, const T&>>>
auto and_then(F&& f) const& -> U
{
return and_then_impl<F, const optional&, U, const T&>(etl::forward<F>(f), *this);
}
template <typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void, T&&>::type>::type>
template <typename F, typename U = etl::remove_cv_t< etl::invoke_result_t<F, T&&>>>
auto and_then(F&& f) && -> U
{
return and_then_impl<F, optional&&, U, T&&>(etl::forward<F>(f), etl::move(*this));
}
template < typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void, const T&&>::type>::type>
template < typename F, typename U = etl::remove_cv_t< etl::invoke_result_t<F, const T&&>>>
auto and_then(F&& f) const&& -> U
{
return and_then_impl<F, const optional&&, U, const T&&>(etl::forward<F>(f), etl::move(*this));
}
template <typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void>::type>::type>
template <typename F, typename U = etl::remove_cv_t<etl::invoke_result_t<F>>>
auto or_else(F&& f) & -> U
{
return or_else_impl<F, optional&, U>(etl::forward<F>(f), *this);
}
template < typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void>::type>::type>
template < typename F, typename U = etl::remove_cv_t<etl::invoke_result_t<F>>>
auto or_else(F&& f) const& -> U
{
return or_else_impl<F, const optional&, U>(etl::forward<F>(f), *this);
}
template <typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void>::type>::type>
template <typename F, typename U = etl::remove_cv_t< etl::invoke_result_t<F>>>
auto or_else(F&& f) && -> U
{
return or_else_impl<F, optional&&, U>(etl::forward<F>(f), etl::move(*this));
}
template < typename F, typename U = typename etl::remove_cvref< typename etl::invoke_result<F, void>::type>::type>
template < typename F, typename U = etl::remove_cv_t< etl::invoke_result_t<F>>>
auto or_else(F&& f) const&& -> U
{
return or_else_impl<F, const optional&&, U>(etl::forward<F>(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<!etl::is_void<TRet>::value>::type>
template < typename F, typename TOpt, typename TRet, typename TValueRef, typename = etl::enable_if_t<!etl::is_void<TRet>::value>>
auto transform_impl(F&& f, TOpt&& opt) const -> etl::optional<TRet>
{
if (opt.has_value())
@ -1620,7 +1608,7 @@ namespace etl
}
template < typename F, typename TOpt, typename TRet, typename TValueRef,
typename = typename etl::enable_if<!etl::is_void<TRet>::value && etl::is_optional<TRet>::value>::type>
typename = etl::enable_if_t<!etl::is_void<TRet>::value && etl::is_optional<TRet>::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<TRet>::value && etl::is_optional<TRet>::value
&& etl::is_same<typename TRet::value_type, T>::value>::type>
template <
typename F, typename TOpt, typename TRet,
typename = etl::enable_if_t< !etl::is_void<TRet>::value && etl::is_optional<TRet>::value && etl::is_same<typename TRet::value_type, T>::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<T, Args...>` is true.
//***************************************************************************
template <typename T, typename... Args, //
typename etl::enable_if< etl::is_constructible<T, Args...>::value, int>::type = 0, //
template <typename T, typename... Args, //
etl::enable_if_t< etl::is_constructible<T, Args...>::value, int> = 0, //
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
ETL_CONSTEXPR14 etl::optional<T> make_optional(Args&&... args) //
ETL_CONSTEXPR14 etl::optional<T> make_optional(Args&&... args) //
ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, Args...>::value))
{
return etl::optional<T>(etl::in_place_t{}, etl::forward<Args>(args)...);
}
template <typename T, typename... Args, //
typename etl::enable_if< etl::is_constructible<T, Args...>::value, int>::type = 0, //
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
template <typename T, typename... Args, //
etl::enable_if_t< etl::is_constructible<T, Args...>::value, int> = 0, //
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
ETL_CONSTEXPR20_STL etl::optional<T> make_optional(Args&&... args) //
ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, Args...>::value))
{
@ -2285,17 +2273,17 @@ namespace etl
/// This overload participates in overload resolution only if
/// `etl::is_constructible_v<T, std::initializer_list<U>&, Args...>` is true.
//***************************************************************************
template <typename T, typename TL, typename... Args, //
typename etl::enable_if< etl::is_constructible<T, std::initializer_list<TL>&, Args...>::value, int>::type = 0, //
template <typename T, typename TL, typename... Args, //
etl::enable_if_t< etl::is_constructible<T, std::initializer_list<TL>&, Args...>::value, int> = 0, //
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
ETL_CONSTEXPR14 etl::optional<T> make_optional(std::initializer_list<TL> ilist, Args&&... args)
ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, std::initializer_list<TL>&, Args...>::value))
{
return etl::optional<T>(etl::in_place_t{}, ilist, etl::forward<Args>(args)...);
}
template <typename T, typename TL, typename... Args, //
typename etl::enable_if< etl::is_constructible<T, std::initializer_list<TL>&, Args...>::value, int>::type = 0, //
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
template <typename T, typename TL, typename... Args, //
etl::enable_if_t< etl::is_constructible<T, std::initializer_list<TL>&, Args...>::value, int> = 0, //
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
ETL_CONSTEXPR20_STL etl::optional<T> make_optional(std::initializer_list<TL> ilist, Args&&... args)
ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, std::initializer_list<TL>&, Args...>::value))
{