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 : public std::unary_function<int, char> 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()47int main() 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