Added emplace(void) for older compilers

This commit is contained in:
Andrzej Krzemienski
2015-05-15 16:27:40 +02:00
parent 339202a8fb
commit 8ca74951b0
7 changed files with 65 additions and 33 deletions

View File

@ -18,12 +18,14 @@
#define BOOST_OPTIONAL_OPTIONAL_FLC_19NOV2002_HPP
#include <new>
#include <algorithm>
#include <iosfwd>
#include <boost/config.hpp>
#include <boost/assert.hpp>
#include <boost/core/addressof.hpp>
#include <boost/core/enable_if.hpp>
#include <boost/core/explicit_operator_bool.hpp>
#include <boost/core/swap.hpp>
#include <boost/optional/bad_optional_access.hpp>
#include <boost/static_assert.hpp>
#include <boost/throw_exception.hpp>
@ -47,13 +49,7 @@
#include <boost/detail/reference_content.hpp>
#include <boost/move/utility.hpp>
#include <boost/none.hpp>
#include <boost/utility/addressof.hpp>
#include <boost/utility/compare_pointees.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/utility/in_place_factory.hpp>
#include <boost/utility/swap.hpp>
#include <boost/optional/optional_fwd.hpp>
@ -506,6 +502,13 @@ class optional_base : public optional_tag
::new (m_storage.address()) internal_type( boost::forward<Arg>(arg) );
m_initialized = true ;
}
void emplace_assign ()
{
destroy();
::new (m_storage.address()) internal_type();
m_initialized = true ;
}
#else
template<class Arg>
void emplace_assign ( const Arg& arg )
@ -515,13 +518,20 @@ class optional_base : public optional_tag
m_initialized = true ;
}
template<class Arg>
template<class Arg>
void emplace_assign ( Arg& arg )
{
destroy();
::new (m_storage.address()) internal_type( arg );
m_initialized = true ;
}
void emplace_assign ()
{
destroy();
::new (m_storage.address()) internal_type();
m_initialized = true ;
}
#endif
#ifndef BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT
@ -976,6 +986,11 @@ class optional : public optional_detail::optional_base<T>
{
this->emplace_assign( boost::forward<Arg>(arg) );
}
void emplace ()
{
this->emplace_assign();
}
#else
template<class Arg>
void emplace ( const Arg& arg )
@ -988,6 +1003,11 @@ class optional : public optional_detail::optional_base<T>
{
this->emplace_assign( arg );
}
void emplace ()
{
this->emplace_assign();
}
#endif
void swap( optional & arg )
@ -1448,9 +1468,9 @@ struct swap_selector<true>
return;
if( !hasX )
x = boost::in_place();
x.emplace();
else if ( !hasY )
y = boost::in_place();
y.emplace();
// Boost.Utility.Swap will take care of ADL and workarounds for broken compilers
boost::swap(x.get(),y.get());