invoke_int_0.pass.cpp revision f5256e16dfc425c1d466f6308d4026d529ce9e0b
1//===----------------------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. 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 24int count = 0; 25 26int f_int_0() 27{ 28 return 3; 29} 30 31struct A_int_0 32{ 33 int operator()() {return 4;} 34}; 35 36void 37test_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 59// 1 arg, return void 60 61void f_void_1(int i) 62{ 63 count += i; 64} 65 66struct A_void_1 67{ 68 void operator()(int i) 69 { 70 count += i; 71 } 72}; 73 74int main() 75{ 76 test_int_0(); 77} 78