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 int
22 
23 int count = 0;
24 
25 int f_int_0()
26 {
27     return 3;
28 }
29 
30 struct A_int_0
31 {
32     int operator()() {return 4;}
33 };
34 
35 void
36 test_int_0()
37 {
38     // function
39     {
40     std::reference_wrapper<int ()> r1(f_int_0);
41     assert(r1() == 3);
42     }
43     // function pointer
44     {
45     int (*fp)() = f_int_0;
46     std::reference_wrapper<int (*)()> r1(fp);
47     assert(r1() == 3);
48     }
49     // functor
50     {
51     A_int_0 a0;
52     std::reference_wrapper<A_int_0> r1(a0);
53     assert(r1() == 4);
54     }
55 }
56 
57 // 1 arg, return void
58 
59 void f_void_1(int i)
60 {
61     count += i;
62 }
63 
64 struct A_void_1
65 {
66     void operator()(int i)
67     {
68         count += i;
69     }
70 };
71 
72 int main(int, char**)
73 {
74     test_int_0();
75 
76   return 0;
77 }
78