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 // reference_wrapper& operator=(const reference_wrapper<T>& x); 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 t2 = t; 28 std::reference_wrapper<T> r2(t2); 29 r2 = r; 30 assert(&r2.get() == &t); 31 } 32 33 void f() {} 34 void g() {} 35 36 void 37 test_function() 38 { 39 std::reference_wrapper<void ()> r(f); 40 std::reference_wrapper<void ()> r2(g); 41 r2 = r; 42 assert(&r2.get() == &f); 43 } 44 45 int main(int, char**) 46 { 47 void (*fp)() = f; 48 test(fp); 49 test_function(); 50 functor1 f1; 51 test(f1); 52 int i = 0; 53 test(i); 54 const int j = 0; 55 test(j); 56 57 return 0; 58 } 59