mirror of
https://github.com/boostorg/move.git
synced 2025-07-31 12:57:14 +02:00
Last merge for 1.55
[SVN r85702]
This commit is contained in:
@ -19,6 +19,8 @@
|
||||
|
||||
#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) || (defined(_MSC_VER) && (_MSC_VER == 1600))
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/type_traits/is_class.hpp>
|
||||
#include <boost/type_traits/is_convertible.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#endif
|
||||
#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
@ -28,6 +30,7 @@
|
||||
|
||||
#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
struct not_a_type;
|
||||
struct not_a_type2;
|
||||
#define BOOST_MOVE_CATCH_CONST(U) \
|
||||
typename ::boost::mpl::if_< ::boost::is_class<U>, BOOST_CATCH_CONST_RLVALUE(U), const U &>::type
|
||||
#define BOOST_MOVE_CATCH_RVALUE(U)\
|
||||
@ -40,7 +43,6 @@ struct not_a_type;
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
|
||||
#define BOOST_MOVE_CONVERSION_AWARE_CATCH(PUB_FUNCTION, TYPE, RETURN_VALUE, FWD_FUNCTION)\
|
||||
RETURN_VALUE PUB_FUNCTION(BOOST_MOVE_CATCH_CONST(TYPE) x)\
|
||||
{ return FWD_FUNCTION(static_cast<const TYPE&>(x)); }\
|
||||
@ -72,7 +74,7 @@ struct not_a_type;
|
||||
return FWD_FUNCTION(::boost::move(t));\
|
||||
}\
|
||||
//
|
||||
|
||||
// ::boost::is_convertible<BOOST_MOVE_TEMPL_PARAM, TYPE>::value &&
|
||||
#elif (defined(_MSC_VER) && (_MSC_VER == 1600))
|
||||
|
||||
#define BOOST_MOVE_CONVERSION_AWARE_CATCH(PUB_FUNCTION, TYPE, RETURN_VALUE, FWD_FUNCTION)\
|
||||
@ -108,7 +110,7 @@ struct not_a_type;
|
||||
|
||||
#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
|
||||
#define BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(PUB_FUNCTION, TYPE, RETURN_VALUE, FWD_FUNCTION, ARG1)\
|
||||
#define BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(PUB_FUNCTION, TYPE, RETURN_VALUE, FWD_FUNCTION, ARG1, UNLESS_CONVERTIBLE_TO)\
|
||||
RETURN_VALUE PUB_FUNCTION(ARG1 arg1, BOOST_MOVE_CATCH_CONST(TYPE) x)\
|
||||
{ return FWD_FUNCTION(arg1, static_cast<const TYPE&>(x)); }\
|
||||
\
|
||||
@ -119,8 +121,7 @@ struct not_a_type;
|
||||
{ return FWD_FUNCTION(arg1, const_cast<const TYPE &>(x)); }\
|
||||
\
|
||||
template<class BOOST_MOVE_TEMPL_PARAM>\
|
||||
typename ::boost::enable_if_c\
|
||||
< ::boost::is_class<TYPE>::value &&\
|
||||
typename ::boost::enable_if_c<\
|
||||
::boost::is_same<TYPE, BOOST_MOVE_TEMPL_PARAM>::value &&\
|
||||
!::boost::has_move_emulation_enabled<BOOST_MOVE_TEMPL_PARAM>::value\
|
||||
, RETURN_VALUE >::type\
|
||||
@ -128,10 +129,10 @@ struct not_a_type;
|
||||
{ return FWD_FUNCTION(arg1, u); }\
|
||||
\
|
||||
template<class BOOST_MOVE_TEMPL_PARAM>\
|
||||
typename ::boost::enable_if_c\
|
||||
< (!::boost::is_class<BOOST_MOVE_TEMPL_PARAM>::value || \
|
||||
!::boost::move_detail::is_rv<BOOST_MOVE_TEMPL_PARAM>::value) && \
|
||||
!::boost::is_same<TYPE, BOOST_MOVE_TEMPL_PARAM>::value \
|
||||
typename ::boost::enable_if_c<\
|
||||
!::boost::move_detail::is_rv<BOOST_MOVE_TEMPL_PARAM>::value && \
|
||||
!::boost::is_same<TYPE, BOOST_MOVE_TEMPL_PARAM>::value && \
|
||||
!::boost::is_convertible<BOOST_MOVE_TEMPL_PARAM, UNLESS_CONVERTIBLE_TO>::value \
|
||||
, RETURN_VALUE >::type\
|
||||
PUB_FUNCTION(ARG1 arg1, const BOOST_MOVE_TEMPL_PARAM &u)\
|
||||
{\
|
||||
@ -142,7 +143,7 @@ struct not_a_type;
|
||||
|
||||
#elif (defined(_MSC_VER) && (_MSC_VER == 1600))
|
||||
|
||||
#define BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(PUB_FUNCTION, TYPE, RETURN_VALUE, FWD_FUNCTION, ARG1)\
|
||||
#define BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(PUB_FUNCTION, TYPE, RETURN_VALUE, FWD_FUNCTION, ARG1, UNLESS_CONVERTIBLE_TO)\
|
||||
RETURN_VALUE PUB_FUNCTION(ARG1 arg1, BOOST_MOVE_CATCH_CONST(TYPE) x)\
|
||||
{ return FWD_FUNCTION(arg1, static_cast<const TYPE&>(x)); }\
|
||||
\
|
||||
@ -151,7 +152,8 @@ struct not_a_type;
|
||||
\
|
||||
template<class BOOST_MOVE_TEMPL_PARAM>\
|
||||
typename ::boost::enable_if_c\
|
||||
< !::boost::is_same<TYPE, BOOST_MOVE_TEMPL_PARAM>::value\
|
||||
< !::boost::is_same<TYPE, BOOST_MOVE_TEMPL_PARAM>::value && \
|
||||
!::boost::is_convertible<BOOST_MOVE_TEMPL_PARAM, UNLESS_CONVERTIBLE_TO>::value \
|
||||
, RETURN_VALUE >::type\
|
||||
PUB_FUNCTION(ARG1 arg1, const BOOST_MOVE_TEMPL_PARAM &u)\
|
||||
{\
|
||||
@ -162,7 +164,7 @@ struct not_a_type;
|
||||
|
||||
#else
|
||||
|
||||
#define BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(PUB_FUNCTION, TYPE, RETURN_VALUE, FWD_FUNCTION, ARG1)\
|
||||
#define BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(PUB_FUNCTION, TYPE, RETURN_VALUE, FWD_FUNCTION, ARG1, UNLESS_CONVERTIBLE_TO)\
|
||||
RETURN_VALUE PUB_FUNCTION(ARG1 arg1, BOOST_MOVE_CATCH_CONST(TYPE) x)\
|
||||
{ return FWD_FUNCTION(arg1, static_cast<const TYPE&>(x)); }\
|
||||
\
|
||||
|
@ -84,34 +84,99 @@ class conversion_target_movable
|
||||
template<class T>
|
||||
class container
|
||||
{
|
||||
typename ::boost::aligned_storage<sizeof(T), ::boost::alignment_of<T>::value>::type storage_;
|
||||
T *storage_;
|
||||
public:
|
||||
struct const_iterator{};
|
||||
struct iterator : const_iterator{};
|
||||
container()
|
||||
: storage_(0)
|
||||
{}
|
||||
|
||||
typedef T * iterator;
|
||||
typedef const T * const_iterator;
|
||||
~container()
|
||||
{ delete storage_; }
|
||||
|
||||
container(const container &c)
|
||||
: storage_(c.storage_ ? new T(*c.storage_) : 0)
|
||||
{}
|
||||
|
||||
container &operator=(const container &c)
|
||||
{
|
||||
if(storage_){
|
||||
delete storage_;
|
||||
storage_ = 0;
|
||||
}
|
||||
storage_ = c.storage_ ? new T(*c.storage_) : 0;
|
||||
return *this;
|
||||
}
|
||||
|
||||
BOOST_MOVE_CONVERSION_AWARE_CATCH(push_back, T, void, priv_push_back)
|
||||
|
||||
BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert, T, iterator, priv_insert, const_iterator)
|
||||
BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert, T, iterator, priv_insert, const_iterator, const_iterator)
|
||||
|
||||
template <class Iterator>
|
||||
iterator insert(Iterator, Iterator){ return iterator(); }
|
||||
|
||||
ConstructionType construction_type() const
|
||||
{ return construction_type_impl(typename ::boost::is_class<T>::type()); }
|
||||
{ return construction_type_impl(typename ::boost::is_class<T>::type()); }
|
||||
|
||||
ConstructionType construction_type_impl(::boost::true_type) const
|
||||
{ return reinterpret_cast<const T&>(storage_).construction_type(); }
|
||||
{ return storage_->construction_type(); }
|
||||
|
||||
ConstructionType construction_type_impl(::boost::false_type) const
|
||||
{ return Copied; }
|
||||
|
||||
iterator begin() { return iterator(0); }
|
||||
{ return Copied; }
|
||||
|
||||
iterator begin() const { return iterator(); }
|
||||
|
||||
private:
|
||||
template<class U>
|
||||
void priv_construct(BOOST_MOVE_CATCH_FWD(U) x)
|
||||
{
|
||||
if(storage_){
|
||||
delete storage_;
|
||||
storage_ = 0;
|
||||
}
|
||||
storage_ = new T(::boost::forward<U>(x));
|
||||
}
|
||||
|
||||
template<class U>
|
||||
void priv_push_back(BOOST_MOVE_CATCH_FWD(U) x)
|
||||
{ ::new (&storage_) T(::boost::forward<U>(x)); }
|
||||
{ priv_construct(::boost::forward<U>(x)); }
|
||||
|
||||
template<class U>
|
||||
iterator priv_insert(const_iterator, BOOST_MOVE_CATCH_FWD(U) x)
|
||||
{ ::new (&storage_) T(::boost::forward<U>(x)); return 0; }
|
||||
{ priv_construct(::boost::forward<U>(x)); return iterator(); }
|
||||
};
|
||||
|
||||
class recursive_container
|
||||
{
|
||||
BOOST_COPYABLE_AND_MOVABLE(recursive_container)
|
||||
public:
|
||||
recursive_container()
|
||||
{}
|
||||
|
||||
recursive_container(const recursive_container &c)
|
||||
: container_(c.container_)
|
||||
{}
|
||||
|
||||
recursive_container(BOOST_RV_REF(recursive_container) c)
|
||||
: container_(::boost::move(c.container_))
|
||||
{}
|
||||
|
||||
recursive_container & operator =(BOOST_COPY_ASSIGN_REF(recursive_container) c)
|
||||
{
|
||||
container_= c.container_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
recursive_container & operator =(BOOST_RV_REF(recursive_container) c)
|
||||
{
|
||||
container_= ::boost::move(c.container_);
|
||||
return *this;
|
||||
}
|
||||
|
||||
container<recursive_container> container_;
|
||||
friend bool operator< (const recursive_container &a, const recursive_container &b)
|
||||
{ return &a < &b; }
|
||||
};
|
||||
|
||||
|
||||
@ -289,6 +354,61 @@ int main()
|
||||
c.insert(c.begin(), conversion_source());
|
||||
assert(c.construction_type() == Copied);
|
||||
}
|
||||
//c.insert(c.begin(), c.begin());
|
||||
}
|
||||
|
||||
{
|
||||
container<int> c;
|
||||
{
|
||||
int x;
|
||||
c.push_back(x);
|
||||
assert(c.construction_type() == Copied);
|
||||
c.insert(c.begin(), c.construction_type());
|
||||
assert(c.construction_type() == Copied);
|
||||
}
|
||||
{
|
||||
const int x = 0;
|
||||
c.push_back(x);
|
||||
assert(c.construction_type() == Copied);
|
||||
c.insert(c.begin(), x);
|
||||
assert(c.construction_type() == Copied);
|
||||
}
|
||||
{
|
||||
c.push_back(int(0));
|
||||
assert(c.construction_type() == Copied);
|
||||
c.insert(c.begin(), int(0));
|
||||
assert(c.construction_type() == Copied);
|
||||
}
|
||||
{
|
||||
conversion_source x;
|
||||
c.push_back(x);
|
||||
assert(c.construction_type() == Copied);
|
||||
c.insert(c.begin(), x);
|
||||
assert(c.construction_type() == Copied);
|
||||
}
|
||||
|
||||
{
|
||||
const conversion_source x;
|
||||
c.push_back(x);
|
||||
assert(c.construction_type() == Copied);
|
||||
c.insert(c.begin(), x);
|
||||
assert(c.construction_type() == Copied);
|
||||
}
|
||||
{
|
||||
c.push_back(conversion_source());
|
||||
assert(c.construction_type() == Copied);
|
||||
c.insert(c.begin(), conversion_source());
|
||||
assert(c.construction_type() == Copied);
|
||||
}
|
||||
c.insert(c.begin(), c.begin());
|
||||
}
|
||||
|
||||
{
|
||||
recursive_container c;
|
||||
recursive_container internal;
|
||||
c.container_.insert(c.container_.begin(), recursive_container());
|
||||
c.container_.insert(c.container_.begin(), internal);
|
||||
c.container_.insert(c.container_.begin(), c.container_.begin());
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -677,5 +797,4 @@ int main()
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
*/
|
||||
*/
|
||||
|
Reference in New Issue
Block a user