mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Added etl::type_list to etl::nth_type
This commit is contained in:
parent
2cae496620
commit
2862b3b247
@ -31,6 +31,7 @@ SOFTWARE.
|
||||
|
||||
#include "platform.h"
|
||||
#include "static_assert.h"
|
||||
#include "type_list.h"
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
namespace etl
|
||||
@ -60,6 +61,13 @@ namespace etl
|
||||
using type = typename private_nth_type::nth_type_helper<Index, TTypes...>::type;
|
||||
};
|
||||
|
||||
//***********************************
|
||||
template <size_t Index, typename... TTypes>
|
||||
struct nth_type<Index, etl::type_list<TTypes...>> : public nth_type<Index, TTypes...>
|
||||
{
|
||||
using nth_type<Index, TTypes...>::type;
|
||||
};
|
||||
|
||||
//***********************************
|
||||
template <size_t Index, typename... TTypes>
|
||||
using nth_type_t = typename nth_type<Index, TTypes...>::type;
|
||||
|
||||
@ -29,6 +29,7 @@ SOFTWARE.
|
||||
#include "unit_test_framework.h"
|
||||
|
||||
#include "etl/nth_type.h"
|
||||
#include "etl/type_list.h"
|
||||
#include <type_traits>
|
||||
|
||||
namespace
|
||||
@ -42,5 +43,15 @@ namespace
|
||||
CHECK((std::is_same<etl::nth_type_t<1, int, long, double>, long>::value));
|
||||
CHECK((std::is_same<etl::nth_type_t<2, int, long, double>, double>::value));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_nth_type_from_type_list)
|
||||
{
|
||||
using types = etl::type_list<int, long, double>;
|
||||
|
||||
CHECK((std::is_same<etl::nth_type_t<0, types>, int>::value));
|
||||
CHECK((std::is_same<etl::nth_type_t<1, types>, long>::value));
|
||||
CHECK((std::is_same<etl::nth_type_t<2, types>, double>::value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user