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)
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 */
13 
14 
36 #ifndef LIB_META_TYPELIST_UTIL_H
37 #define LIB_META_TYPELIST_UTIL_H
38 
39 
40 
41 #include "lib/meta/typelist.hpp"
42 
43 namespace lib {
44 namespace meta {
45 
46 
51  template<class TYPES>
52  struct count;
53  template<>
54  struct count<NullType>
55  {
56  enum{ value = 0 };
57  };
58  template<class TY, class TYPES>
59  struct count<Node<TY,TYPES>>
60  {
61  enum{ value = 1 + count<TYPES>::value };
62  };
63 
64 
68  template<class TYPES>
69  struct maxSize;
70  template<>
71  struct maxSize<NullType>
72  {
73  static constexpr int value = 0;
74  };
75  template<class TY, class TYPES>
76  struct maxSize<Node<TY,TYPES>>
77  {
78  static constexpr size_t thisval = sizeof(TY);
79  static constexpr size_t nextval = maxSize<TYPES>::value;
80  static constexpr size_t value = nextval > thisval? nextval:thisval;
81  };
82 
83 
87  template<class TYPES>
88  struct maxAlign;
89  template<>
91  {
92  static constexpr int value = 0;
93  };
94  template<class TY, class TYPES>
95  struct maxAlign<Node<TY,TYPES>>
96  {
97  static constexpr size_t thisval = alignof(TY);
98  static constexpr size_t nextval = maxAlign<TYPES>::value;
99  static constexpr size_t value = nextval > thisval? nextval:thisval;
100  };
101 
102 
107  template<typename TY, typename TYPES>
108  struct IsInList
109  {
110  enum{ value = false };
111  };
112 
113  template<typename TY, typename TYPES>
114  struct IsInList<TY, Node<TY,TYPES>>
115  {
116  enum{ value = true };
117  };
118 
119  template<typename TY, typename XX, typename TYPES>
120  struct IsInList<TY, Node<XX,TYPES>>
121  {
122  enum{ value = IsInList<TY,TYPES>::value };
123  };
124 
126  template<typename TY, typename TYPES>
127  constexpr bool
129  {
131  }
132 
133 
137  template<typename TYPES>
138  struct ConstAll;
139 
140  template<>
142  {
143  typedef NullType List;
144  };
145 
146  template<typename TY, typename TYPES>
147  struct ConstAll<Node<TY,TYPES>>
148  {
150  };
151 
152 
153 
154 }} // namespace lib::meta
155 #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