1 ////////////////////////////////////////////////////////////////////////////// 2 // 3 // (C) Copyright Ion Gaztanaga 2009. 4 // Distributed under the Boost Software License, Version 1.0. 5 // (See accompanying file LICENSE_1_0.txt or copy at 6 // http://www.boost.org/LICENSE_1_0.txt) 7 // 8 // See http://www.boost.org/libs/move for documentation. 9 // 10 ////////////////////////////////////////////////////////////////////////////// 11 12 #include <boost/config.hpp> 13 14 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 15 main()16int main() 17 { 18 return 0; 19 } 20 21 #else 22 23 //[how_works_example 24 #include <boost/move/core.hpp> 25 #include <iostream> 26 27 class sink_tester 28 { 29 public: //conversions provided by BOOST_COPYABLE_AND_MOVABLE operator ::boost::rv<sink_tester>&()30 operator ::boost::rv<sink_tester>&() 31 { return *static_cast< ::boost::rv<sink_tester>* >(this); } operator const::boost::rv<sink_tester>&() const32 operator const ::boost::rv<sink_tester>&() const 33 { return *static_cast<const ::boost::rv<sink_tester>* >(this); } 34 }; 35 36 //Functions returning different r/lvalue types rvalue()37 sink_tester rvalue() { return sink_tester(); } const_rvalue()38const sink_tester const_rvalue() { return sink_tester(); } lvalue()39 sink_tester & lvalue() { static sink_tester lv; return lv; } const_lvalue()40const sink_tester & const_lvalue() { static const sink_tester clv = sink_tester(); return clv; } 41 42 //BOOST_RV_REF overload sink(::boost::rv<sink_tester> &)43void sink(::boost::rv<sink_tester> &) { std::cout << "non-const rvalue catched" << std::endl; } 44 //BOOST_COPY_ASSIGN_REF overload sink(const::boost::rv<sink_tester> &)45void sink(const ::boost::rv<sink_tester> &){ std::cout << "const (r-l)value catched" << std::endl; } 46 //Overload provided by BOOST_COPYABLE_AND_MOVABLE sink(sink_tester &)47void sink(sink_tester &) { std::cout << "non-const lvalue catched" << std::endl; } 48 main()49int main() 50 { 51 sink(const_rvalue()); //"const (r-l)value catched" 52 sink(const_lvalue()); //"const (r-l)value catched" 53 sink(lvalue()); //"non-const lvalue catched" 54 sink(rvalue()); //"non-const rvalue catched" 55 return 0; 56 } 57 //] 58 59 #endif 60