Lumiera  0.pre.03
»edityourfreedom«
function.hpp
Go to the documentation of this file.
1 /*
2  FUNCTION.hpp - metaprogramming utilities for transforming function types
3 
4  Copyright (C) Lumiera.org
5  2009, 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 
51 #ifndef LIB_META_FUNCTION_H
52 #define LIB_META_FUNCTION_H
53 
54 #include "lib/meta/typelist.hpp"
55 #include "lib/meta/util.hpp"
56 
57 #include <functional>
58 
59 
60 
61 namespace lib {
62 namespace meta{
63 
64  using std::function;
65 
66 
107  template<typename FUN, typename SEL =void>
108  struct _Fun
109  : std::false_type
110  {
111  using Functor = FUN;
112  };
113 
115  template<typename FUN>
116  struct _Fun<FUN, enable_if<has_FunctionOperator<FUN>> >
117  : _Fun<decltype(&FUN::operator())>
118  {
119  using Functor = FUN;
120  };
121 
123  template<typename RET, typename...ARGS>
124  struct _Fun<RET(ARGS...)>
125  : std::true_type
126  {
127  using Ret = RET;
128  using Args = Types<ARGS...>;
129  using Sig = RET(ARGS...);
130  using Functor = std::function<Sig>;
131  };
133  template<typename SIG>
134  struct _Fun<SIG*>
135  : _Fun<SIG>
136  { };
137 
139  template<typename SIG>
140  struct _Fun<SIG&>
141  : _Fun<SIG>
142  { };
143 
145  template<typename SIG>
146  struct _Fun<SIG&&>
147  : _Fun<SIG>
148  { };
149 
151  template<class C, typename RET, typename...ARGS>
152  struct _Fun<RET (C::*) (ARGS...)>
153  : _Fun<RET(ARGS...)>
154  { };
155 
159  template<class C, typename RET, typename...ARGS>
160  struct _Fun<RET (C::*) (ARGS...) const>
161  : _Fun<RET(ARGS...)>
162  { };
163 
164 
165 
166 
167 
168 
169 
170 
171 
179  template<typename RET, typename ARGS>
181 
182 
183  template< typename RET>
184  struct FunctionTypedef<RET, Types<> >
185  {
186  typedef function<RET(void)> Func;
187  typedef RET Sig();
188  };
189 
190 
191  template< typename RET
192  , typename A1
193  >
194  struct FunctionTypedef<RET, Types<A1>>
195  {
196  typedef function<RET(A1)> Func;
197  typedef RET Sig(A1);
198  };
199 
200 
201  template< typename RET
202  , typename A1
203  , typename A2
204  >
205  struct FunctionTypedef<RET, Types<A1,A2>>
206  {
207  typedef function<RET(A1,A2)> Func;
208  typedef RET Sig(A1,A2);
209  };
210 
211 
212  template< typename RET
213  , typename A1
214  , typename A2
215  , typename A3
216  >
217  struct FunctionTypedef<RET, Types<A1,A2,A3>>
218  {
219  typedef function<RET(A1,A2,A3)> Func;
220  typedef RET Sig(A1,A2,A3);
221  };
222 
223 
224  template< typename RET
225  , typename A1
226  , typename A2
227  , typename A3
228  , typename A4
229  >
230  struct FunctionTypedef<RET, Types<A1,A2,A3,A4>>
231  {
232  typedef function<RET(A1,A2,A3,A4)> Func;
233  typedef RET Sig(A1,A2,A3,A4);
234  };
235 
236 
237  template< typename RET
238  , typename A1
239  , typename A2
240  , typename A3
241  , typename A4
242  , typename A5
243  >
244  struct FunctionTypedef<RET, Types<A1,A2,A3,A4,A5>>
245  {
246  typedef function<RET(A1,A2,A3,A4,A5)> Func;
247  typedef RET Sig(A1,A2,A3,A4,A5);
248  };
249 
250 
251  template< typename RET
252  , typename A1
253  , typename A2
254  , typename A3
255  , typename A4
256  , typename A5
257  , typename A6
258  >
259  struct FunctionTypedef<RET, Types<A1,A2,A3,A4,A5,A6>>
260  {
261  typedef function<RET(A1,A2,A3,A4,A5,A6)> Func;
262  typedef RET Sig(A1,A2,A3,A4,A5,A6);
263  };
264 
265 
266  template< typename RET
267  , typename A1
268  , typename A2
269  , typename A3
270  , typename A4
271  , typename A5
272  , typename A6
273  , typename A7
274  >
275  struct FunctionTypedef<RET, Types<A1,A2,A3,A4,A5,A6,A7>>
276  {
277  typedef function<RET(A1,A2,A3,A4,A5,A6,A7)> Func;
278  typedef RET Sig(A1,A2,A3,A4,A5,A6,A7);
279  };
280 
281 
282  template< typename RET
283  , typename A1
284  , typename A2
285  , typename A3
286  , typename A4
287  , typename A5
288  , typename A6
289  , typename A7
290  , typename A8
291  >
292  struct FunctionTypedef<RET, Types<A1,A2,A3,A4,A5,A6,A7,A8>>
293  {
294  typedef function<RET(A1,A2,A3,A4,A5,A6,A7,A8)> Func;
295  typedef RET Sig(A1,A2,A3,A4,A5,A6,A7,A8);
296  };
297 
298 
299  template< typename RET
300  , typename A1
301  , typename A2
302  , typename A3
303  , typename A4
304  , typename A5
305  , typename A6
306  , typename A7
307  , typename A8
308  , typename A9
309  >
310  struct FunctionTypedef<RET, Types<A1,A2,A3,A4,A5,A6,A7,A8,A9>>
311  {
312  typedef function<RET(A1,A2,A3,A4,A5,A6,A7,A8,A9)> Func;
313  typedef RET Sig(A1,A2,A3,A4,A5,A6,A7,A8,A9);
314  };
315 
316 
317 
318 
319 
320 }} // namespace lib::meta
321 #endif
A template metaprogramming technique for manipulating collections of types.
typename enable_if_c< Cond::value, T >::type enable_if
SFINAE helper to control the visibility of specialisations and overloads.
Definition: meta/util.hpp:91
Simple and lightweight helpers for metaprogramming and type detection.
function< RET(A1, A2, A3, A4, A5, A6, A7, A8, A9)> Func
Definition: function.hpp:312
Helper for uniform access to function signature types.
Definition: function.hpp:108
Implementation namespace for support and library code.
Build function types from given Argument types.
Definition: function.hpp:180
std::function< Sig > Functor
Definition: function.hpp:130
Trait template to detect presence of a simple function call operator.
Definition: meta/util.hpp:185