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