1 | |
2 | // Copyright (C) 2009-2012 Lorenzo Caminiti |
3 | // Distributed under the Boost Software License, Version 1.0 |
4 | // (see accompanying file LICENSE_1_0.txt or a copy at |
5 | // http://www.boost.org/LICENSE_1_0.txt) |
6 | // Home at http://www.boost.org/libs/local_function |
7 | |
8 | #include <boost/config.hpp> |
9 | #ifdef BOOST_NO_CXX11_VARIADIC_MACROS |
10 | # error "variadic macros required" |
11 | #else |
12 | |
13 | #include <boost/local_function.hpp> |
14 | #include <boost/typeof/typeof.hpp> |
15 | #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP() |
16 | |
17 | struct s; |
18 | BOOST_TYPEOF_REGISTER_TYPE(s) // Register before binding `this_` below. |
19 | |
20 | // Compile all local function declaration combinations. |
21 | struct s { |
22 | void f(double p = 1.23, double q = -1.23) { |
23 | { // Only params. |
24 | void BOOST_LOCAL_FUNCTION(int x, int y, default 0) { |
25 | } BOOST_LOCAL_FUNCTION_NAME(l) |
26 | l(1); |
27 | } |
28 | { // Only const binds. |
29 | int a, b; |
30 | |
31 | const int& BOOST_LOCAL_FUNCTION(const bind a, |
32 | const bind& b, const bind& p, const bind q) { |
33 | return b; |
34 | } BOOST_LOCAL_FUNCTION_NAME(l) |
35 | l(); |
36 | |
37 | const s& BOOST_LOCAL_FUNCTION(const bind this_) { |
38 | return *this_; |
39 | } BOOST_LOCAL_FUNCTION_NAME(t) |
40 | t(); |
41 | |
42 | const int BOOST_LOCAL_FUNCTION(const bind a, |
43 | const bind& b, const bind& p, const bind q, |
44 | const bind this_) { |
45 | return a; |
46 | } BOOST_LOCAL_FUNCTION_NAME(lt) |
47 | lt(); |
48 | } |
49 | { // Only plain binds. |
50 | int c, d; |
51 | |
52 | int& BOOST_LOCAL_FUNCTION(bind c, bind& d, |
53 | bind& p, bind& q) { |
54 | return d; |
55 | } BOOST_LOCAL_FUNCTION_NAME(l) |
56 | l(); |
57 | |
58 | s& BOOST_LOCAL_FUNCTION(bind this_) { |
59 | return *this_; |
60 | } BOOST_LOCAL_FUNCTION_NAME(t) |
61 | t(); |
62 | |
63 | int BOOST_LOCAL_FUNCTION(bind c, bind& d, |
64 | bind& p, bind& q, bind this_) { |
65 | return c; |
66 | } BOOST_LOCAL_FUNCTION_NAME(lt) |
67 | lt(); |
68 | } |
69 | |
70 | { // Both params and const binds. |
71 | int a, b; |
72 | |
73 | void BOOST_LOCAL_FUNCTION(const bind a, const bind& b, |
74 | const bind& p, const bind q, |
75 | int x, int y, default 0) { |
76 | } BOOST_LOCAL_FUNCTION_NAME(l) |
77 | l(1); |
78 | |
79 | void BOOST_LOCAL_FUNCTION(const bind this_, |
80 | int x, int y, default 0) { |
81 | } BOOST_LOCAL_FUNCTION_NAME(t) |
82 | t(1); |
83 | |
84 | void BOOST_LOCAL_FUNCTION(const bind a, const bind this_, |
85 | const bind& b, const bind& p, const bind q, |
86 | int x, int y, default 0) { |
87 | } BOOST_LOCAL_FUNCTION_NAME(lt) |
88 | lt(1); |
89 | } |
90 | { // Both params and plain binds. |
91 | int c, d; |
92 | |
93 | void BOOST_LOCAL_FUNCTION(bind c, bind& d, bind& p, bind q, |
94 | int x, int y, default 0) { |
95 | } BOOST_LOCAL_FUNCTION_NAME(l) |
96 | l(1); |
97 | |
98 | void BOOST_LOCAL_FUNCTION(bind this_, |
99 | int x, int y, default 0) { |
100 | } BOOST_LOCAL_FUNCTION_NAME(t) |
101 | t(1); |
102 | |
103 | void BOOST_LOCAL_FUNCTION(bind c, bind& d, |
104 | bind& p, bind this_, bind q, |
105 | int x, int y, default 0) { |
106 | } BOOST_LOCAL_FUNCTION_NAME(lt) |
107 | lt(1); |
108 | } |
109 | { // Both const and plain binds. |
110 | int a, b, c, d; |
111 | |
112 | void BOOST_LOCAL_FUNCTION(const bind a, const bind& b, |
113 | const bind p, bind c, bind& d, bind q) { |
114 | } BOOST_LOCAL_FUNCTION_NAME(l) |
115 | l(); |
116 | |
117 | void BOOST_LOCAL_FUNCTION(const bind this_, |
118 | bind c, bind& d, bind q) { |
119 | } BOOST_LOCAL_FUNCTION_NAME(ct) |
120 | ct(); |
121 | void BOOST_LOCAL_FUNCTION(const bind this_, |
122 | const bind a, const bind& b, const bind p, |
123 | bind c, bind& d, bind q) { |
124 | } BOOST_LOCAL_FUNCTION_NAME(lct) |
125 | lct(); |
126 | |
127 | void BOOST_LOCAL_FUNCTION(const bind a, const bind& b, |
128 | const bind p, bind this_) { |
129 | } BOOST_LOCAL_FUNCTION_NAME(pt) |
130 | pt(); |
131 | void BOOST_LOCAL_FUNCTION(const bind a, const bind& b, |
132 | const bind p, bind c, bind this_, bind& d, bind q) { |
133 | } BOOST_LOCAL_FUNCTION_NAME(lpt) |
134 | lpt(); |
135 | } |
136 | |
137 | { // All params, const binds, and plain binds. |
138 | int a, b, c, d; |
139 | |
140 | void BOOST_LOCAL_FUNCTION( |
141 | const bind a, const bind& b, const bind& p, |
142 | bind c, bind& d, bind& q, int x, int y, default 0) { |
143 | } BOOST_LOCAL_FUNCTION_NAME(l) |
144 | l(1); |
145 | |
146 | void BOOST_LOCAL_FUNCTION(const bind this_, |
147 | bind c, bind& d, bind& q, |
148 | int x, int y, default 0) { |
149 | } BOOST_LOCAL_FUNCTION_NAME(ct) |
150 | ct(1); |
151 | void BOOST_LOCAL_FUNCTION( |
152 | const bind a, const bind& b, const bind& p, |
153 | bind this_, int x, int y, default 0) { |
154 | } BOOST_LOCAL_FUNCTION_NAME(pt) |
155 | pt(1); |
156 | |
157 | void BOOST_LOCAL_FUNCTION(const bind a, const bind this_, |
158 | const bind& b, const bind& p, bind c, bind& d, |
159 | bind& q, int x, int y, default 0) { |
160 | } BOOST_LOCAL_FUNCTION_NAME(lct) |
161 | lct(1); |
162 | void BOOST_LOCAL_FUNCTION(const bind a, const bind& b, |
163 | const bind& p, bind c, bind& d, bind this_, bind& q, |
164 | int x, int y, default 0) { |
165 | } BOOST_LOCAL_FUNCTION_NAME(lpt) |
166 | lpt(1); |
167 | } |
168 | } |
169 | }; |
170 | |
171 | int main(void) { |
172 | s().f(); |
173 | return 0; |
174 | } |
175 | |
176 | #endif // VARIADIC_MACROS |
177 | |
178 | |