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 // 0 args, return void 22 23 int count = 0; 24 25 void f_void_0() 26 { 27 ++count; 28 } 29 30 struct A_void_0 31 { 32 void operator()() {++count;} 33 }; 34 35 void 36 test_void_0() 37 { 38 int save_count = count; 39 // function 40 { 41 std::reference_wrapper<void ()> r1(f_void_0); 42 r1(); 43 assert(count == save_count+1); 44 save_count = count; 45 } 46 // function pointer 47 { 48 void (*fp)() = f_void_0; 49 std::reference_wrapper<void (*)()> r1(fp); 50 r1(); 51 assert(count == save_count+1); 52 save_count = count; 53 } 54 // functor 55 { 56 A_void_0 a0; 57 std::reference_wrapper<A_void_0> r1(a0); 58 r1(); 59 assert(count == save_count+1); 60 save_count = count; 61 } 62 } 63 64 int main(int, char**) 65 { 66 test_void_0(); 67 68 return 0; 69 } 70