diff --git a/test/Jamfile b/test/Jamfile index 21fd42dd..f491d9a8 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -109,6 +109,7 @@ import testing ; [ run sequence/vector_iterator.cpp : : : : ] [ run sequence/vector_make.cpp : : : : ] [ run sequence/vector_misc.cpp : : : : ] + [ run sequence/vector_move.cpp : : : : ] [ run sequence/vector_mutate.cpp : : : : ] [ run sequence/vector_n.cpp : : : : ] [ run sequence/vector_tie.cpp : : : : ] diff --git a/test/sequence/deque_copy.cpp b/test/sequence/deque_copy.cpp index 2cf4a8eb..e9f2b91f 100644 --- a/test/sequence/deque_copy.cpp +++ b/test/sequence/deque_copy.cpp @@ -3,7 +3,7 @@ Copyright (c) 2001-2011 Joel de Guzman Copyright (c) 2006 Dan Marsden - Distributed under the Boost Software License, Version 1.0. (See accompanying + 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) ==============================================================================*/ #include diff --git a/test/sequence/deque_move.cpp b/test/sequence/deque_move.cpp new file mode 100644 index 00000000..42fda2d9 --- /dev/null +++ b/test/sequence/deque_move.cpp @@ -0,0 +1,32 @@ +/*============================================================================= + Copyright (c) 2012 Joel de Guzman + + 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) +==============================================================================*/ +#define BOOST_FUSION_DONT_USE_PREPROCESSED_FILES // $$$ JDG temp $$$ + + +#include + +#if !defined(BOOST_NO_RVALUE_REFERENCES) + +#include + +#define FUSION_SEQUENCE boost::fusion::deque +#include "move.hpp" + +#else +#include +#endif + +int +main() +{ +#if !defined(BOOST_NO_RVALUE_REFERENCES) + test(); +#endif + + return boost::report_errors(); +} + diff --git a/test/sequence/move.hpp b/test/sequence/move.hpp new file mode 100644 index 00000000..c3ce1111 --- /dev/null +++ b/test/sequence/move.hpp @@ -0,0 +1,118 @@ +/*============================================================================= + Copyright (c) 2012 Joel de Guzman + + 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) +==============================================================================*/ +#include + +#if defined(BOOST_NO_RVALUE_REFERENCES) +#error "Valid only on compilers that support rvalues" +#endif + +#include +#include +#include +#include +#include + + +namespace test_detail +{ + int copies = 0; + + void incr_copy() + { + copies++; + } + + struct x //: boost::noncopyable + { + int i; + x() : i(123) {} + + x(x&& rhs) : i(rhs.i) {} + + x& operator=(x&& rhs) + { + i = rhs.i; + return *this; + } + + x(x const& rhs) + { + incr_copy(); + } + + x& operator=(x const& rhs) + { + incr_copy(); + return *this; + } + }; + + typedef std::vector vector_type; + extern bool disable_rvo; // to disable RVO + + vector_type + generate_vec() + { + vector_type v; + v.push_back(x()); + if (disable_rvo) + return v; + return vector_type(); + } + + + template + T move_me(T && val) + { + T r(std::move(val)); + if (disable_rvo) + return r; + return T(); + } + + typedef FUSION_SEQUENCE> return_type; + + return_type + generate() + { + return_type r(generate_vec()); + if (disable_rvo) + return r; + return return_type(); + } + + typedef FUSION_SEQUENCE, x> return_type2; + + return_type2 + generate2() + { + return_type2 r(generate_vec(), x()); + if (disable_rvo) + return r; + return return_type2(); + } +} + +void test() +{ + using namespace boost::fusion; + using namespace test_detail; + + return_type v = move_me(generate()); + BOOST_TEST(copies == 0); + + return_type2 v2 = move_me(generate2()); + BOOST_TEST(copies == 0); + + std::cout << "Copies: " << copies << std::endl; +} + +namespace test_detail +{ + bool disable_rvo = true; +} + diff --git a/test/sequence/vector_move.cpp b/test/sequence/vector_move.cpp new file mode 100644 index 00000000..70483f06 --- /dev/null +++ b/test/sequence/vector_move.cpp @@ -0,0 +1,31 @@ +/*============================================================================= + Copyright (c) 2012 Joel de Guzman + + 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) +==============================================================================*/ +#define BOOST_FUSION_DONT_USE_PREPROCESSED_FILES // $$$ JDG temp $$$ + +#include + +#if !defined(BOOST_NO_RVALUE_REFERENCES) + +#include + +#define FUSION_SEQUENCE boost::fusion::vector +#include "move.hpp" + +#else +#include +#endif + +int +main() +{ +#if !defined(BOOST_NO_RVALUE_REFERENCES) + test(); +#endif + + return boost::report_errors(); +} +