1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // UNSUPPORTED: c++98, c++03 11 12 // <functional> 13 14 // template<CopyConstructible Fn, CopyConstructible... Types> 15 // unspecified bind(Fn, Types...); 16 // template<Returnable R, CopyConstructible Fn, CopyConstructible... Types> 17 // unspecified bind(Fn, Types...); 18 19 #include <functional> 20 #include <cassert> 21 22 int count = 0; 23 24 template <class F> 25 void 26 test(F f) 27 { 28 int save_count = count; 29 f(); 30 assert(count == save_count + 1); 31 } 32 33 template <class F> 34 void 35 test_const(const F& f) 36 { 37 int save_count = count; 38 f(); 39 assert(count == save_count + 2); 40 } 41 42 void f() {++count;} 43 44 int g() {++count; return 0;} 45 46 struct A_void_0 47 { 48 void operator()() {++count;} 49 void operator()() const {count += 2;} 50 }; 51 52 struct A_int_0 53 { 54 int operator()() {++count; return 4;} 55 int operator()() const {count += 2; return 5;} 56 }; 57 58 int main() 59 { 60 test(std::bind(f)); 61 test(std::bind(&f)); 62 test(std::bind(A_void_0())); 63 test_const(std::bind(A_void_0())); 64 65 test(std::bind<void>(f)); 66 test(std::bind<void>(&f)); 67 test(std::bind<void>(A_void_0())); 68 test_const(std::bind<void>(A_void_0())); 69 70 test(std::bind<void>(g)); 71 test(std::bind<void>(&g)); 72 test(std::bind<void>(A_int_0())); 73 test_const(std::bind<void>(A_int_0())); 74 } 75