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