xref: /llvm-project/libcxx/test/std/utilities/function.objects/refwrap/refwrap.access/conversion.pass.cpp (revision 57b08b0944046a6a57ee9b7b479181f548a5b9b4)
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 // operator T& () const;
14 
15 #include <functional>
16 #include <cassert>
17 
18 class functor1
19 {
20 };
21 
22 template <class T>
23 void
24 test(T& t)
25 {
26     std::reference_wrapper<T> r(t);
27     T& r2 = r;
28     assert(&r2 == &t);
29 }
30 
31 void f() {}
32 
33 int main()
34 {
35     void (*fp)() = f;
36     test(fp);
37     test(f);
38     functor1 f1;
39     test(f1);
40     int i = 0;
41     test(i);
42     const int j = 0;
43     test(j);
44 }
45