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