////////////////////////////////////////////////////////////////////////////// // // (C) Copyright David Abrahams, Vicente Botet, Ion Gaztanaga 2009. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // See http://www.boost.org/libs/move for documentation. // ////////////////////////////////////////////////////////////////////////////// #include //[construct_forward_example #include #include class copyable_only_tester { public: copyable_only_tester() { std::cout << "copyable_only_tester()" << std::endl; } copyable_only_tester(const copyable_only_tester&) { std::cout << "copyable_only_tester(const copyable_only_tester&)" << std::endl; } copyable_only_tester(int) { std::cout << "copyable_only_tester(int)" << std::endl; } copyable_only_tester(int, double) { std::cout << "copyable_only_tester(int, double)" << std::endl; } }; class copyable_movable_tester { // move semantics BOOST_COPYABLE_AND_MOVABLE(copyable_movable_tester) public: copyable_movable_tester() { std::cout << "copyable_movable_tester()" << std::endl; } copyable_movable_tester(int) { std::cout << "copyable_movable_tester(int)" << std::endl; } copyable_movable_tester(BOOST_RV_REF(copyable_movable_tester)) { std::cout << "copyable_movable_tester(BOOST_RV_REF(copyable_movable_tester))" << std::endl; } copyable_movable_tester(const copyable_movable_tester &) { std::cout << "copyable_movable_tester(const copyable_movable_tester &)" << std::endl; } copyable_movable_tester(BOOST_RV_REF(copyable_movable_tester), BOOST_RV_REF(copyable_movable_tester)) { std::cout << "copyable_movable_tester(BOOST_RV_REF(copyable_movable_tester), BOOST_RV_REF(copyable_movable_tester))" << std::endl; } copyable_movable_tester &operator=(BOOST_RV_REF(copyable_movable_tester)) { std::cout << "copyable_movable_tester & operator=(BOOST_RV_REF(copyable_movable_tester))" << std::endl; return *this; } copyable_movable_tester &operator=(BOOST_COPY_ASSIGN_REF(copyable_movable_tester)) { std::cout << "copyable_movable_tester & operator=(BOOST_COPY_ASSIGN_REF(copyable_movable_tester))" << std::endl; return *this; } }; //1 argument template void function_construct(BOOST_FWD_REF(MaybeRv) x) { MaybeMovable m(boost::forward(x)); } //2 argument template void function_construct(BOOST_FWD_REF(MaybeRv) x, BOOST_FWD_REF(MaybeRv2) x2) { MaybeMovable m(boost::forward(x), boost::forward(x2)); } int main() { copyable_movable_tester m; //move constructor function_construct(boost::move(m)); //copy constructor function_construct(copyable_movable_tester()); //two rvalue constructor function_construct(boost::move(m), boost::move(m)); copyable_only_tester nm; //copy constructor (copyable_only_tester has no move ctor.) function_construct(boost::move(nm)); //copy constructor function_construct(nm); //int constructor function_construct(int(0)); //int, double constructor function_construct(int(0), double(0.0)); //Output is: //copyable_movable_tester() //copyable_movable_tester(BOOST_RV_REF(copyable_movable_tester)) //copyable_movable_tester() //copyable_movable_tester(const copyable_movable_tester &) //copyable_movable_tester(BOOST_RV_REF(copyable_movable_tester), BOOST_RV_REF(copyable_movable_tester)) //copyable_only_tester() //copyable_only_tester(const copyable_only_tester&) //copyable_only_tester(const copyable_only_tester&) //copyable_only_tester(int) //copyable_only_tester(int, double) return 0; } //] #include