| 124 | } |
| 125 | |
| 126 | void functional_test::test_bind() |
| 127 | { |
| 128 | auto f1 = std::bind(aux::f1, _1, 1); |
| 129 | auto res1 = f1(3); |
| 130 | |
| 131 | test_eq("bind placeholder", res1, 4); |
| 132 | |
| 133 | auto f2 = std::bind(aux::f2, _2, _1); |
| 134 | auto res2 = f2(5, 6); |
| 135 | |
| 136 | test_eq("bind reverse placeholder order", res2, 65); |
| 137 | |
| 138 | int x{}; |
| 139 | int y{}; |
| 140 | auto f3 = std::bind(aux::f3, _1, std::ref(y)); |
| 141 | f3(std::ref(x)); |
| 142 | |
| 143 | test_eq("bind std::ref as bound", y, 1337); |
| 144 | test_eq("bind std::ref as unbound", x, 42); |
| 145 | |
| 146 | auto f4 = std::bind(aux::f2, x, y); |
| 147 | auto res3 = f4(); |
| 148 | |
| 149 | test_eq("bind all arguments bound", res3, 1757); |
| 150 | |
| 151 | aux::Foo foo{5}; |
| 152 | auto f5 = std::mem_fn(&aux::Foo::add); |
| 153 | auto res4 = f5(&foo, 4); |
| 154 | |
| 155 | test_eq("mem_fn", res4, 9); |
| 156 | |
| 157 | /* auto f5 = std::bind(&aux::Foo::add, _1, _2); */ |
| 158 | /* auto res4 = f4(&foo, 10); */ |
| 159 | |
| 160 | /* test_eq("bind to member function", res4, 19); */ |
| 161 | } |
| 162 | } |