Sopporting changes for etl::tuple

This commit is contained in:
John Wellbelove 2025-04-14 09:51:28 +01:00
parent 2fd887ecc3
commit d9af24f34b
4 changed files with 111 additions and 42 deletions

View File

@ -112,6 +112,39 @@ namespace etl
return reference_wrapper<const T>(t.get());
}
//***************************************************************************
/// unwrap_reference.
//***************************************************************************
template <class T>
struct unwrap_reference
{
typedef T type;
};
template <typename U>
struct unwrap_reference<etl::reference_wrapper<U> >
{
typedef U& type;
};
#if ETL_USING_CPP11
template <typename T>
using unwrap_reference_t = typename unwrap_reference<T>::type;
#endif
//***************************************************************************
/// unwrap_ref_decay.
//***************************************************************************
template <typename T>
struct unwrap_ref_decay : etl::unwrap_reference<typename etl::decay<T>::type> {};
#if ETL_USING_CPP11
template <typename T>
using unwrap_ref_decay_t = typename unwrap_ref_decay<T>::type;
#endif
//***************************************************************************
/// unary_function
//***************************************************************************
template <typename TArgumentType, typename TResultType>
struct unary_function
@ -120,6 +153,8 @@ namespace etl
typedef TResultType result_type;
};
//***************************************************************************
/// binary_function
//***************************************************************************
template <typename TFirstArgumentType, typename TSecondArgumentType, typename TResultType>
struct binary_function

View File

@ -32,50 +32,41 @@ SOFTWARE.
#include "platform.h"
#include "static_assert.h"
#if ETL_NOT_USING_CPP11
#if !defined(ETL_IN_UNIT_TEST)
#error NOT SUPPORTED FOR C++03 OR BELOW
#endif
#else
namespace etl
{
#if ETL_USING_CPP11
namespace private_nth_type
{
//***********************************
template <size_t N, typename T1, typename... TRest>
struct nth_type_helper
{
using type = typename nth_type_helper<N - 1U, TRest...>::type;
};
//***************************************************************************
/// Finds the nth type in a variadic type parameter.
//***************************************************************************
template <typename T1, typename... TRest>
struct nth_type_helper<0U, T1, TRest...>
{
using type = T1;
};
}
//***********************************
template <size_t N, typename... TTypes>
struct nth_type;
//***************************************************************************
/// Finds the nth type in a variadic type parameter.
//***************************************************************************
template <size_t N, typename T1, typename... TRest>
struct nth_type<N, T1, TRest...>
struct nth_type
{
ETL_STATIC_ASSERT(N <= sizeof...(TRest), "etl::nth_type out of range for type list");
ETL_STATIC_ASSERT(N < sizeof...(TTypes), "etl::nth_type index 'N' out of bounds");
using type = typename nth_type<N - 1U, TRest...>::type;
using type = typename private_nth_type::nth_type_helper<N, TTypes...>::type;
};
//***************************************************************************
/// Finds the 0thth type in a variadic type parameter.
//***************************************************************************
template <typename T1, typename... TRest>
struct nth_type<0U, T1, TRest...>
{
using type = T1;
};
//***************************************************************************
/// Handles a zero length type list.
//***************************************************************************
template <size_t N>
struct nth_type<N>
{
};
//***************************************************************************
/// Finds the nth type in a variadic type parameter.
//***************************************************************************
//***********************************
template <size_t N, typename... TTypes>
using nth_type_t = typename nth_type<N, TTypes...>::type;
#endif
}
#endif
#endif

View File

@ -34,6 +34,9 @@ SOFTWARE.
#include "platform.h"
#include "type_traits.h"
#include "private/tuple_element.h"
#include "private/tuple_size.h"
#if defined(ETL_IN_UNIT_TEST) || ETL_USING_STL
#if ETL_USING_CPP11
#include <utility>
@ -325,6 +328,33 @@ namespace etl
}
#endif
#if ETL_USING_CPP11
//******************************************************************************
template <size_t Index, typename T1, typename T2>
struct tuple_element<Index, ETL_OR_STD::pair<T1, T2> >
{
ETL_STATIC_ASSERT(Index < 2U, "pair has only 2 elements");
};
template <typename T1, typename T2>
struct tuple_element<0U, ETL_OR_STD::pair<T1, T2> >
{
typedef T1 type;
};
template <typename T1, typename T2>
struct tuple_element<1U, ETL_OR_STD::pair<T1, T2> >
{
typedef T2 type;
};
//******************************************************************************
template <typename T1, typename T2>
struct tuple_size<ETL_OR_STD::pair<T1, T2>> : public etl::integral_constant<size_t, 2U>
{
};
#endif
//******************************************************************************
template <typename T1, typename T2>
inline void swap(pair<T1, T2>& a, pair<T1, T2>& b)
@ -332,7 +362,7 @@ namespace etl
a.swap(b);
}
/// Two pairs of the same type are equal iff their members are equal.
/// Two pairs of the same type are equal if their members are equal.
template <typename T1, typename T2>
inline bool operator ==(const pair<T1, T2>& a, const pair<T1, T2>& b)
{
@ -496,7 +526,7 @@ namespace etl
ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Integral types only");
using value_type = T;
typedef T value_type;
static ETL_CONSTEXPR size_t size() ETL_NOEXCEPT
{
@ -504,7 +534,7 @@ namespace etl
}
};
namespace private_index_sequence
namespace private_integer_sequence
{
template <size_t N, typename IndexSeq>
struct make_index_sequence;
@ -524,11 +554,17 @@ namespace etl
//***********************************
template <size_t N>
using make_index_sequence = typename private_index_sequence::make_index_sequence<N, etl::integer_sequence<size_t>>::type;
using make_index_sequence = typename private_integer_sequence::make_index_sequence<N, etl::integer_sequence<size_t>>::type;
template <typename... TTypes>
using make_index_sequence_for = typename private_integer_sequence::make_index_sequence<sizeof...(TTypes), etl::integer_sequence<size_t>>::type;
//***********************************
template <size_t... Indices>
using index_sequence = etl::integer_sequence<size_t, Indices...>;
template <typename... TTypes>
using index_sequence_for = typename etl::make_index_sequence_for<TTypes...>;
#endif
//***************************************************************************
@ -621,7 +657,7 @@ namespace etl
//*********************************
/// Const function operator.
//*********************************
//*********************************
constexpr TReturn operator()(TParams... args) const
{
return ptr(etl::forward<TParams>(args)...);

View File

@ -209,6 +209,13 @@ public:
other.valid = false;
}
TestDataM(const TestDataM&& other) noexcept
: value(std::move(other.value))
, valid(true)
{
other.valid = false;
}
virtual ~TestDataM()
{
valid = false;
@ -249,8 +256,8 @@ public:
return valid;
}
T value;
bool valid;
T value;
mutable bool valid;
private: