Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
variadic type_list
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewcorrigan committed Oct 12, 2020
1 parent 22e6dd1 commit 6ff6c6d
Showing 1 changed file with 26 additions and 112 deletions.
138 changes: 26 additions & 112 deletions testing/unittest/meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,10 @@ namespace unittest
struct null_type {};

// this type encapsulates a list of
// up to 10 types
template<typename T0 = null_type,
typename T1 = null_type,
typename T2 = null_type,
typename T3 = null_type,
typename T4 = null_type,
typename T5 = null_type,
typename T6 = null_type,
typename T7 = null_type,
typename T8 = null_type,
typename T9 = null_type,
typename T10 = null_type,
typename T11 = null_type,
typename T12 = null_type,
typename T13 = null_type,
typename T14 = null_type,
typename T15 = null_type,
typename T16 = null_type,
typename T17 = null_type,
typename T18 = null_type,
typename T19 = null_type>
// types
template<typename... Ts>
struct type_list
{
typedef T0 type_0;
typedef T1 type_1;
typedef T2 type_2;
typedef T3 type_3;
typedef T4 type_4;
typedef T5 type_5;
typedef T6 type_6;
typedef T7 type_7;
typedef T8 type_8;
typedef T9 type_9;
typedef T10 type_10;
typedef T11 type_11;
typedef T12 type_12;
typedef T13 type_13;
typedef T14 type_14;
typedef T15 type_15;
typedef T16 type_16;
typedef T17 type_17;
typedef T18 type_18;
typedef T19 type_19;
};

// this type provides a way of indexing
Expand All @@ -66,26 +27,17 @@ template<typename List, unsigned int i>
typedef null_type type;
};

template<typename List> struct get_type<List,0> { typedef typename List::type_0 type; };
template<typename List> struct get_type<List,1> { typedef typename List::type_1 type; };
template<typename List> struct get_type<List,2> { typedef typename List::type_2 type; };
template<typename List> struct get_type<List,3> { typedef typename List::type_3 type; };
template<typename List> struct get_type<List,4> { typedef typename List::type_4 type; };
template<typename List> struct get_type<List,5> { typedef typename List::type_5 type; };
template<typename List> struct get_type<List,6> { typedef typename List::type_6 type; };
template<typename List> struct get_type<List,7> { typedef typename List::type_7 type; };
template<typename List> struct get_type<List,8> { typedef typename List::type_8 type; };
template<typename List> struct get_type<List,9> { typedef typename List::type_9 type; };
template<typename List> struct get_type<List,10> { typedef typename List::type_10 type; };
template<typename List> struct get_type<List,11> { typedef typename List::type_11 type; };
template<typename List> struct get_type<List,12> { typedef typename List::type_12 type; };
template<typename List> struct get_type<List,13> { typedef typename List::type_13 type; };
template<typename List> struct get_type<List,14> { typedef typename List::type_14 type; };
template<typename List> struct get_type<List,15> { typedef typename List::type_15 type; };
template<typename List> struct get_type<List,16> { typedef typename List::type_16 type; };
template<typename List> struct get_type<List,17> { typedef typename List::type_17 type; };
template<typename List> struct get_type<List,18> { typedef typename List::type_18 type; };
template<typename List> struct get_type<List,19> { typedef typename List::type_19 type; };
template<typename T, typename... Ts>
struct get_type<type_list<T, Ts...>, 0>
{
typedef T type;
};

template<typename T, typename... Ts, unsigned int i>
struct get_type<type_list<T, Ts...>, i>
{
typedef typename get_type<type_list<Ts...>, i - 1>::type type;
};

// this type and its specialization provides a way to
// iterate over a type_list, and
Expand Down Expand Up @@ -196,64 +148,26 @@ template<template <typename,typename> class Template>
// the Type_list's types
template<typename TypeList,
template <typename> class Template>
struct transform1
{
typedef typename ApplyTemplate1<Template, typename get_type<TypeList,0>::type>::type type_0;
typedef typename ApplyTemplate1<Template, typename get_type<TypeList,1>::type>::type type_1;
typedef typename ApplyTemplate1<Template, typename get_type<TypeList,2>::type>::type type_2;
typedef typename ApplyTemplate1<Template, typename get_type<TypeList,3>::type>::type type_3;
typedef typename ApplyTemplate1<Template, typename get_type<TypeList,4>::type>::type type_4;
typedef typename ApplyTemplate1<Template, typename get_type<TypeList,5>::type>::type type_5;
typedef typename ApplyTemplate1<Template, typename get_type<TypeList,6>::type>::type type_6;
typedef typename ApplyTemplate1<Template, typename get_type<TypeList,7>::type>::type type_7;
typedef typename ApplyTemplate1<Template, typename get_type<TypeList,8>::type>::type type_8;
typedef typename ApplyTemplate1<Template, typename get_type<TypeList,9>::type>::type type_9;
typedef typename ApplyTemplate1<Template, typename get_type<TypeList,10>::type>::type type_10;
typedef typename ApplyTemplate1<Template, typename get_type<TypeList,11>::type>::type type_11;
typedef typename ApplyTemplate1<Template, typename get_type<TypeList,12>::type>::type type_12;
typedef typename ApplyTemplate1<Template, typename get_type<TypeList,13>::type>::type type_13;
typedef typename ApplyTemplate1<Template, typename get_type<TypeList,14>::type>::type type_14;
typedef typename ApplyTemplate1<Template, typename get_type<TypeList,15>::type>::type type_15;
typedef typename ApplyTemplate1<Template, typename get_type<TypeList,16>::type>::type type_16;
typedef typename ApplyTemplate1<Template, typename get_type<TypeList,17>::type>::type type_17;
typedef typename ApplyTemplate1<Template, typename get_type<TypeList,18>::type>::type type_18;
typedef typename ApplyTemplate1<Template, typename get_type<TypeList,19>::type>::type type_19;
struct transform1;

typedef type_list<type_0, type_1, type_2, type_3, type_4, type_5, type_6, type_7, type_8, type_9,
type_10, type_11, type_12, type_13, type_14, type_15, type_16, type_17, type_18, type_19> type;
template<typename... Ts,
template <typename> class Template>
struct transform1<type_list<Ts...>, Template>
{
typedef type_list<typename ApplyTemplate1<Template, Ts>::type...> type;
};

// this type creates a new type_list by applying a Template to each of
// two type_list's types
template<typename TypeList1,
typename TypeList2,
template <typename,typename> class Template>
struct transform2
{
typedef typename ApplyTemplate2<Template, typename get_type<TypeList1,0>::type, typename get_type<TypeList2,0>::type>::type type_0;
typedef typename ApplyTemplate2<Template, typename get_type<TypeList1,1>::type, typename get_type<TypeList2,1>::type>::type type_1;
typedef typename ApplyTemplate2<Template, typename get_type<TypeList1,2>::type, typename get_type<TypeList2,2>::type>::type type_2;
typedef typename ApplyTemplate2<Template, typename get_type<TypeList1,3>::type, typename get_type<TypeList2,3>::type>::type type_3;
typedef typename ApplyTemplate2<Template, typename get_type<TypeList1,4>::type, typename get_type<TypeList2,4>::type>::type type_4;
typedef typename ApplyTemplate2<Template, typename get_type<TypeList1,5>::type, typename get_type<TypeList2,5>::type>::type type_5;
typedef typename ApplyTemplate2<Template, typename get_type<TypeList1,6>::type, typename get_type<TypeList2,6>::type>::type type_6;
typedef typename ApplyTemplate2<Template, typename get_type<TypeList1,7>::type, typename get_type<TypeList2,7>::type>::type type_7;
typedef typename ApplyTemplate2<Template, typename get_type<TypeList1,8>::type, typename get_type<TypeList2,8>::type>::type type_8;
typedef typename ApplyTemplate2<Template, typename get_type<TypeList1,9>::type, typename get_type<TypeList2,9>::type>::type type_9;
typedef typename ApplyTemplate2<Template, typename get_type<TypeList1,10>::type, typename get_type<TypeList2,10>::type>::type type_10;
typedef typename ApplyTemplate2<Template, typename get_type<TypeList1,11>::type, typename get_type<TypeList2,11>::type>::type type_11;
typedef typename ApplyTemplate2<Template, typename get_type<TypeList1,12>::type, typename get_type<TypeList2,12>::type>::type type_12;
typedef typename ApplyTemplate2<Template, typename get_type<TypeList1,13>::type, typename get_type<TypeList2,13>::type>::type type_13;
typedef typename ApplyTemplate2<Template, typename get_type<TypeList1,14>::type, typename get_type<TypeList2,14>::type>::type type_14;
typedef typename ApplyTemplate2<Template, typename get_type<TypeList1,15>::type, typename get_type<TypeList2,15>::type>::type type_15;
typedef typename ApplyTemplate2<Template, typename get_type<TypeList1,16>::type, typename get_type<TypeList2,16>::type>::type type_16;
typedef typename ApplyTemplate2<Template, typename get_type<TypeList1,17>::type, typename get_type<TypeList2,17>::type>::type type_17;
typedef typename ApplyTemplate2<Template, typename get_type<TypeList1,18>::type, typename get_type<TypeList2,18>::type>::type type_18;
typedef typename ApplyTemplate2<Template, typename get_type<TypeList1,19>::type, typename get_type<TypeList2,19>::type>::type type_19;

struct transform2;

typedef type_list<type_0, type_1, type_2, type_3, type_4, type_5, type_6, type_7, type_8, type_9,
type_10, type_11, type_12, type_13, type_14, type_15, type_16, type_17, type_18, type_19> type;
template<typename... T1s,
typename... T2s,
template <typename,typename> class Template>
struct transform2<type_list<T1s...>, type_list<T2s...>, Template>
{
typedef type_list<typename ApplyTemplate2<Template, T1s, T2s>::type...> type;
};

} // end unittest
Expand Down

0 comments on commit 6ff6c6d

Please sign in to comment.