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