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 // <functional> 11 12 // reference_wrapper 13 14 // template <class... ArgTypes> 15 // requires Callable<T, ArgTypes&&...> 16 // Callable<T, ArgTypes&&...>::result_type 17 // operator()(ArgTypes&&... args) const; 18 19 #include <functional> 20 #include <cassert> 21 22 // 0 args, return int 23 24 int count = 0; 25 26 int f_int_0() 27 { 28 return 3; 29 } 30 31 struct A_int_0 32 { 33 int operator()() {return 4;} 34 }; 35 36 void 37 test_int_0() 38 { 39 // function 40 { 41 std::reference_wrapper<int ()> r1(f_int_0); 42 assert(r1() == 3); 43 } 44 // function pointer 45 { 46 int (*fp)() = f_int_0; 47 std::reference_wrapper<int (*)()> r1(fp); 48 assert(r1() == 3); 49 } 50 // functor 51 { 52 A_int_0 a0; 53 std::reference_wrapper<A_int_0> r1(a0); 54 assert(r1() == 4); 55 } 56 } 57 58 // 1 arg, return void 59 60 void f_void_1(int i) 61 { 62 count += i; 63 } 64 65 struct A_void_1 66 { 67 void operator()(int i) 68 { 69 count += i; 70 } 71 }; 72 73 int main() 74 { 75 test_int_0(); 76 } 77