Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
generator.hpp
Go to the documentation of this file.
1/*
2 GENERATOR.hpp - metaprogramming utilities for generating classes and interfaces
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====================================================================
13This code is heavily inspired by
14 The Loki Library (loki-lib/trunk/include/loki/Sequence.h)
15 Copyright (c) 2001 by Andrei Alexandrescu
16 Copyright (c) 2005 by Peter Kümmel
17 This Loki code accompanies the book:
18 Alexandrescu, Andrei. "Modern C++ Design: Generic Programming
19 and Design Patterns Applied".
20 Copyright (c) 2001. Addison-Wesley. ISBN 0201704315
21
22 Loki Copyright Notice:
23 Permission to use, copy, modify, distribute and sell this software for any
24 purpose is hereby granted without fee, provided that the above copyright
25 notice appear in all copies and that both that copyright notice and this
26 permission notice appear in supporting documentation.
27 The author makes no representations about the suitability of this software
28 for any purpose. It is provided "as is" without express or implied warranty.
29*/
30
31
50#ifndef LIB_META_GENERATOR_H
51#define LIB_META_GENERATOR_H
52
53#include "lib/meta/typelist.hpp"
54
55
56
57namespace lib {
58namespace meta{
59
66 template
67 < class TYPES // List of Types
68 , template<class> class _X_ // your-template-goes-here
69 , class BASE = Nil // Base class at end of chain
70 >
72
73
74 template<template<class> class _X_, class BASE>
75 class InstantiateForEach<Nil, _X_, BASE>
76 : public BASE
77 {
78 public:
79 using Unit = BASE;
80 using Next = Nil;
81 };
82
83
84 template
85 < class TY, typename TYPES
86 , template<class> class _X_
87 , class BASE
88 >
89 class InstantiateForEach<Node<TY, TYPES>, _X_, BASE>
90 : public _X_<TY>,
91 public InstantiateForEach<TYPES, _X_, BASE>
92 {
93 public:
94 using Unit = _X_<TY>;
96 };
97
98
100 template<typename T>
101 struct InheritFrom : T
102 { };
103
104
105
106
115 template
116 < class TYPES // List of Types
117 , template<class,class> class _X_ // your-template-goes-here
118 , class BASE = Nil // Base class at end of chain
119 >
121
122
123 template<template<class,class> class _X_, class BASE>
124 class InstantiateChained<Nil, _X_, BASE>
125 : public BASE
126 {
127 public:
128 using Unit = BASE;
129 using Next = Nil;
130 };
131
132
133 template
134 < class TY, typename TYPES
135 , template<class,class> class _X_
136 , class BASE
137 >
138 class InstantiateChained<Node<TY, TYPES>, _X_, BASE>
139 : public _X_< TY
140 , InstantiateChained<TYPES, _X_, BASE>
141 >
142 {
143 public:
146 };
147
148
149
159 template
160 < class TYPES // List of Types
161 , template<class,class,uint> class _X_ // your-template-goes-here
162 , class BASE = Nil // Base class at end of chain
163 , uint i = 0 // incremented on each instantiation
164 >
166
167
168 template< template<class,class,uint> class _X_
169 , class BASE
170 , uint i
171 >
172 class InstantiateWithIndex<Nil, _X_, BASE, i>
173 : public BASE
174 {
175 public:
176 using Unit = BASE;
177 using Next = Nil;
178 enum{ COUNT = i };
179 };
180
181
182 template
183 < class TY, typename TYPES
184 , template<class,class,uint> class _X_
185 , class BASE
186 , uint i
187 >
188 class InstantiateWithIndex<Node<TY, TYPES>, _X_, BASE, i>
189 : public _X_< TY
190 , InstantiateWithIndex<TYPES, _X_, BASE, i+1 >
191 , i
192 >
193 {
194 public:
197 enum{ COUNT = Next::COUNT };
198 };
199
200
201}} // namespace lib::meta
202#endif
Build a single inheritance chain of template instantiations.
Apply a template to a collection of types.
Definition generator.hpp:71
InstantiateWithIndex< TYPES, _X_, BASE, i+1 > Next
unsigned int uint
Definition integral.hpp:29
enable_if_c< Cond::value, T >::type enable_if
SFINAE helper to control the visibility of specialisations and overloads.
Definition meta/util.hpp:87
A Variation of InstantiateChained providing an incremented Index value template parameter.
»Empty« mark
Definition typelist.hpp:82
Type list with head and tail; T ≡ Nil marks list end.
Definition typelist.hpp:90
Implementation namespace for support and library code.
Helper to just inherit from the given type(s)
A template metaprogramming technique for manipulating collections of types.