mirror of
https://github.com/boostorg/utility.git
synced 2025-05-08 18:34:02 +00:00
value_init: Removed aligned_storage::address() calls, to improve TR1 compatibility, as confirmed by John Maddock. Added internal helper function, wrapper_address(), as discussed with Fernando.
[SVN r43025]
This commit is contained in:
parent
1beca24dd8
commit
28596e678d
@ -5,7 +5,7 @@
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// 21 Ago 2002 (Created) Fernando Cacciola
|
||||
// 19 Jan 2008 (Worked around compiler bugs, added initialized_value) Fernando Cacciola, Niels Dekker
|
||||
// 30 Jan 2008 (Worked around compiler bugs, added initialized_value) Fernando Cacciola, Niels Dekker
|
||||
//
|
||||
#ifndef BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP
|
||||
#define BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP
|
||||
@ -37,13 +37,22 @@ class value_initialized
|
||||
remove_const<T>::type data;
|
||||
};
|
||||
|
||||
mutable aligned_storage<sizeof(wrapper), alignment_of<wrapper>::value> x;
|
||||
mutable
|
||||
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x592))
|
||||
typename
|
||||
#endif
|
||||
aligned_storage<sizeof(wrapper), alignment_of<wrapper>::value>::type x;
|
||||
|
||||
wrapper * wrapper_address() const
|
||||
{
|
||||
return static_cast<wrapper *>( static_cast<void*>(&x));
|
||||
}
|
||||
|
||||
public :
|
||||
|
||||
value_initialized()
|
||||
{
|
||||
std::memset(x.address(), 0, sizeof(x));
|
||||
std::memset(&x, 0, sizeof(x));
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(push)
|
||||
#if _MSC_VER >= 1310
|
||||
@ -53,7 +62,7 @@ class value_initialized
|
||||
#pragma warning(disable: 4345)
|
||||
#endif
|
||||
#endif
|
||||
new (x.address()) wrapper();
|
||||
new (wrapper_address()) wrapper();
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
@ -61,24 +70,23 @@ class value_initialized
|
||||
|
||||
value_initialized(value_initialized const & arg)
|
||||
{
|
||||
new (x.address()) wrapper( *static_cast<wrapper const *>(arg.x.address()) );
|
||||
new (wrapper_address()) wrapper( static_cast<wrapper const &>(*(arg.wrapper_address())));
|
||||
}
|
||||
|
||||
value_initialized & operator=(value_initialized const & arg)
|
||||
{
|
||||
T const & arg_data = arg.data();
|
||||
this->data() = arg_data;
|
||||
this->data() = static_cast<T const &>( arg.data() );
|
||||
return *this;
|
||||
}
|
||||
|
||||
~value_initialized()
|
||||
{
|
||||
static_cast<wrapper *>(x.address())->wrapper::~wrapper();
|
||||
wrapper_address()->wrapper::~wrapper();
|
||||
}
|
||||
|
||||
T& data() const
|
||||
{
|
||||
return static_cast<wrapper *>(x.address())->data;
|
||||
return wrapper_address()->data;
|
||||
}
|
||||
|
||||
operator T&() const { return this->data(); }
|
||||
|
Loading…
x
Reference in New Issue
Block a user