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()16 int main()
17 {
18    return 0;
19 }
20 
21 #else
22 
23 #include <boost/move/detail/config_begin.hpp>
24 
25 //[how_works_example
26 #include <boost/move/core.hpp>
27 #include <iostream>
28 
29 class sink_tester
30 {
31    public: //conversions provided by BOOST_COPYABLE_AND_MOVABLE
operator ::boost::rv<sink_tester>&()32    operator ::boost::rv<sink_tester>&()
33       {  return *static_cast< ::boost::rv<sink_tester>* >(this);  }
operator const::boost::rv<sink_tester>&() const34    operator const ::boost::rv<sink_tester>&() const
35       {  return *static_cast<const ::boost::rv<sink_tester>* >(this);  }
36 };
37 
38 //Functions returning different r/lvalue types
rvalue()39       sink_tester    rvalue()       {  return sink_tester(); }
const_rvalue()40 const sink_tester    const_rvalue() {  return sink_tester(); }
lvalue()41       sink_tester &  lvalue()       {  static sink_tester lv; return lv; }
const_lvalue()42 const sink_tester &  const_lvalue() {  static const sink_tester clv = sink_tester(); return clv; }
43 
44 //BOOST_RV_REF overload
sink(::boost::rv<sink_tester> &)45 void sink(::boost::rv<sink_tester> &)      { std::cout << "non-const rvalue catched" << std::endl; }
46 //BOOST_COPY_ASSIGN_REF overload
sink(const::boost::rv<sink_tester> &)47 void sink(const ::boost::rv<sink_tester> &){ std::cout << "const (r-l)value catched" << std::endl; }
48 //Overload provided by BOOST_COPYABLE_AND_MOVABLE
sink(sink_tester &)49 void sink(sink_tester &)                   { std::cout << "non-const lvalue catched" << std::endl; }
50 
main()51 int main()
52 {
53    sink(const_rvalue());   //"const (r-l)value catched"
54    sink(const_lvalue());   //"const (r-l)value catched"
55    sink(lvalue());         //"non-const lvalue catched"
56    sink(rvalue());         //"non-const rvalue catched"
57    return 0;
58 }
59 //]
60 
61 #include <boost/move/detail/config_end.hpp>
62 
63 #endif
64