Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r82887 - in trunk: boost libs/any
From: steven_at_[hidden]
Date: 2013-02-14 13:43:24


Author: steven_watanabe
Date: 2013-02-14 13:43:23 EST (Thu, 14 Feb 2013)
New Revision: 82887
URL: http://svn.boost.org/trac/boost/changeset/82887

Log:
Add free swap. Fixes #7578.
Text files modified:
   trunk/boost/any.hpp | 5 +++++
   trunk/libs/any/any_test.cpp | 26 ++++++++++++++++++++++++++
   2 files changed, 31 insertions(+), 0 deletions(-)

Modified: trunk/boost/any.hpp
==============================================================================
--- trunk/boost/any.hpp (original)
+++ trunk/boost/any.hpp 2013-02-14 13:43:23 EST (Thu, 14 Feb 2013)
@@ -162,6 +162,11 @@
 
     };
 
+ inline void swap(any & lhs, any & rhs)
+ {
+ lhs.swap(rhs);
+ }
+
     class bad_any_cast : public std::bad_cast
     {
     public:

Modified: trunk/libs/any/any_test.cpp
==============================================================================
--- trunk/libs/any/any_test.cpp (original)
+++ trunk/libs/any/any_test.cpp 2013-02-14 13:43:23 EST (Thu, 14 Feb 2013)
@@ -53,6 +53,26 @@
     const test_case_iterator begin = test_cases;
     const test_case_iterator end =
         test_cases + (sizeof test_cases / sizeof *test_cases);
+
+
+
+ struct copy_counter
+ {
+
+ public:
+
+ copy_counter() {}
+ copy_counter(const copy_counter&) { ++count; }
+ copy_counter& operator=(const copy_counter&) { ++count; }
+ static int get_count() { return count; }
+
+ private:
+
+ static int count;
+
+ };
+
+ int copy_counter::count = 0;
 }
 
 namespace any_tests // test definitions
@@ -175,6 +195,12 @@
             any_cast<std::string>(&swapped),
             "comparing address in swapped against original");
         check_equal(swap_result, &original, "address of swap result");
+
+ any copy1 = copy_counter();
+ any copy2 = copy_counter();
+ int count = copy_counter::get_count();
+ swap(copy1, copy2);
+ check_equal(count, copy_counter::get_count(), "checking that free swap doesn't make any copies.");
     }
 
     void test_null_copying()


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk