type_list.hpp
Go to the documentation of this file.
/*
CLAW - a C++ Library Absolutely Wonderful
CLAW is a free library without any particular aim but being useful to
anyone.
Copyright (C) 2005-2011 Julien Jorge
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
contact: julien.jorge@gamned.org
*/
#ifndef __CLAW_TYPE_LIST_HPP__
#define __CLAW_TYPE_LIST_HPP__
#include <claw/meta/conditional.hpp>
#include <claw/meta/no_type.hpp>
#include <claw/meta/same_type.hpp>
namespace claw
{
namespace meta
{
template<typename Head, typename Queue>
struct type_list
{
typedef Head head_type;
typedef Queue queue_type;
}; // struct type_list
template<typename Delimiter, typename TypeList>
struct split_type_list_at;
template<typename Delimiter>
struct split_type_list_at<Delimiter, no_type>
{
typedef no_type left_part_type;
typedef no_type right_part_type;
}; // struct split_type_list_at
template<typename Delimiter, typename TypeList>
struct split_type_list_at
{
typedef typename if_then_else
< same_type<Delimiter, typename TypeList::head_type>::result,
no_type, /* delimiter is found, mark the end of the list. */
type_list /* otherwise, cut in the remaining types. */
< typename TypeList::head_type,
typename split_type_list_at
<Delimiter, typename TypeList::queue_type>::left_part_type > >::result
left_part_type;
typedef typename if_then_else
< same_type<Delimiter, typename TypeList::head_type>::result,
TypeList, /* delimiter is found, this is the right part. */
typename split_type_list_at
<Delimiter, typename TypeList::queue_type>::right_part_type >::result
right_part_type;
}; // struct split_type_list_at
template<typename T1>
struct type_list_maker_1
{
typedef type_list<T1, no_type> result;
}; // struct type_list_maker_1
template<typename T1, typename T2>
struct type_list_maker_2
{
typedef type_list< T1, typename type_list_maker_1<T2>::result > result;
}; // struct type_list_maker_2
template<typename T1, typename T2, typename T3>
struct type_list_maker_3
{
typedef
type_list< T1, typename type_list_maker_2<T2, T3>::result > result;
}; // struct type_list_maker_3
template<typename T1, typename T2, typename T3, typename T4>
struct type_list_maker_4
{
typedef
type_list< T1, typename type_list_maker_3<T2, T3, T4>::result > result;
}; // struct type_list_maker_4
template<typename T1, typename T2, typename T3, typename T4, typename T5>
struct type_list_maker_5
{
typedef type_list
< T1,
typename type_list_maker_4<T2, T3, T4, T5>::result > result;
}; // struct type_list_maker_5
template<typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6>
struct type_list_maker_6
{
typedef type_list
< T1,
typename type_list_maker_5<T2, T3, T4, T5, T6>::result > result;
}; // struct type_list_maker_6
template<typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7>
struct type_list_maker_7
{
typedef type_list
< T1,
typename type_list_maker_6<T2, T3, T4, T5, T6, T7>::result > result;
}; // struct type_list_maker_7
template<typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8>
struct type_list_maker_8
{
typedef type_list
< T1,
typename type_list_maker_7<T2, T3, T4, T5, T6, T7, T8>::result > result;
}; // struct type_list_maker_8
template<typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8, typename T9>
struct type_list_maker_9
{
typedef type_list
< T1,
typename type_list_maker_8
<T2, T3, T4, T5, T6, T7, T8, T9>::result
> result;
}; // struct type_list_maker_9
template<typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8, typename T9, typename T10>
struct type_list_maker_10
{
typedef type_list
< T1,
typename type_list_maker_9
<T2, T3, T4, T5, T6, T7, T8, T9, T10>::result
> result;
}; // struct type_list_maker_10
template<typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8, typename T9, typename T10,
typename T11>
struct type_list_maker_11
{
typedef type_list
< T1,
typename type_list_maker_10
<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>::result
> result;
}; // struct type_list_maker_11
template<typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8, typename T9, typename T10,
typename T11, typename T12>
struct type_list_maker_12
{
typedef type_list
< T1,
typename type_list_maker_11
<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>::result
> result;
}; // struct type_list_maker_12
template<typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8, typename T9, typename T10,
typename T11, typename T12, typename T13>
struct type_list_maker_13
{
typedef type_list
< T1,
typename type_list_maker_12
<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>::result
> result;
}; // struct type_list_maker_13
template<typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8, typename T9, typename T10,
typename T11, typename T12, typename T13, typename T14>
struct type_list_maker_14
{
typedef type_list
< T1,
typename type_list_maker_13
<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>::result
> result;
}; // struct type_list_maker_14
template<typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8, typename T9, typename T10,
typename T11, typename T12, typename T13, typename T14,
typename T15>
struct type_list_maker_15
{
typedef type_list
< T1,
typename type_list_maker_14
<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>::result
> result;
}; // struct type_list_maker_15
template< typename T1, typename T2 = no_type, typename T3 = no_type,
typename T4 = no_type, typename T5 = no_type,
typename T6 = no_type, typename T7 = no_type,
typename T8 = no_type, typename T9 = no_type,
typename T10 = no_type, typename T11 = no_type,
typename T12 = no_type, typename T13 = no_type,
typename T14 = no_type, typename T15 = no_type >
struct type_list_maker
{
typedef typename split_type_list_at
< no_type,
typename type_list_maker_15
< T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
T15 >::result
>::left_part_type result;
}; // struct type_list_maker
template<typename T, typename List>
struct type_list_find
{
enum
{
result = same_type<T, typename List::head_type>::result
|| type_list_find<T, typename List::queue_type>::result
};
}; // struct type_list_find
template<typename T>
struct type_list_find<T, no_type>
{
enum
{
result = same_type<T, no_type>::result
};
}; // struct type_list_find
template<typename List>
struct type_list_is_a_set
{
enum
{
result = !type_list_find<typename List::head_type,
typename List::queue_type>::result
&& type_list_is_a_set<typename List::queue_type>::result
};
}; // struct type_list_is_a_set
template<>
struct type_list_is_a_set<no_type>
{
enum
{
result = true
};
}; // struct type_list_is_a_set [no_type]
template<typename List>
struct type_list_length
{
enum
{
result = 1 + type_list_length<typename List::queue_type>::result
};
}; // struct type_list_length
template<>
struct type_list_length<no_type>
{
enum
{
result = 0
};
}; // struct type_list_length [no_type]
template<typename T, typename List>
struct type_list_contains;
template<typename T, typename Tail>
struct type_list_contains< T, type_list<T, Tail> >
{
enum
{
result = true
};
}; // struct type_list_contains
template<typename T>
struct type_list_contains< T, no_type >
{
enum
{
result = false
};
}; // struct type_list_contains
template<typename T, typename Head, typename Tail>
struct type_list_contains< T, type_list<Head, Tail> >
{
enum
{
result = type_list_contains<T, Tail>::result
};
}; // struct type_list_contains
typedef type_list_maker
< signed char, unsigned char,
signed short, unsigned short,
signed int, unsigned int,
signed long, unsigned long,
#ifndef __STRICT_ANSI__
signed long long, unsigned long long,
#endif
float,
double,
long double,
bool >::result cpp_type_list;
} // namespace meta
} // namespace claw
#endif // __CLAW_TYPE_LIST_HPP__
conditional.hpp
Structures for meta-programming.
claw::meta
Structures for meta-programmation.
Definition claw.hpp:81
claw::meta::cpp_type_list
type_list_maker< signedchar, unsignedchar, signedshort, unsignedshort, signedint, unsignedint, signedlong, unsignedlong, signedlonglong, unsignedlonglong, float, double, longdouble, bool >::result cpp_type_list
The list of the types of the C++ language.
Definition type_list.hpp:493
claw
This is the main namespace.
Definition algorithm.hpp:34
no_type.hpp
An empty class not considered as a effective type.
same_type.hpp
Check if two types are the same.
claw::meta::if_then_else
This structure allows to do conditional typing.
Definition conditional.hpp:50
claw::meta::no_type
Empty type.
Definition no_type.hpp:40
claw::meta::split_type_list_at< Delimiter, no_type >::right_part_type
no_type right_part_type
There is no right part if there is no list.
Definition type_list.hpp:88
claw::meta::split_type_list_at< Delimiter, no_type >::left_part_type
no_type left_part_type
There is no left part if there is no list.
Definition type_list.hpp:85
claw::meta::split_type_list_at
Split a type_list according to the first instance of a given type.
Definition type_list.hpp:101
claw::meta::split_type_list_at::left_part_type
if_then_else< same_type< Delimiter, typenameTypeList::head_type >::result, no_type, type_list< typenameTypeList::head_type, typenamesplit_type_list_at< Delimiter, typenameTypeList::queue_type >::left_part_type > >::result left_part_type
The left part of the list. The delimiter is not included.
Definition type_list.hpp:110
claw::meta::split_type_list_at::right_part_type
if_then_else< same_type< Delimiter, typenameTypeList::head_type >::result, TypeList, typenamesplit_type_list_at< Delimiter, typenameTypeList::queue_type >::right_part_type >::result right_part_type
The right part of the list. The delimiter is included.
Definition type_list.hpp:118
claw::meta::type_list_contains
Tell if a given type list contains a given type.
Definition type_list.hpp:452
claw::meta::type_list_find
Check if a type is present in a type_list.
Definition type_list.hpp:378
claw::meta::type_list_is_a_set
This class checks if each type in a type_list<> is present only once.
Definition type_list.hpp:403
claw::meta::type_list_length
This class computes the length of a list of types.
Definition type_list.hpp:428
claw::meta::type_list_maker_10
A type list with ten types, more readable than an imbricated type_list.
Definition type_list.hpp:246
claw::meta::type_list_maker_10::result
type_list< T1, typename type_list_maker_9< T2, T3, T4, T5, T6, T7, T8, T9, T10 >::result > result
The list described by this implementation.
Definition type_list.hpp:252
claw::meta::type_list_maker_11
A type list with eleven types, more readable than an imbricated type_list.
Definition type_list.hpp:263
claw::meta::type_list_maker_11::result
type_list< T1, typename type_list_maker_10< T2, T3, T4, T5, T6, T7, T8, T9, T10, T11 >::result > result
The list described by this implementation.
Definition type_list.hpp:269
claw::meta::type_list_maker_12
A type list with twelve types, more readable than an imbricated type_list.
Definition type_list.hpp:280
claw::meta::type_list_maker_12::result
type_list< T1, typename type_list_maker_11< T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12 >::result > result
The list described by this implementation.
Definition type_list.hpp:286
claw::meta::type_list_maker_13
A type list with thirteen types, more readable than an imbricated type_list.
Definition type_list.hpp:297
claw::meta::type_list_maker_13::result
type_list< T1, typename type_list_maker_12< T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13 >::result > result
The list described by this implementation.
Definition type_list.hpp:303
claw::meta::type_list_maker_14
A type list with fourteen types, more readable than an imbricated type_list.
Definition type_list.hpp:314
claw::meta::type_list_maker_14::result
type_list< T1, typename type_list_maker_13< T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 >::result > result
The list described by this implementation.
Definition type_list.hpp:320
claw::meta::type_list_maker_15
A type list with fifteen types, more readable than an imbricated type_list.
Definition type_list.hpp:332
claw::meta::type_list_maker_15::result
type_list< T1, typename type_list_maker_14< T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15 >::result > result
The list described by this implementation.
Definition type_list.hpp:338
claw::meta::type_list_maker_1
A type list with a single type, more readable than an imbricated type_list.
Definition type_list.hpp:128
claw::meta::type_list_maker_1::result
type_list< T1, no_type > result
The list described by this implementation.
Definition type_list.hpp:130
claw::meta::type_list_maker_2
A type list with two types, more readable than an imbricated type_list.
Definition type_list.hpp:139
claw::meta::type_list_maker_2::result
type_list< T1, typename type_list_maker_1< T2 >::result > result
The list described by this implementation.
Definition type_list.hpp:141
claw::meta::type_list_maker_3
A type list with three types, more readable than an imbricated type_list.
Definition type_list.hpp:150
claw::meta::type_list_maker_3::result
type_list< T1, typename type_list_maker_2< T2, T3 >::result > result
The list described by this implementation.
Definition type_list.hpp:153
claw::meta::type_list_maker_4
A type list with four types, more readable than an imbricated type_list.
Definition type_list.hpp:162
claw::meta::type_list_maker_4::result
type_list< T1, typename type_list_maker_3< T2, T3, T4 >::result > result
The list described by this implementation.
Definition type_list.hpp:165
claw::meta::type_list_maker_5
A type list with five types, more readable than an imbricated type_list.
Definition type_list.hpp:174
claw::meta::type_list_maker_5::result
type_list< T1, typename type_list_maker_4< T2, T3, T4, T5 >::result > result
The list described by this implementation.
Definition type_list.hpp:178
claw::meta::type_list_maker_6
A type list with six types, more readable than an imbricated type_list.
Definition type_list.hpp:188
claw::meta::type_list_maker_6::result
type_list< T1, typename type_list_maker_5< T2, T3, T4, T5, T6 >::result > result
The list described by this implementation.
Definition type_list.hpp:192
claw::meta::type_list_maker_7
A type list with seven types, more readable than an imbricated type_list.
Definition type_list.hpp:202
claw::meta::type_list_maker_7::result
type_list< T1, typename type_list_maker_6< T2, T3, T4, T5, T6, T7 >::result > result
The list described by this implementation.
Definition type_list.hpp:206
claw::meta::type_list_maker_8
A type list with height types, more readable than an imbricated type_list.
Definition type_list.hpp:216
claw::meta::type_list_maker_8::result
type_list< T1, typename type_list_maker_7< T2, T3, T4, T5, T6, T7, T8 >::result > result
The list described by this implementation.
Definition type_list.hpp:220
claw::meta::type_list_maker_9
A type list with nine types, more readable than an imbricated type_list.
Definition type_list.hpp:230
claw::meta::type_list_maker_9::result
type_list< T1, typename type_list_maker_8< T2, T3, T4, T5, T6, T7, T8, T9 >::result > result
The list described by this implementation.
Definition type_list.hpp:236
claw::meta::type_list_maker
A type list with up to six types, more readable than an imbricated type_list, more readable than type...
Definition type_list.hpp:354
claw::meta::type_list_maker::result
split_type_list_at< no_type, typenametype_list_maker_15< T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15 >::result >::left_part_type result
The list described by this implementation.
Definition type_list.hpp:361
claw::meta::type_list
Use this class to make a list of types.
Definition type_list.hpp:60
claw::meta::type_list::queue_type
Queue queue_type
The remaining types in the list.
Definition type_list.hpp:65
claw::meta::type_list::head_type
Head head_type
The first type in the list.
Definition type_list.hpp:62