Boost logo

Boost-Commit :

From: eric_at_[hidden]
Date: 2007-12-09 17:25:23


Author: eric_niebler
Date: 2007-12-09 17:25:23 EST (Sun, 09 Dec 2007)
New Revision: 41941
URL: http://svn.boost.org/trac/boost/changeset/41941

Log:
Merged revisions 41916-41940 via svnmerge from
https://svn.boost.org/svn/boost/trunk

........
  r41919 | niels_dekker | 2007-12-09 03:53:08 -0800 (Sun, 09 Dec 2007) | 2 lines
  
  Added value_init tests if a copy function of T is called when value_initialized<T> is copied -- a case I hadn't thought of before...
........

Text files modified:
   branches/proto/v3/libs/utility/value_init_test.cpp | 37 +++++++++++++++++++++++++++++++++++++
   1 files changed, 37 insertions(+), 0 deletions(-)

Modified: branches/proto/v3/libs/utility/value_init_test.cpp
==============================================================================
--- branches/proto/v3/libs/utility/value_init_test.cpp (original)
+++ branches/proto/v3/libs/utility/value_init_test.cpp 2007-12-09 17:25:23 EST (Sun, 09 Dec 2007)
@@ -156,6 +156,29 @@
 
 typedef unsigned char ArrayOfBytes[256];
 
+
+//
+// A struct that allows testing whether the appropriate copy functions are called.
+//
+struct CopyFunctionCallTester
+{
+ bool is_copy_constructed;
+ bool is_assignment_called;
+
+ CopyFunctionCallTester()
+ : is_copy_constructed(false), is_assignment_called(false) {}
+
+ CopyFunctionCallTester(const CopyFunctionCallTester & )
+ : is_copy_constructed(true), is_assignment_called(false) {}
+
+ CopyFunctionCallTester & operator=(const CopyFunctionCallTester & )
+ {
+ is_assignment_called = true ;
+ return *this ;
+ }
+};
+
+
 //
 // This test function tests boost::value_initialized<T> for a specific type T.
 // The first argument (y) is assumed have the value of a value-initialized object.
@@ -244,8 +267,22 @@
   boost::value_initialized<ArrayOfBytes> valueInitializedArrayOfBytes;
   BOOST_CHECK (std::memcmp(get(valueInitializedArrayOfBytes), zeroInitializedArrayOfBytes, sizeof(ArrayOfBytes)) == 0);
 
+ boost::value_initialized<CopyFunctionCallTester> copyFunctionCallTester1;
+ BOOST_CHECK ( ! get(copyFunctionCallTester1).is_copy_constructed);
+ BOOST_CHECK ( ! get(copyFunctionCallTester1).is_assignment_called);
+
+ boost::value_initialized<CopyFunctionCallTester> copyFunctionCallTester2 = boost::value_initialized<CopyFunctionCallTester>(copyFunctionCallTester1);
+ BOOST_CHECK ( get(copyFunctionCallTester2).is_copy_constructed);
+ BOOST_CHECK ( ! get(copyFunctionCallTester2).is_assignment_called);
+
+ boost::value_initialized<CopyFunctionCallTester> copyFunctionCallTester3;
+ copyFunctionCallTester3 = boost::value_initialized<CopyFunctionCallTester>(copyFunctionCallTester1);
+ BOOST_CHECK ( ! get(copyFunctionCallTester3).is_copy_constructed);
+ BOOST_CHECK ( get(copyFunctionCallTester3).is_assignment_called);
+
   return 0;
 }
 
 
 unsigned int expected_failures = 0;
+


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