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