Lumiera  0.pre.03
»edit your freedom«
typelist-util.hpp
Go to the documentation of this file.
1 /*
2  TYPELIST-UTIL.hpp - simple helpers for working with lists-of-types
3 
4  Copyright (C) Lumiera.org
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
23 
45 #ifndef LIB_META_TYPELIST_UTIL_H
46 #define LIB_META_TYPELIST_UTIL_H
47 
48 
49 
50 #include "lib/meta/typelist.hpp"
51 
52 namespace lib {
53 namespace meta {
54 
55 
60  template<class TYPES>
61  struct count;
62  template<>
63  struct count<NullType>
64  {
65  enum{ value = 0 };
66  };
67  template<class TY, class TYPES>
68  struct count<Node<TY,TYPES>>
69  {
70  enum{ value = 1 + count<TYPES>::value };
71  };
72 
73 
77  template<class TYPES>
78  struct maxSize;
79  template<>
80  struct maxSize<NullType>
81  {
82  static constexpr int value = 0;
83  };
84  template<class TY, class TYPES>
85  struct maxSize<Node<TY,TYPES>>
86  {
87  static constexpr size_t thisval = sizeof(TY);
88  static constexpr size_t nextval = maxSize<TYPES>::value;
89  static constexpr size_t value = nextval > thisval? nextval:thisval;
90  };
91 
92 
96  template<class TYPES>
97  struct maxAlign;
98  template<>
100  {
101  static constexpr int value = 0;
102  };
103  template<class TY, class TYPES>
104  struct maxAlign<Node<TY,TYPES>>
105  {
106  static constexpr size_t thisval = alignof(TY);
107  static constexpr size_t nextval = maxAlign<TYPES>::value;
108  static constexpr size_t value = nextval > thisval? nextval:thisval;
109  };
110 
111 
116  template<typename TY, typename TYPES>
117  struct IsInList
118  {
119  enum{ value = false };
120  };
121 
122  template<typename TY, typename TYPES>
123  struct IsInList<TY, Node<TY,TYPES>>
124  {
125  enum{ value = true };
126  };
127 
128  template<typename TY, typename XX, typename TYPES>
129  struct IsInList<TY, Node<XX,TYPES>>
130  {
131  enum{ value = IsInList<TY,TYPES>::value };
132  };
133 
135  template<typename TY, typename TYPES>
136  constexpr bool
138  {
140  }
141 
142 
146  template<typename TYPES>
147  struct ConstAll;
148 
149  template<>
151  {
152  typedef NullType List;
153  };
154 
155  template<typename TY, typename TYPES>
156  struct ConstAll<Node<TY,TYPES>>
157  {
159  };
160 
161 
162 
163 }} // namespace lib::meta
164 #endif
A template metaprogramming technique for manipulating collections of types.
Build a list of const types from a given typelist.
Metafunction to check if a specific type is contained in a given typelist.
Metafunction " max( alignof(T) ) for T in TYPES ".
Implementation namespace for support and library code.
Metafunction " max( sizeof(T) ) for T in TYPES ".
Metafunction counting the number of Types in the collection.
constexpr bool isInList()
convenience shortcut: query function