• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. 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 void
23 
24 int count = 0;
25 
f_void_0()26 void f_void_0()
27 {
28     ++count;
29 }
30 
31 struct A_void_0
32 {
operator ()A_void_033     void operator()() {++count;}
34 };
35 
36 void
test_void_0()37 test_void_0()
38 {
39     int save_count = count;
40     // function
41     {
42     std::reference_wrapper<void ()> r1(f_void_0);
43     r1();
44     assert(count == save_count+1);
45     save_count = count;
46     }
47     // function pointer
48     {
49     void (*fp)() = f_void_0;
50     std::reference_wrapper<void (*)()> r1(fp);
51     r1();
52     assert(count == save_count+1);
53     save_count = count;
54     }
55     // functor
56     {
57     A_void_0 a0;
58     std::reference_wrapper<A_void_0> r1(a0);
59     r1();
60     assert(count == save_count+1);
61     save_count = count;
62     }
63 }
64 
main()65 int main()
66 {
67     test_void_0();
68 }
69