| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // UNSUPPORTED: c++03 |
| 10 | |
| 11 | // <functional> |
| 12 | |
| 13 | // template<CopyConstructible Fn, CopyConstructible... Types> |
| 14 | // unspecified bind(Fn, Types...); |
| 15 | // template<Returnable R, CopyConstructible Fn, CopyConstructible... Types> |
| 16 | // unspecified bind(Fn, Types...); |
| 17 | |
| 18 | #include <functional> |
| 19 | #include <cassert> |
| 20 | |
| 21 | #include "test_macros.h" |
| 22 | |
| 23 | int count = 0; |
| 24 | |
| 25 | template <class F> |
| 26 | void |
| 27 | test(F f) |
| 28 | { |
| 29 | int save_count = count; |
| 30 | f(); |
| 31 | assert(count == save_count + 1); |
| 32 | } |
| 33 | |
| 34 | template <class F> |
| 35 | void |
| 36 | test_const(const F& f) |
| 37 | { |
| 38 | int save_count = count; |
| 39 | f(); |
| 40 | assert(count == save_count + 2); |
| 41 | } |
| 42 | |
| 43 | void f() {++count;} |
| 44 | |
| 45 | int g() {++count; return 0;} |
| 46 | |
| 47 | struct A_void_0 |
| 48 | { |
| 49 | void operator()() {++count;} |
| 50 | void operator()() const {count += 2;} |
| 51 | }; |
| 52 | |
| 53 | struct A_int_0 |
| 54 | { |
| 55 | int operator()() {++count; return 4;} |
| 56 | int operator()() const {count += 2; return 5;} |
| 57 | }; |
| 58 | |
| 59 | int main(int, char**) |
| 60 | { |
| 61 | test(f: std::bind(f&: f)); |
| 62 | test(f: std::bind(f: &f)); |
| 63 | test(f: std::bind(f: A_void_0())); |
| 64 | test_const(f: std::bind(f: A_void_0())); |
| 65 | |
| 66 | test(f: std::bind<void>(f&: f)); |
| 67 | test(f: std::bind<void>(f: &f)); |
| 68 | test(f: std::bind<void>(f: A_void_0())); |
| 69 | test_const(f: std::bind<void>(f: A_void_0())); |
| 70 | |
| 71 | test(f: std::bind<void>(f&: g)); |
| 72 | test(f: std::bind<void>(f: &g)); |
| 73 | test(f: std::bind<void>(f: A_int_0())); |
| 74 | test_const(f: std::bind<void>(f: A_int_0())); |
| 75 | |
| 76 | return 0; |
| 77 | } |
| 78 | |