From b8509c89844a4e77904175f2d3d7cdb399696340 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Tue, 25 Dec 2007 04:38:53 +0000 Subject: [PATCH] Merged revisions 42236-42288 via svnmerge from https://svn.boost.org/svn/boost/trunk ........ r42247 | grafik | 2007-12-22 16:32:17 -0500 (Sat, 22 Dec 2007) | 1 line Fix time related callbacks to new arguments. ........ r42264 | ramey | 2007-12-23 15:00:03 -0500 (Sun, 23 Dec 2007) | 1 line correction to input of zero length strings ........ r42266 | turkanis | 2007-12-23 19:27:12 -0500 (Sun, 23 Dec 2007) | 1 line ported changes from branches/iostreams_dev revisions 42144-42265 ........ r42267 | turkanis | 2007-12-23 19:37:53 -0500 (Sun, 23 Dec 2007) | 1 line last commit accidentally included a commented out #if directive ........ r42270 | eric_niebler | 2007-12-23 22:51:59 -0500 (Sun, 23 Dec 2007) | 1 line add missing #includes ........ r42274 | troyer | 2007-12-24 02:06:11 -0500 (Mon, 24 Dec 2007) | 1 line removed warning ........ r42277 | niels_dekker | 2007-12-24 15:42:16 -0500 (Mon, 24 Dec 2007) | 1 line value_init now uses aligned_storage::address(), instead of "&x", as recommended by Fernando Cacciola (by mail) ........ r42278 | niels_dekker | 2007-12-24 17:00:37 -0500 (Mon, 24 Dec 2007) | 1 line Added value_init tests, testing copy construction and assignment. ........ [SVN r42289] --- include/boost/utility/value_init.hpp | 24 +++++++----------------- value_init_test.cpp | 7 +++++++ 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/include/boost/utility/value_init.hpp b/include/boost/utility/value_init.hpp index f5f04bf..097f21a 100644 --- a/include/boost/utility/value_init.hpp +++ b/include/boost/utility/value_init.hpp @@ -5,9 +5,7 @@ // http://www.boost.org/LICENSE_1_0.txt) // // 21 Ago 2002 (Created) Fernando Cacciola -// 07 Set 2007 (Worked around MSVC++ bug) Fernando Cacciola, Niels Dekker -// 16 Nov 2007 (Refactoring: removed private base classes) Fernando Cacciola, Niels Dekker -// 09 Dec 2007 (Worked around various compiler bugs) Fernando Cacciola, Niels Dekker +// 24 Dec 2007 (Refactored and worked around various compiler bugs) Fernando Cacciola, Niels Dekker // #ifndef BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP #define BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP @@ -30,7 +28,6 @@ // clearing the bytes of T, before constructing the T object it contains. #include -#include #include #include #include @@ -51,17 +48,13 @@ class value_initialized remove_const::type data; }; - mutable -#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x592)) - typename -#endif - ::boost::aligned_storage::value>::type x; + mutable aligned_storage::value> x; public : value_initialized() { - std::memset(&x, 0, sizeof(x)); + std::memset(x.address(), 0, sizeof(x)); #ifdef BOOST_MSVC #pragma warning(push) #if _MSC_VER >= 1310 @@ -71,7 +64,7 @@ class value_initialized #pragma warning(disable: 4345) #endif #endif - new (&x) wrapper(); + new (x.address()) wrapper(); #ifdef BOOST_MSVC #pragma warning(pop) #endif @@ -79,8 +72,7 @@ class value_initialized value_initialized(value_initialized const & arg) { - void const * const ptr = &(arg.x); - new (&x) wrapper( *static_cast(ptr) ); + new (x.address()) wrapper( *static_cast(arg.x.address()) ); } value_initialized & operator=(value_initialized const & arg) @@ -93,14 +85,12 @@ class value_initialized ~value_initialized() { - void * const ptr = &x; - static_cast(ptr)->wrapper::~wrapper(); + static_cast(x.address())->wrapper::~wrapper(); } T& data() const { - void * const ptr = &x; - return static_cast(ptr)->data; + return static_cast(x.address())->data; } operator T&() const { return this->data(); } diff --git a/value_init_test.cpp b/value_init_test.cpp index 00c3333..6dc8e27 100644 --- a/value_init_test.cpp +++ b/value_init_test.cpp @@ -202,6 +202,13 @@ bool test ( T const& y, T const& z ) x_c_ref = z ; BOOST_CHECK ( x_c == z ) ; + boost::value_initialized const copy1 = x; + BOOST_CHECK ( boost::get(copy1) == boost::get(x) ) ; + + boost::value_initialized copy2; + copy2 = x; + BOOST_CHECK ( boost::get(copy2) == boost::get(x) ) ; + boost::shared_ptr > ptr( new boost::value_initialized ); BOOST_CHECK ( y == *ptr ) ;