Debian Codegraph @

libcxx/test/std/utilities/function.objects/refwrap/refwrap.invoke/invoke_int_0.pass.cpp

raw
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
27 int f_int_0()
28 {
29 return 3;
30 }
31
32 struct A_int_0
33 {
34 int operator()() {return 4;}
35 };
36
37 void
38 test_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
61 void f_void_1(int i)
62 {
63 count += i;
64 }
65
66 struct A_void_1
67 {
68 void operator()(int i)
69 {
70 count += i;
71 }
72 };
73
74 int main(int, char**)
75 {
76 test_int_0();
77
78 return 0;
79 }