| 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 |
#include "test_macros.h" |
| 19 |
|
| 20 |
class functor1 |
| 21 |
{ |
| 22 |
}; |
| 23 |
|
| 24 |
template <class T> |
| 25 |
void |
| 26 |
test(T& t) |
| 27 |
{ |
| 28 |
std::reference_wrapper<T> r(t); |
| 29 |
T& r2 = r; |
| 30 |
assert(&r2 == &t); |
| 31 |
} |
| 32 |
|
| 33 |
void f() {} |
| 34 |
|
| 35 |
int main(int, char**) |
| 36 |
{ |
| 37 |
void (*fp)() = f; |
| 38 |
test(fp); |
| 39 |
test(f); |
| 40 |
functor1 f1; |
| 41 |
test(f1); |
| 42 |
int i = 0; |
| 43 |
test(i); |
| 44 |
const int j = 0; |
| 45 |
test(j); |
| 46 |
|
| 47 |
return 0; |
| 48 |
} |