Build system improvements
[ustl.git] / metamac.h
blobb1e51dab805f93e6e998f6e521f80743615792eb
1 // This file is part of the ustl library, an STL implementation.
2 //
3 // Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
4 // This file is free software, distributed under the MIT License.
5 //
6 /// \file metamac.h
7 /// \brief Macros for complex metaprogramming involving pseudoiteration.
8 ///
10 #ifndef METAMAC_H_7235D14A209C29332F2330EF553B81AF
11 #define METAMAC_H_7235D14A209C29332F2330EF553B81AF
13 //----------------------------------------------------------------------
14 // Functors and general utilities.
15 //----------------------------------------------------------------------
17 /// Evaluates to itself
18 #define ITSELF(x) x
20 /// Concatenates \p a and \p b
21 #define PASTE(a,b) a##b
23 //----------------------------------------------------------------------
24 // Lists and other iterators
25 //----------------------------------------------------------------------
27 /// The maximum number of elements in REPEAT, LIST, and COMMA_LIST
28 #define METAMAC_MAXN 9
30 /// Simple list with no separators. Repeats x N times.
31 /// @{
32 #define REPEAT_1(x) x(1)
33 #define REPEAT_2(x) REPEAT_1(x) x(2)
34 #define REPEAT_3(x) REPEAT_2(x) x(3)
35 #define REPEAT_4(x) REPEAT_3(x) x(4)
36 #define REPEAT_5(x) REPEAT_4(x) x(5)
37 #define REPEAT_6(x) REPEAT_5(x) x(6)
38 #define REPEAT_7(x) REPEAT_6(x) x(7)
39 #define REPEAT_8(x) REPEAT_7(x) x(8)
40 #define REPEAT_9(x) REPEAT_8(x) x(9)
41 #define REPEAT(N,x) PASTE(REPEAT_,N)(x)
42 /// @}
44 /// Simple separated list. Repeats x N times with sep in between.
45 /// @{
46 #define LIST_1(x,sep) x(1)
47 #define LIST_2(x,sep) LIST_1(x,sep) sep x(2)
48 #define LIST_3(x,sep) LIST_2(x,sep) sep x(3)
49 #define LIST_4(x,sep) LIST_3(x,sep) sep x(4)
50 #define LIST_5(x,sep) LIST_4(x,sep) sep x(5)
51 #define LIST_6(x,sep) LIST_5(x,sep) sep x(6)
52 #define LIST_7(x,sep) LIST_6(x,sep) sep x(7)
53 #define LIST_8(x,sep) LIST_7(x,sep) sep x(8)
54 #define LIST_9(x,sep) LIST_8(x,sep) sep x(9)
55 #define LIST(N,x,sep) PASTE(LIST_,N)(x,sep)
56 /// @}
58 /// Comma separated list. A special case of LIST needed because the preprocessor can't substitute commas.
59 /// @{
60 #define COMMA_LIST_1(x) x(1)
61 #define COMMA_LIST_2(x) COMMA_LIST_1(x), x(2)
62 #define COMMA_LIST_3(x) COMMA_LIST_2(x), x(3)
63 #define COMMA_LIST_4(x) COMMA_LIST_3(x), x(4)
64 #define COMMA_LIST_5(x) COMMA_LIST_4(x), x(5)
65 #define COMMA_LIST_6(x) COMMA_LIST_5(x), x(6)
66 #define COMMA_LIST_7(x) COMMA_LIST_6(x), x(7)
67 #define COMMA_LIST_8(x) COMMA_LIST_7(x), x(8)
68 #define COMMA_LIST_9(x) COMMA_LIST_8(x), x(9)
69 #define COMMA_LIST(N,x) PASTE(COMMA_LIST_,N)(x)
70 /// @}
72 //----------------------------------------------------------------------
73 // Macros for defining LIST arguments.
74 //----------------------------------------------------------------------
76 /// Ignores N, producing lists of identically named arguments.
77 #define LARG_NONE(name,N) name
79 /// Appends N to name.
80 #define LARG_NUMBER(name,N) name##N
82 /// name is a reference type.
83 #define LARG_REF(name,N) name##N&
85 /// Sequential parameter passed by value with sequential types.
86 #define LARG_MT_PARAM_BY_VALUE(type,name,N) type##N name##N
88 /// Sequential parameter passed by reference with sequential types.
89 #define LARG_MT_PARAM_BY_REF(type,name,N) type##N& name##N
91 //----------------------------------------------------------------------
93 #endif