380 lines
11 KiB
C++
380 lines
11 KiB
C++
// Distributed under the Boost Software License, Version 1.0. (See
|
|
// accompanying file LICENSE_1_0.txt or copy at
|
|
// http://www.boost.org/LICENSE_1_0.txt)
|
|
// (C) Copyright 2007-8 Anthony Williams
|
|
// (C) Copyright 2011-2012 Vicente J. Botet Escriba
|
|
|
|
#ifndef ACTIV_BOOST_THREAD_MOVE_HPP
|
|
#define ACTIV_BOOST_THREAD_MOVE_HPP
|
|
|
|
#include <ActivBoost/thread/detail/config.hpp>
|
|
#ifndef ACTIV_BOOST_NO_SFINAE
|
|
#include <ActivBoost/core/enable_if.hpp>
|
|
#include <ActivBoost/type_traits/is_convertible.hpp>
|
|
#include <ActivBoost/type_traits/remove_reference.hpp>
|
|
#include <ActivBoost/type_traits/remove_cv.hpp>
|
|
#include <ActivBoost/type_traits/decay.hpp>
|
|
#include <ActivBoost/type_traits/conditional.hpp>
|
|
#include <ActivBoost/type_traits/remove_extent.hpp>
|
|
#include <ActivBoost/type_traits/is_array.hpp>
|
|
#include <ActivBoost/type_traits/is_function.hpp>
|
|
#include <ActivBoost/type_traits/add_pointer.hpp>
|
|
#endif
|
|
|
|
#include <ActivBoost/thread/detail/delete.hpp>
|
|
#include <ActivBoost/move/utility.hpp>
|
|
#include <ActivBoost/move/traits.hpp>
|
|
#include <ActivBoost/config/abi_prefix.hpp>
|
|
#ifndef ACTIV_BOOST_NO_CXX11_RVALUE_REFERENCES
|
|
#include <type_traits>
|
|
#endif
|
|
namespace Boost
|
|
{
|
|
|
|
namespace detail
|
|
{
|
|
template <typename T>
|
|
struct enable_move_utility_emulation_dummy_specialization;
|
|
template<typename T>
|
|
struct thread_move_t
|
|
{
|
|
T& t;
|
|
explicit thread_move_t(T& t_):
|
|
t(t_)
|
|
{}
|
|
|
|
T& operator*() const
|
|
{
|
|
return t;
|
|
}
|
|
|
|
T* operator->() const
|
|
{
|
|
return &t;
|
|
}
|
|
private:
|
|
void operator=(thread_move_t&);
|
|
};
|
|
}
|
|
|
|
#if !defined ACTIV_BOOST_THREAD_USES_MOVE
|
|
|
|
#ifndef ACTIV_BOOST_NO_SFINAE
|
|
template<typename T>
|
|
typename enable_if<Boost::is_convertible<T&,Boost::detail::thread_move_t<T> >, Boost::detail::thread_move_t<T> >::type move(T& t)
|
|
{
|
|
return Boost::detail::thread_move_t<T>(t);
|
|
}
|
|
#endif
|
|
|
|
template<typename T>
|
|
Boost::detail::thread_move_t<T> move(Boost::detail::thread_move_t<T> t)
|
|
{
|
|
return t;
|
|
}
|
|
|
|
#endif //#if !defined ACTIV_BOOST_THREAD_USES_MOVE
|
|
}
|
|
|
|
#if ! defined ACTIV_BOOST_NO_CXX11_RVALUE_REFERENCES
|
|
|
|
#define ACTIV_BOOST_THREAD_COPY_ASSIGN_REF(TYPE) ACTIV_BOOST_COPY_ASSIGN_REF(TYPE)
|
|
#define ACTIV_BOOST_THREAD_RV_REF(TYPE) ACTIV_BOOST_RV_REF(TYPE)
|
|
#define ACTIV_BOOST_THREAD_RV_REF_2_TEMPL_ARGS(TYPE) ACTIV_BOOST_RV_REF_2_TEMPL_ARGS(TYPE)
|
|
#define ACTIV_BOOST_THREAD_RV_REF_BEG ACTIV_BOOST_RV_REF_BEG
|
|
#define ACTIV_BOOST_THREAD_RV_REF_END ACTIV_BOOST_RV_REF_END
|
|
#define ACTIV_BOOST_THREAD_RV(V) V
|
|
#define ACTIV_BOOST_THREAD_MAKE_RV_REF(RVALUE) RVALUE
|
|
#define ACTIV_BOOST_THREAD_FWD_REF(TYPE) ACTIV_BOOST_FWD_REF(TYPE)
|
|
#define ACTIV_BOOST_THREAD_DCL_MOVABLE(TYPE)
|
|
#define ACTIV_BOOST_THREAD_DCL_MOVABLE_BEG(T) \
|
|
namespace detail { \
|
|
template <typename T> \
|
|
struct enable_move_utility_emulation_dummy_specialization<
|
|
|
|
#define ACTIV_BOOST_THREAD_DCL_MOVABLE_BEG2(T1, T2) \
|
|
namespace detail { \
|
|
template <typename T1, typename T2> \
|
|
struct enable_move_utility_emulation_dummy_specialization<
|
|
|
|
#define ACTIV_BOOST_THREAD_DCL_MOVABLE_END > \
|
|
: integral_constant<bool, false> \
|
|
{}; \
|
|
}
|
|
|
|
#elif ! defined ACTIV_BOOST_NO_CXX11_RVALUE_REFERENCES && defined ACTIV_BOOST_MSVC
|
|
|
|
#define ACTIV_BOOST_THREAD_COPY_ASSIGN_REF(TYPE) ACTIV_BOOST_COPY_ASSIGN_REF(TYPE)
|
|
#define ACTIV_BOOST_THREAD_RV_REF(TYPE) ACTIV_BOOST_RV_REF(TYPE)
|
|
#define ACTIV_BOOST_THREAD_RV_REF_2_TEMPL_ARGS(TYPE) ACTIV_BOOST_RV_REF_2_TEMPL_ARGS(TYPE)
|
|
#define ACTIV_BOOST_THREAD_RV_REF_BEG ACTIV_BOOST_RV_REF_BEG
|
|
#define ACTIV_BOOST_THREAD_RV_REF_END ACTIV_BOOST_RV_REF_END
|
|
#define ACTIV_BOOST_THREAD_RV(V) V
|
|
#define ACTIV_BOOST_THREAD_MAKE_RV_REF(RVALUE) RVALUE
|
|
#define ACTIV_BOOST_THREAD_FWD_REF(TYPE) ACTIV_BOOST_FWD_REF(TYPE)
|
|
#define ACTIV_BOOST_THREAD_DCL_MOVABLE(TYPE)
|
|
#define ACTIV_BOOST_THREAD_DCL_MOVABLE_BEG(T) \
|
|
namespace detail { \
|
|
template <typename T> \
|
|
struct enable_move_utility_emulation_dummy_specialization<
|
|
|
|
#define ACTIV_BOOST_THREAD_DCL_MOVABLE_BEG2(T1, T2) \
|
|
namespace detail { \
|
|
template <typename T1, typename T2> \
|
|
struct enable_move_utility_emulation_dummy_specialization<
|
|
|
|
#define ACTIV_BOOST_THREAD_DCL_MOVABLE_END > \
|
|
: integral_constant<bool, false> \
|
|
{}; \
|
|
}
|
|
|
|
#else
|
|
|
|
#if defined ACTIV_BOOST_THREAD_USES_MOVE
|
|
#define ACTIV_BOOST_THREAD_COPY_ASSIGN_REF(TYPE) ACTIV_BOOST_COPY_ASSIGN_REF(TYPE)
|
|
#define ACTIV_BOOST_THREAD_RV_REF(TYPE) ACTIV_BOOST_RV_REF(TYPE)
|
|
#define ACTIV_BOOST_THREAD_RV_REF_2_TEMPL_ARGS(TYPE) ACTIV_BOOST_RV_REF_2_TEMPL_ARGS(TYPE)
|
|
#define ACTIV_BOOST_THREAD_RV_REF_BEG ACTIV_BOOST_RV_REF_BEG
|
|
#define ACTIV_BOOST_THREAD_RV_REF_END ACTIV_BOOST_RV_REF_END
|
|
#define ACTIV_BOOST_THREAD_RV(V) V
|
|
#define ACTIV_BOOST_THREAD_FWD_REF(TYPE) ACTIV_BOOST_FWD_REF(TYPE)
|
|
#define ACTIV_BOOST_THREAD_DCL_MOVABLE(TYPE)
|
|
#define ACTIV_BOOST_THREAD_DCL_MOVABLE_BEG(T) \
|
|
namespace detail { \
|
|
template <typename T> \
|
|
struct enable_move_utility_emulation_dummy_specialization<
|
|
|
|
#define ACTIV_BOOST_THREAD_DCL_MOVABLE_BEG2(T1, T2) \
|
|
namespace detail { \
|
|
template <typename T1, typename T2> \
|
|
struct enable_move_utility_emulation_dummy_specialization<
|
|
|
|
#define ACTIV_BOOST_THREAD_DCL_MOVABLE_END > \
|
|
: integral_constant<bool, false> \
|
|
{}; \
|
|
}
|
|
|
|
#else
|
|
|
|
#define ACTIV_BOOST_THREAD_COPY_ASSIGN_REF(TYPE) const TYPE&
|
|
#define ACTIV_BOOST_THREAD_RV_REF(TYPE) Boost::detail::thread_move_t< TYPE >
|
|
#define ACTIV_BOOST_THREAD_RV_REF_BEG Boost::detail::thread_move_t<
|
|
#define ACTIV_BOOST_THREAD_RV_REF_END >
|
|
#define ACTIV_BOOST_THREAD_RV(V) (*V)
|
|
#define ACTIV_BOOST_THREAD_FWD_REF(TYPE) ACTIV_BOOST_FWD_REF(TYPE)
|
|
|
|
#define ACTIV_BOOST_THREAD_DCL_MOVABLE(TYPE) \
|
|
template <> \
|
|
struct enable_move_utility_emulation< TYPE > \
|
|
{ \
|
|
static const bool value = false; \
|
|
};
|
|
|
|
#define ACTIV_BOOST_THREAD_DCL_MOVABLE_BEG(T) \
|
|
template <typename T> \
|
|
struct enable_move_utility_emulation<
|
|
|
|
#define ACTIV_BOOST_THREAD_DCL_MOVABLE_BEG2(T1, T2) \
|
|
template <typename T1, typename T2> \
|
|
struct enable_move_utility_emulation<
|
|
|
|
#define ACTIV_BOOST_THREAD_DCL_MOVABLE_END > \
|
|
{ \
|
|
static const bool value = false; \
|
|
};
|
|
|
|
#endif
|
|
|
|
namespace Boost
|
|
{
|
|
namespace detail
|
|
{
|
|
template <typename T>
|
|
ACTIV_BOOST_THREAD_RV_REF(typename ::Boost::remove_cv<typename ::Boost::remove_reference<T>::type>::type)
|
|
make_rv_ref(T v) ACTIV_BOOST_NOEXCEPT
|
|
{
|
|
return (ACTIV_BOOST_THREAD_RV_REF(typename ::Boost::remove_cv<typename ::Boost::remove_reference<T>::type>::type))(v);
|
|
}
|
|
// template <typename T>
|
|
// ACTIV_BOOST_THREAD_RV_REF(typename ::Boost::remove_cv<typename ::Boost::remove_reference<T>::type>::type)
|
|
// make_rv_ref(T &v) ACTIV_BOOST_NOEXCEPT
|
|
// {
|
|
// return (ACTIV_BOOST_THREAD_RV_REF(typename ::Boost::remove_cv<typename ::Boost::remove_reference<T>::type>::type))(v);
|
|
// }
|
|
// template <typename T>
|
|
// const ACTIV_BOOST_THREAD_RV_REF(typename ::Boost::remove_cv<typename ::Boost::remove_reference<T>::type>::type)
|
|
// make_rv_ref(T const&v) ACTIV_BOOST_NOEXCEPT
|
|
// {
|
|
// return (const ACTIV_BOOST_THREAD_RV_REF(typename ::Boost::remove_cv<typename ::Boost::remove_reference<T>::type>::type))(v);
|
|
// }
|
|
}
|
|
}
|
|
|
|
#define ACTIV_BOOST_THREAD_MAKE_RV_REF(RVALUE) RVALUE.move()
|
|
//#define ACTIV_BOOST_THREAD_MAKE_RV_REF(RVALUE) Boost::detail::make_rv_ref(RVALUE)
|
|
#endif
|
|
|
|
|
|
#if ! defined ACTIV_BOOST_NO_CXX11_RVALUE_REFERENCES
|
|
|
|
#define ACTIV_BOOST_THREAD_MOVABLE(TYPE)
|
|
|
|
#define ACTIV_BOOST_THREAD_COPYABLE(TYPE)
|
|
|
|
#else
|
|
|
|
#if defined ACTIV_BOOST_THREAD_USES_MOVE
|
|
|
|
#define ACTIV_BOOST_THREAD_MOVABLE(TYPE) \
|
|
::Boost::rv<TYPE>& move() ACTIV_BOOST_NOEXCEPT \
|
|
{ \
|
|
return *static_cast< ::Boost::rv<TYPE>* >(this); \
|
|
} \
|
|
const ::Boost::rv<TYPE>& move() const ACTIV_BOOST_NOEXCEPT \
|
|
{ \
|
|
return *static_cast<const ::Boost::rv<TYPE>* >(this); \
|
|
} \
|
|
operator ::Boost::rv<TYPE>&() \
|
|
{ \
|
|
return *static_cast< ::Boost::rv<TYPE>* >(this); \
|
|
} \
|
|
operator const ::Boost::rv<TYPE>&() const \
|
|
{ \
|
|
return *static_cast<const ::Boost::rv<TYPE>* >(this); \
|
|
}\
|
|
|
|
#define ACTIV_BOOST_THREAD_COPYABLE(TYPE) \
|
|
TYPE& operator=(TYPE &t)\
|
|
{ this->operator=(static_cast<const ::Boost::rv<TYPE> &>(const_cast<const TYPE &>(t))); return *this;}
|
|
|
|
|
|
#else
|
|
|
|
#define ACTIV_BOOST_THREAD_MOVABLE(TYPE) \
|
|
operator ::Boost::detail::thread_move_t<TYPE>() ACTIV_BOOST_NOEXCEPT \
|
|
{ \
|
|
return move(); \
|
|
} \
|
|
::Boost::detail::thread_move_t<TYPE> move() ACTIV_BOOST_NOEXCEPT \
|
|
{ \
|
|
::Boost::detail::thread_move_t<TYPE> x(*this); \
|
|
return x; \
|
|
} \
|
|
|
|
#define ACTIV_BOOST_THREAD_COPYABLE(TYPE)
|
|
|
|
#endif
|
|
#endif
|
|
|
|
#define ACTIV_BOOST_THREAD_MOVABLE_ONLY(TYPE) \
|
|
ACTIV_BOOST_THREAD_NO_COPYABLE(TYPE) \
|
|
ACTIV_BOOST_THREAD_MOVABLE(TYPE) \
|
|
typedef int boost_move_no_copy_constructor_or_assign; \
|
|
|
|
|
|
#define ACTIV_BOOST_THREAD_COPYABLE_AND_MOVABLE(TYPE) \
|
|
ACTIV_BOOST_THREAD_COPYABLE(TYPE) \
|
|
ACTIV_BOOST_THREAD_MOVABLE(TYPE) \
|
|
|
|
|
|
|
|
namespace Boost
|
|
{
|
|
namespace thread_detail
|
|
{
|
|
|
|
#if ! defined ACTIV_BOOST_NO_CXX11_RVALUE_REFERENCES
|
|
#elif defined ACTIV_BOOST_THREAD_USES_MOVE
|
|
template <class T>
|
|
struct is_rv
|
|
: ::Boost::move_detail::is_rv<T>
|
|
{};
|
|
|
|
#else
|
|
template <class T>
|
|
struct is_rv
|
|
: ::Boost::integral_constant<bool, false>
|
|
{};
|
|
|
|
template <class T>
|
|
struct is_rv< ::Boost::detail::thread_move_t<T> >
|
|
: ::Boost::integral_constant<bool, true>
|
|
{};
|
|
|
|
template <class T>
|
|
struct is_rv< const ::Boost::detail::thread_move_t<T> >
|
|
: ::Boost::integral_constant<bool, true>
|
|
{};
|
|
#endif
|
|
|
|
#ifndef ACTIV_BOOST_NO_CXX11_RVALUE_REFERENCES
|
|
template <class Tp>
|
|
struct remove_reference : Boost::remove_reference<Tp> {};
|
|
template <class Tp>
|
|
struct decay : Boost::decay<Tp> {};
|
|
#else
|
|
template <class Tp>
|
|
struct remove_reference
|
|
{
|
|
typedef Tp type;
|
|
};
|
|
template <class Tp>
|
|
struct remove_reference<Tp&>
|
|
{
|
|
typedef Tp type;
|
|
};
|
|
template <class Tp>
|
|
struct remove_reference< rv<Tp> > {
|
|
typedef Tp type;
|
|
};
|
|
|
|
template <class Tp>
|
|
struct decay
|
|
{
|
|
private:
|
|
typedef typename Boost::move_detail::remove_rvalue_reference<Tp>::type Up0;
|
|
typedef typename Boost::remove_reference<Up0>::type Up;
|
|
public:
|
|
typedef typename conditional
|
|
<
|
|
is_array<Up>::value,
|
|
typename remove_extent<Up>::type*,
|
|
typename conditional
|
|
<
|
|
is_function<Up>::value,
|
|
typename add_pointer<Up>::type,
|
|
typename remove_cv<Up>::type
|
|
>::type
|
|
>::type type;
|
|
};
|
|
#endif
|
|
|
|
#ifndef ACTIV_BOOST_NO_CXX11_RVALUE_REFERENCES
|
|
template <class T>
|
|
typename decay<T>::type
|
|
decay_copy(T&& t)
|
|
{
|
|
return Boost::forward<T>(t);
|
|
}
|
|
typedef void (*void_fct_ptr)();
|
|
|
|
// inline void_fct_ptr
|
|
// decay_copy(void (&t)())
|
|
// {
|
|
// return &t;
|
|
// }
|
|
#else
|
|
template <class T>
|
|
typename decay<T>::type
|
|
decay_copy(ACTIV_BOOST_THREAD_FWD_REF(T) t)
|
|
{
|
|
return Boost::forward<T>(t);
|
|
}
|
|
#endif
|
|
}
|
|
}
|
|
|
|
#include <ActivBoost/config/abi_suffix.hpp>
|
|
|
|
#endif
|