From 86b177d3eea031e3b2b12d20c851dc144b91451b Mon Sep 17 00:00:00 2001 From: Ahmed Charles Date: Fri, 21 Feb 2014 03:14:11 -0800 Subject: [PATCH] Add support for move constructors in C++11 (#6947). --- bitset_test.hpp | 27 +++++++++- dyn_bitset_unit_tests1.cpp | 54 ++++++++++++++++--- dynamic_bitset.html | 50 ++++++++++++++++- .../boost/dynamic_bitset/dynamic_bitset.hpp | 37 ++++++++++++- 4 files changed, 158 insertions(+), 10 deletions(-) diff --git a/bitset_test.hpp b/bitset_test.hpp index ec9baa6..599b5d1 100644 --- a/bitset_test.hpp +++ b/bitset_test.hpp @@ -1,6 +1,7 @@ // ----------------------------------------------------------- // Copyright (c) 2001 Jeremy Siek // Copyright (c) 2003-2006, 2008 Gennaro Prota +// Copyright (c) 2014 Ahmed Charles // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -267,11 +268,12 @@ struct bitset_test { } } - // assignment operator (absent from std::bitset) - static void assignment_operator(const Bitset& lhs, const Bitset& rhs) + // copy assignment operator (absent from std::bitset) + static void copy_assignment_operator(const Bitset& lhs, const Bitset& rhs) { Bitset b(lhs); b = rhs; + b = b; // self assignment check BOOST_CHECK(b == rhs); // Changes to the copy do not affect the original @@ -282,6 +284,27 @@ struct bitset_test { } } +#ifndef BOOST_NO_RVALUE_REFERENCES + + // move constructor (absent from std::bitset) + static void move_constructor(const Bitset& b) + { + Bitset copy(boost::move(b)); + BOOST_CHECK(b == copy); + } + + // move assignment operator (absent from std::bitset) + static void move_assignment_operator(const Bitset& lhs, const Bitset& rhs) + { + Bitset b(lhs); + Bitset c(rhs); + b = boost::move(c); + b = boost::move(b); // self assignment check + BOOST_CHECK(b == rhs); + } + +#endif // BOOST_NO_RVALUE_REFERENCES + static void swap(const Bitset& lhs, const Bitset& rhs) { // bitsets must be swapped diff --git a/dyn_bitset_unit_tests1.cpp b/dyn_bitset_unit_tests1.cpp index a67903d..4cfd19b 100644 --- a/dyn_bitset_unit_tests1.cpp +++ b/dyn_bitset_unit_tests1.cpp @@ -1,6 +1,7 @@ // ----------------------------------------------------------- // Copyright (c) 2001 Jeremy Siek // Copyright (c) 2003-2006 Gennaro Prota +// Copyright (c) 2014 Ahmed Charles // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -237,29 +238,70 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) ) Tests::copy_constructor(b); } //===================================================================== - // Test assignment operator + // Test copy assignment operator { bitset_type a, b; - Tests::assignment_operator(a, b); + Tests::copy_assignment_operator(a, b); } { bitset_type a(std::string("1")), b(std::string("0")); - Tests::assignment_operator(a, b); + Tests::copy_assignment_operator(a, b); } { bitset_type a(long_string), b(long_string); - Tests::assignment_operator(a, b); + Tests::copy_assignment_operator(a, b); } { bitset_type a; bitset_type b(long_string); // b greater than a, a empty - Tests::assignment_operator(a, b); + Tests::copy_assignment_operator(a, b); } { bitset_type a(std::string("0")); bitset_type b(long_string); // b greater than a - Tests::assignment_operator(a, b); + Tests::copy_assignment_operator(a, b); } + +#ifndef BOOST_NO_RVALUE_REFERENCES + //===================================================================== + // Test move constructor + { + boost::dynamic_bitset b; + Tests::move_constructor(b); + } + { + boost::dynamic_bitset b(std::string("0")); + Tests::move_constructor(b); + } + { + boost::dynamic_bitset b(long_string); + Tests::move_constructor(b); + } + //===================================================================== + // Test move assignment operator + { + bitset_type a, b; + Tests::move_assignment_operator(a, b); + } + { + bitset_type a(std::string("1")), b(std::string("0")); + Tests::move_assignment_operator(a, b); + } + { + bitset_type a(long_string), b(long_string); + Tests::move_assignment_operator(a, b); + } + { + bitset_type a; + bitset_type b(long_string); // b greater than a, a empty + Tests::move_assignment_operator(a, b); + } + { + bitset_type a(std::string("0")); + bitset_type b(long_string); // b greater than a + Tests::move_assignment_operator(a, b); + } +#endif // BOOST_NO_RVALUE_REFERENCES //===================================================================== // Test swap { diff --git a/dynamic_bitset.html b/dynamic_bitset.html index cef2fe1..1629802 100644 --- a/dynamic_bitset.html +++ b/dynamic_bitset.html @@ -6,6 +6,7 @@