Merge branch 'develop'

This commit is contained in:
Ion Gaztañaga
2015-04-19 11:09:15 +02:00
7 changed files with 338 additions and 88 deletions

View File

@@ -53,6 +53,12 @@
#include <boost/move/detail/type_traits.hpp>
#if 1
#define BOOST_MOVE_TO_RV_CAST(RV_TYPE, ARG) static_cast<RV_TYPE>(ARG)
#else
#define BOOST_MOVE_TO_RV_CAST(RV_TYPE, ARG) reinterpret_cast<RV_TYPE>(ARG)
#endif
//Move emulation rv breaks standard aliasing rules so add workarounds for some compilers
#if defined(__GNUC__) && (__GNUC__ >= 4) && \
(\
@@ -101,6 +107,12 @@
: integral_constant<bool, ::boost::move_detail::is_rv_impl<T>::value >
{};
template <class T>
struct is_not_rv
{
static const bool value = !is_rv<T>::value;
};
} //namespace move_detail {
//////////////////////////////////////////////////////////////////////////////
@@ -113,6 +125,12 @@
: ::boost::move_detail::has_move_emulation_enabled_impl<T>
{};
template<class T>
struct has_move_emulation_disabled
{
static const bool value = !::boost::move_detail::has_move_emulation_enabled_impl<T>::value;
};
} //namespace boost {
#define BOOST_RV_REF(TYPE)\
@@ -183,7 +201,7 @@
, ::boost::rv<T>&>::type
move_return(T& x) BOOST_NOEXCEPT
{
return *static_cast< ::boost::rv<T>* >(::boost::move_detail::addressof(x));
return *BOOST_MOVE_TO_RV_CAST(::boost::rv<T>*, ::boost::move_detail::addressof(x));
}
template <class Ret, class T>
@@ -216,9 +234,9 @@
BOOST_MOVE_IMPL_NO_COPY_CTOR_OR_ASSIGN(TYPE)\
public:\
operator ::boost::rv<TYPE>&() \
{ return *static_cast< ::boost::rv<TYPE>* >(this); }\
{ return *BOOST_MOVE_TO_RV_CAST(::boost::rv<TYPE>*, this); }\
operator const ::boost::rv<TYPE>&() const \
{ return *static_cast<const ::boost::rv<TYPE>* >(this); }\
{ return *BOOST_MOVE_TO_RV_CAST(const ::boost::rv<TYPE>*, this); }\
private:\
//
@@ -231,21 +249,21 @@
#define BOOST_COPYABLE_AND_MOVABLE(TYPE)\
public:\
TYPE& operator=(TYPE &t)\
{ this->operator=(static_cast<const ::boost::rv<TYPE> &>(const_cast<const TYPE &>(t))); return *this;}\
{ this->operator=(const_cast<const TYPE &>(t)); return *this;}\
public:\
operator ::boost::rv<TYPE>&() \
{ return *static_cast< ::boost::rv<TYPE>* >(this); }\
{ return *BOOST_MOVE_TO_RV_CAST(::boost::rv<TYPE>*, this); }\
operator const ::boost::rv<TYPE>&() const \
{ return *static_cast<const ::boost::rv<TYPE>* >(this); }\
{ return *BOOST_MOVE_TO_RV_CAST(const ::boost::rv<TYPE>*, this); }\
private:\
//
#define BOOST_COPYABLE_AND_MOVABLE_ALT(TYPE)\
public:\
operator ::boost::rv<TYPE>&() \
{ return *static_cast< ::boost::rv<TYPE>* >(this); }\
{ return *BOOST_MOVE_TO_RV_CAST(::boost::rv<TYPE>*, this); }\
operator const ::boost::rv<TYPE>&() const \
{ return *static_cast<const ::boost::rv<TYPE>* >(this); }\
{ return *BOOST_MOVE_TO_RV_CAST(const ::boost::rv<TYPE>*, this); }\
private:\
//
@@ -295,6 +313,12 @@
static const bool value = false;
};
template<class T>
struct has_move_emulation_disabled
{
static const bool value = true;
};
} //namespace boost{
//!This macro is used to achieve portable syntax in move

View File

@@ -33,11 +33,53 @@ template <class T> class rv;
namespace move_detail {
//////////////////////////////////////
// is_different
//////////////////////////////////////
template<class T, class U>
struct is_different
{
static const bool value = !is_same<T, U>::value;
};
//////////////////////////////////////
// apply
//////////////////////////////////////
template<class F, class Param>
struct apply
{
typedef typename F::template apply<Param>::type type;
};
//////////////////////////////////////
// bool_
//////////////////////////////////////
template< bool C_ >
struct bool_ : integral_constant<bool, C_>
{
operator bool() const { return C_; }
bool operator()() const { return C_; }
};
typedef bool_<true> true_;
typedef bool_<false> false_;
//////////////////////////////////////
// nat
//////////////////////////////////////
struct nat{};
//////////////////////////////////////
// yes_type/no_type
//////////////////////////////////////
typedef char yes_type;
struct no_type
{
char _[2];
};
//////////////////////////////////////
// natify
//////////////////////////////////////
@@ -86,9 +128,27 @@ struct remove_reference< const rv<T> &>
typedef T type;
};
#endif
//////////////////////////////////////
// remove_pointer
//////////////////////////////////////
template< class T > struct remove_pointer { typedef T type; };
template< class T > struct remove_pointer<T*> { typedef T type; };
template< class T > struct remove_pointer<T* const> { typedef T type; };
template< class T > struct remove_pointer<T* volatile> { typedef T type; };
template< class T > struct remove_pointer<T* const volatile> { typedef T type; };
//////////////////////////////////////
// add_pointer
//////////////////////////////////////
template< class T >
struct add_pointer
{
typedef typename remove_reference<T>::type* type;
};
//////////////////////////////////////
// add_const
//////////////////////////////////////
@@ -151,6 +211,19 @@ struct is_lvalue_reference<T&>
static const bool value = true;
};
//////////////////////////////////////
// identity
//////////////////////////////////////
template <class T>
struct identity
{
typedef T type;
typedef typename add_const_lvalue_reference<T>::type reference;
reference operator()(reference t)
{ return t; }
};
//////////////////////////////////////
// is_class_or_union
//////////////////////////////////////
@@ -241,9 +314,128 @@ class is_convertible
#endif
template<
bool C
, typename F1
, typename F2
>
struct eval_if_c
: if_c<C,F1,F2>::type
{};
template<
typename C
, typename T1
, typename T2
>
struct eval_if
: if_<C,T1,T2>::type
{};
template<class T, class U, class R = void>
struct enable_if_convertible
: enable_if< is_convertible<T, U>, R>
{};
template<class T, class U, class R = void>
struct disable_if_convertible
: disable_if< is_convertible<T, U>, R>
{};
//////////////////////////////////////////////////////////////////////////////
//
// has_move_emulation_enabled_impl
// and_
//
//////////////////////////////////////////////////////////////////////////////
template<bool Bool, class B = true_, class C = true_, class D = true_>
struct and_impl
: and_impl<B::value, C, D>
{};
template<>
struct and_impl<true, true_, true_, true_>
{
static const bool value = true;
};
template<class B, class C, class D>
struct and_impl<false, B, C, D>
{
static const bool value = false;
};
template<class A, class B, class C = true_, class D = true_>
struct and_
: and_impl<A::value, B, C, D>
{};
//////////////////////////////////////////////////////////////////////////////
//
// or_
//
//////////////////////////////////////////////////////////////////////////////
template<bool Bool, class B = false_, class C = false_, class D = false_>
struct or_impl
: or_impl<B::value, C, D>
{};
template<>
struct or_impl<false, false_, false_, false_>
{
static const bool value = false;
};
template<class B, class C, class D>
struct or_impl<true, B, C, D>
{
static const bool value = true;
};
template<class A, class B, class C = false_, class D = false_>
struct or_
: or_impl<A::value, B, C, D>
{};
//////////////////////////////////////////////////////////////////////////////
//
// not_
//
//////////////////////////////////////////////////////////////////////////////
template<class T>
struct not_
{
static const bool value = !T::value;
};
//////////////////////////////////////////////////////////////////////////////
//
// enable_if_and / disable_if_and / enable_if_or / disable_if_or
//
//////////////////////////////////////////////////////////////////////////////
template<class R, class A, class B, class C = true_, class D = true_>
struct enable_if_and
: enable_if_c< and_<A, B, C, D>::value, R>
{};
template<class R, class A, class B, class C = true_, class D = true_>
struct disable_if_and
: disable_if_c< and_<A, B, C, D>::value, R>
{};
template<class R, class A, class B, class C = false_, class D = false_>
struct enable_if_or
: enable_if_c< or_<A, B, C, D>::value, R>
{};
template<class R, class A, class B, class C = false_, class D = false_>
struct disable_if_or
: disable_if_c< or_<A, B, C, D>::value, R>
{};
//////////////////////////////////////////////////////////////////////////////
//
// has_move_emulation_enabled_impl
//
//////////////////////////////////////////////////////////////////////////////
template<class T>

View File

@@ -49,16 +49,15 @@ template<typename T1, typename T2, typename T3>
struct if_ : if_c<0 != T1::value, T2, T3>
{};
//enable_if_
//////////////////////////////////////
// enable_if_c
//////////////////////////////////////
template <bool B, class T = void>
struct enable_if_c
{
typedef T type;
};
//////////////////////////////////////
// enable_if_c
//////////////////////////////////////
template <class T>
struct enable_if_c<false, T> {};
@@ -68,6 +67,14 @@ struct enable_if_c<false, T> {};
template <class Cond, class T = void>
struct enable_if : enable_if_c<Cond::value, T> {};
//////////////////////////////////////
// disable_if_c
//////////////////////////////////////
template <bool B, class T = void>
struct disable_if_c
: enable_if_c<!B, T>
{};
//////////////////////////////////////
// disable_if
//////////////////////////////////////
@@ -83,19 +90,14 @@ struct integral_constant
static const T value = v;
typedef T value_type;
typedef integral_constant<T, v> type;
operator T() const { return value; }
T operator()() const { return value; }
};
typedef integral_constant<bool, true > true_type;
typedef integral_constant<bool, false > false_type;
//////////////////////////////////////
// identity
//////////////////////////////////////
template <class T>
struct identity
{
typedef T type;
};
//////////////////////////////////////
// is_same

View File

@@ -48,20 +48,24 @@
{ return FWD_FUNCTION(const_cast<const TYPE &>(x)); }\
\
template<class BOOST_MOVE_TEMPL_PARAM>\
typename ::boost::move_detail::enable_if_c\
< ::boost::move_detail::is_class_or_union<TYPE>::value &&\
::boost::move_detail::is_same<TYPE, BOOST_MOVE_TEMPL_PARAM>::value &&\
!::boost::has_move_emulation_enabled<BOOST_MOVE_TEMPL_PARAM>::value\
, RETURN_VALUE >::type\
typename ::boost::move_detail::enable_if_and\
< RETURN_VALUE \
, ::boost::move_detail::is_same<TYPE, BOOST_MOVE_TEMPL_PARAM>\
, ::boost::move_detail::is_class_or_union<TYPE>\
, ::boost::has_move_emulation_disabled<BOOST_MOVE_TEMPL_PARAM>\
>::type\
PUB_FUNCTION(const BOOST_MOVE_TEMPL_PARAM &u)\
{ return FWD_FUNCTION(u); }\
\
template<class BOOST_MOVE_TEMPL_PARAM>\
typename ::boost::move_detail::enable_if_c\
< (!::boost::move_detail::is_class_or_union<BOOST_MOVE_TEMPL_PARAM>::value || \
!::boost::move_detail::is_rv<BOOST_MOVE_TEMPL_PARAM>::value) && \
!::boost::move_detail::is_same<TYPE, BOOST_MOVE_TEMPL_PARAM>::value \
, RETURN_VALUE >::type\
typename ::boost::move_detail::disable_if_or\
< RETURN_VALUE \
, ::boost::move_detail::is_same<TYPE, BOOST_MOVE_TEMPL_PARAM> \
, ::boost::move_detail::and_ \
< ::boost::move_detail::is_rv<BOOST_MOVE_TEMPL_PARAM> \
, ::boost::move_detail::is_class_or_union<BOOST_MOVE_TEMPL_PARAM> \
> \
>::type\
PUB_FUNCTION(const BOOST_MOVE_TEMPL_PARAM &u)\
{\
TYPE t(u);\
@@ -115,19 +119,21 @@
{ return FWD_FUNCTION(arg1, const_cast<const TYPE &>(x)); }\
\
template<class BOOST_MOVE_TEMPL_PARAM>\
typename ::boost::move_detail::enable_if_c<\
::boost::move_detail::is_same<TYPE, BOOST_MOVE_TEMPL_PARAM>::value &&\
!::boost::has_move_emulation_enabled<BOOST_MOVE_TEMPL_PARAM>::value\
, RETURN_VALUE >::type\
typename ::boost::move_detail::enable_if_and\
< RETURN_VALUE \
, ::boost::move_detail::is_same<TYPE, BOOST_MOVE_TEMPL_PARAM>\
, ::boost::has_move_emulation_disabled<BOOST_MOVE_TEMPL_PARAM>\
>::type\
PUB_FUNCTION(ARG1 arg1, const BOOST_MOVE_TEMPL_PARAM &u)\
{ return FWD_FUNCTION(arg1, u); }\
\
template<class BOOST_MOVE_TEMPL_PARAM>\
typename ::boost::move_detail::enable_if_c<\
!::boost::move_detail::is_rv<BOOST_MOVE_TEMPL_PARAM>::value && \
!::boost::move_detail::is_same<TYPE, BOOST_MOVE_TEMPL_PARAM>::value && \
!::boost::move_detail::is_convertible<BOOST_MOVE_TEMPL_PARAM, UNLESS_CONVERTIBLE_TO>::value \
, RETURN_VALUE >::type\
typename ::boost::move_detail::disable_if_or\
< RETURN_VALUE \
, ::boost::move_detail::is_rv<BOOST_MOVE_TEMPL_PARAM>\
, ::boost::move_detail::is_same<TYPE, BOOST_MOVE_TEMPL_PARAM>\
, ::boost::move_detail::is_convertible<BOOST_MOVE_TEMPL_PARAM, UNLESS_CONVERTIBLE_TO>\
>::type\
PUB_FUNCTION(ARG1 arg1, const BOOST_MOVE_TEMPL_PARAM &u)\
{\
TYPE t(u);\
@@ -145,10 +151,11 @@
{ return FWD_FUNCTION(arg1, ::boost::move(x)); }\
\
template<class BOOST_MOVE_TEMPL_PARAM>\
typename ::boost::move_detail::enable_if_c\
< !::boost::move_detail::is_same<TYPE, BOOST_MOVE_TEMPL_PARAM>::value && \
!::boost::move_detail::is_convertible<BOOST_MOVE_TEMPL_PARAM, UNLESS_CONVERTIBLE_TO>::value \
, RETURN_VALUE >::type\
typename ::boost::move_detail::disable_if_or\
< RETURN_VALUE \
, ::boost::move_detail::is_same<TYPE, BOOST_MOVE_TEMPL_PARAM> \
, ::boost::move_detail::is_convertible<BOOST_MOVE_TEMPL_PARAM, UNLESS_CONVERTIBLE_TO> \
>::type\
PUB_FUNCTION(ARG1 arg1, const BOOST_MOVE_TEMPL_PARAM &u)\
{\
TYPE t(u);\

View File

@@ -341,23 +341,17 @@ struct is_pointer<T*>
{ static const bool value = true; };
//////////////////////////
// add_reference
// unvoid_ref
//////////////////////////
template <typename T> struct unvoid_ref : add_lvalue_reference<T>{};
template <> struct unvoid_ref<void> { typedef unvoid_ref & type; };
template <> struct unvoid_ref<const void> { typedef unvoid_ref & type; };
template <> struct unvoid_ref<volatile void> { typedef unvoid_ref & type; };
template <> struct unvoid_ref<const volatile void> { typedef unvoid_ref & type; };
template <typename T>
struct add_reference
{ typedef T& type; };
template<class T>
struct add_reference<T&>
{ typedef T& type; };
template<>
struct add_reference<void>
{ typedef nat &type; };
template<>
struct add_reference<const void>
{ typedef const nat &type; };
struct add_reference : add_lvalue_reference<T>
{};
//////////////////////////
// add_const_reference
@@ -370,6 +364,14 @@ template <class T>
struct add_const_reference<T&>
{ typedef T& type; };
//////////////////////////
// add_const_if_c
//////////////////////////
template<class T, bool Add>
struct add_const_if_c
: if_c<Add, typename add_const<T>::type, T>
{};
//////////////////////////
// remove_const
//////////////////////////

View File

@@ -47,24 +47,33 @@
//////////////////////////////////////////////////////////////////////////////
template <class T>
inline typename ::boost::move_detail::enable_if_c
< enable_move_utility_emulation<T>::value && !has_move_emulation_enabled<T>::value, T&>::type
inline typename ::boost::move_detail::enable_if_and
< T &
, enable_move_utility_emulation<T>
, has_move_emulation_disabled<T>
>::type
move(T& x) BOOST_NOEXCEPT
{
return x;
}
template <class T>
inline typename ::boost::move_detail::enable_if_c
< enable_move_utility_emulation<T>::value && has_move_emulation_enabled<T>::value, rv<T>&>::type
inline typename ::boost::move_detail::enable_if_and
< rv<T>&
, enable_move_utility_emulation<T>
, has_move_emulation_enabled<T>
>::type
move(T& x) BOOST_NOEXCEPT
{
return *static_cast<rv<T>* >(::boost::move_detail::addressof(x));
return *BOOST_MOVE_TO_RV_CAST(::boost::rv<T>*, ::boost::move_detail::addressof(x) );
}
template <class T>
inline typename ::boost::move_detail::enable_if_c
< enable_move_utility_emulation<T>::value && has_move_emulation_enabled<T>::value, rv<T>&>::type
inline typename ::boost::move_detail::enable_if_and
< rv<T>&
, enable_move_utility_emulation<T>
, has_move_emulation_enabled<T>
>::type
move(rv<T>& x) BOOST_NOEXCEPT
{
return x;
@@ -77,17 +86,23 @@
//////////////////////////////////////////////////////////////////////////////
template <class T>
inline typename ::boost::move_detail::enable_if_c
< enable_move_utility_emulation<T>::value && ::boost::move_detail::is_rv<T>::value, T &>::type
inline typename ::boost::move_detail::enable_if_and
< T &
, enable_move_utility_emulation<T>
, ::boost::move_detail::is_rv<T>
>::type
forward(const typename ::boost::move_detail::identity<T>::type &x) BOOST_NOEXCEPT
{
return const_cast<T&>(x);
}
template <class T>
inline typename ::boost::move_detail::enable_if_c
< enable_move_utility_emulation<T>::value && !::boost::move_detail::is_rv<T>::value, const T &>::type
forward(const typename ::boost::move_detail::identity<T>::type &x) BOOST_NOEXCEPT
inline typename ::boost::move_detail::enable_if_and
< const T &
, enable_move_utility_emulation<T>
, ::boost::move_detail::is_not_rv<T>
>::type
forward(const typename ::boost::move_detail::identity<T>::type &x) BOOST_NOEXCEPT
{
return x;
}
@@ -99,22 +114,25 @@
//////////////////////////////////////////////////////////////////////////////
template <class T>
inline typename ::boost::move_detail::enable_if_c
< enable_move_utility_emulation<T>::value &&
::boost::move_detail::is_rv<T>::value
, T &>::type
inline typename ::boost::move_detail::enable_if_and
< T &
, enable_move_utility_emulation<T>
, ::boost::move_detail::is_rv<T>
>::type
move_if_not_lvalue_reference(const typename ::boost::move_detail::identity<T>::type &x) BOOST_NOEXCEPT
{
return const_cast<T&>(x);
}
template <class T>
inline typename ::boost::move_detail::enable_if_c
< enable_move_utility_emulation<T>::value &&
!::boost::move_detail::is_rv<T>::value &&
(::boost::move_detail::is_lvalue_reference<T>::value ||
!has_move_emulation_enabled<T>::value)
, typename ::boost::move_detail::add_lvalue_reference<T>::type
inline typename ::boost::move_detail::enable_if_and
< typename ::boost::move_detail::add_lvalue_reference<T>::type
, enable_move_utility_emulation<T>
, ::boost::move_detail::is_not_rv<T>
, ::boost::move_detail::or_
< ::boost::move_detail::is_lvalue_reference<T>
, has_move_emulation_disabled<T>
>
>::type
move_if_not_lvalue_reference(typename ::boost::move_detail::remove_reference<T>::type &x) BOOST_NOEXCEPT
{
@@ -122,12 +140,14 @@
}
template <class T>
inline typename ::boost::move_detail::enable_if_c
< enable_move_utility_emulation<T>::value &&
!::boost::move_detail::is_rv<T>::value &&
(!::boost::move_detail::is_lvalue_reference<T>::value &&
has_move_emulation_enabled<T>::value)
, rv<T>&
inline typename ::boost::move_detail::enable_if_and
< rv<T>&
, enable_move_utility_emulation<T>
, ::boost::move_detail::is_not_rv<T>
, ::boost::move_detail::and_
< ::boost::move_detail::not_< ::boost::move_detail::is_lvalue_reference<T> >
, has_move_emulation_enabled<T>
>
>::type
move_if_not_lvalue_reference(typename ::boost::move_detail::remove_reference<T>::type &x) BOOST_NOEXCEPT
{

View File

@@ -49,6 +49,7 @@ void test()
int* j = p.release();
BOOST_TEST(p.get() == 0);
BOOST_TEST(i == j);
p.reset(j);
}
//Unbounded array unique_ptr
{
@@ -57,6 +58,7 @@ void test()
int* j = p.release();
BOOST_TEST(p.get() == 0);
BOOST_TEST(i == j);
p.reset(j);
}
//Bounded array unique_ptr
{
@@ -65,6 +67,7 @@ void test()
int* j = p.release();
BOOST_TEST(p.get() == 0);
BOOST_TEST(i == j);
p.reset(j);
}
}