Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-06 08:05:21

0001 //////////////////////////////////////////////////////////////////////////////
0002 //
0003 // (C) Copyright Ion Gaztanaga 2012-2012.
0004 // Distributed under the Boost Software License, Version 1.0.
0005 // (See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt)
0007 //
0008 // See http://www.boost.org/libs/move for documentation.
0009 //
0010 //////////////////////////////////////////////////////////////////////////////
0011 
0012 //! \file
0013 //! This header implements macros to define movable classes and
0014 //! move-aware functions
0015 
0016 #ifndef BOOST_MOVE_CORE_HPP
0017 #define BOOST_MOVE_CORE_HPP
0018 
0019 #ifndef BOOST_CONFIG_HPP
0020 #  include <boost/config.hpp>
0021 #endif
0022 0023 ">#
0024 #if defined(BOOST_HAS_PRAGMA_ONCE)
0025 #  pragma once
0026 #endif
0027 
0028 #include <boost/move/detail/config_begin.hpp>
0029 #include <boost/move/detail/workaround.hpp>
0030 
0031 // @cond
0032 
0033 //boost_move_no_copy_constructor_or_assign typedef
0034 //used to detect noncopyable types for other Boost libraries.
0035 #if defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0036    #define BOOST_MOVE_IMPL_NO_COPY_CTOR_OR_ASSIGN(TYPE) \
0037       private:\
0038       TYPE(TYPE &);\
0039       TYPE& operator=(TYPE &);\
0040       public:\
0041       typedef int boost_move_no_copy_constructor_or_assign; \
0042       private:\
0043    //
0044 #else
0045    #define BOOST_MOVE_IMPL_NO_COPY_CTOR_OR_ASSIGN(TYPE) \
0046       public:\
0047       TYPE(TYPE const &) = delete;\
0048       TYPE& operator=(TYPE const &) = delete;\
0049       public:\
0050       typedef int boost_move_no_copy_constructor_or_assign; \
0051       private:\
0052    //
0053 #endif   //BOOST_NO_CXX11_DELETED_FUNCTIONS
0054 
0055 // @endcond
0056 
0057 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_MOVE_DOXYGEN_INVOKED)
0058 
0059    #include <boost/move/detail/type_traits.hpp>
0060 
0061    #define BOOST_MOVE_TO_RV_CAST(RV_TYPE, ARG) reinterpret_cast<RV_TYPE>(ARG)
0062    #define BOOST_MOVE_TO_LV_CAST(LV_TYPE, ARG) static_cast<LV_TYPE>(ARG)
0063 
0064    //Move emulation rv breaks standard aliasing rules so add workarounds for some compilers
0065    #if defined(BOOST_GCC) && (BOOST_GCC >= 40400) && (BOOST_GCC < 40500)
0066    #define BOOST_RV_ATTRIBUTE_MAY_ALIAS BOOST_MAY_ALIAS
0067    #else
0068    #define BOOST_RV_ATTRIBUTE_MAY_ALIAS 
0069    #endif
0070 
0071    namespace boost {
0072 
0073    //////////////////////////////////////////////////////////////////////////////
0074    //
0075    //                            struct rv
0076    //
0077    //////////////////////////////////////////////////////////////////////////////
0078    template <class T>
0079    class BOOST_RV_ATTRIBUTE_MAY_ALIAS rv
0080       : public ::boost::move_detail::if_c
0081          < ::boost::move_detail::is_class<T>::value
0082          , T
0083          , ::boost::move_detail::nat
0084          >::type
0085    {
0086       rv();
0087       ~rv() throw();
0088       rv(rv const&);
0089       void operator=(rv const&);
0090    };
0091 
0092 
0093    //////////////////////////////////////////////////////////////////////////////
0094    //
0095    //                            is_rv
0096    //
0097    //////////////////////////////////////////////////////////////////////////////
0098 
0099    namespace move_detail {
0100 
0101    template <class T>
0102    struct is_rv
0103         //Derive from integral constant because some Boost code assummes it has
0104         //a "type" internal typedef
0105       : integral_constant<bool, ::boost::move_detail::is_rv_impl<T>::value >
0106    {};
0107 
0108    template <class T>
0109    struct is_not_rv
0110    {
0111       static const bool value = !is_rv<T>::value;
0112    };
0113 
0114    }  //namespace move_detail {
0115 
0116    //////////////////////////////////////////////////////////////////////////////
0117    //
0118    //                               has_move_emulation_enabled
0119    //
0120    //////////////////////////////////////////////////////////////////////////////
0121    template<class T>
0122    struct has_move_emulation_enabled
0123       : ::boost::move_detail::has_move_emulation_enabled_impl<T>
0124    {};
0125 
0126    template<class T>
0127    struct has_move_emulation_disabled
0128    {
0129       static const bool value = !::boost::move_detail::has_move_emulation_enabled_impl<T>::value;
0130    };
0131 
0132    }  //namespace boost {
0133 
0134    #define BOOST_RV_REF(TYPE)\
0135       ::boost::rv< TYPE >& \
0136    //
0137 
0138    #define BOOST_RV_REF_2_TEMPL_ARGS(TYPE, ARG1, ARG2)\
0139       ::boost::rv< TYPE<ARG1, ARG2> >& \
0140    //
0141 
0142    #define BOOST_RV_REF_3_TEMPL_ARGS(TYPE, ARG1, ARG2, ARG3)\
0143       ::boost::rv< TYPE<ARG1, ARG2, ARG3> >& \
0144    //
0145 
0146    #define BOOST_RV_REF_BEG\
0147       ::boost::rv<   \
0148    //
0149 
0150    #define BOOST_RV_REF_END\
0151       >& \
0152    //
0153 
0154    #define BOOST_RV_REF_BEG_IF_CXX11 \
0155       \
0156    //
0157 
0158    #define BOOST_RV_REF_END_IF_CXX11 \
0159       \
0160    //
0161 
0162    #define BOOST_FWD_REF(TYPE)\
0163       const TYPE & \
0164    //
0165 
0166    #define BOOST_COPY_ASSIGN_REF(TYPE)\
0167       const ::boost::rv< TYPE >& \
0168    //
0169 
0170    #define BOOST_COPY_ASSIGN_REF_BEG \
0171       const ::boost::rv<  \
0172    //
0173 
0174    #define BOOST_COPY_ASSIGN_REF_END \
0175       >& \
0176    //
0177 
0178    #define BOOST_COPY_ASSIGN_REF_2_TEMPL_ARGS(TYPE, ARG1, ARG2)\
0179       const ::boost::rv< TYPE<ARG1, ARG2> >& \
0180    //
0181 
0182    #define BOOST_COPY_ASSIGN_REF_3_TEMPL_ARGS(TYPE, ARG1, ARG2, ARG3)\
0183       const ::boost::rv< TYPE<ARG1, ARG2, ARG3> >& \
0184    //
0185 
0186    #define BOOST_CATCH_CONST_RLVALUE(TYPE)\
0187       const ::boost::rv< TYPE >& \
0188    //
0189 
0190    namespace boost {
0191    namespace move_detail {
0192 
0193    template <class Ret, class T>
0194    BOOST_MOVE_FORCEINLINE typename ::boost::move_detail::enable_if_c
0195       <  ::boost::move_detail::is_lvalue_reference<Ret>::value ||
0196         !::boost::has_move_emulation_enabled<T>::value
0197       , T&>::type
0198          move_return(T& x) BOOST_NOEXCEPT
0199    {
0200       return x;
0201    }
0202 
0203    template <class Ret, class T>
0204    BOOST_MOVE_FORCEINLINE typename ::boost::move_detail::enable_if_c
0205       < !::boost::move_detail::is_lvalue_reference<Ret>::value &&
0206          ::boost::has_move_emulation_enabled<T>::value
0207       , ::boost::rv<T>&>::type
0208          move_return(T& x) BOOST_NOEXCEPT
0209    {
0210       return *BOOST_MOVE_TO_RV_CAST(::boost::rv<T>*, ::boost::move_detail::addressof(x));
0211    }
0212 
0213    template <class Ret, class T>
0214    BOOST_MOVE_FORCEINLINE typename ::boost::move_detail::enable_if_c
0215       < !::boost::move_detail::is_lvalue_reference<Ret>::value &&
0216          ::boost::has_move_emulation_enabled<T>::value
0217       , ::boost::rv<T>&>::type
0218          move_return(::boost::rv<T>& x) BOOST_NOEXCEPT
0219    {
0220       return x;
0221    }
0222 
0223    template <class T>
0224    BOOST_MOVE_FORCEINLINE T& unrv(::boost::rv<T> &rv) BOOST_NOEXCEPT
0225    {  return BOOST_MOVE_TO_LV_CAST(T&, rv);   }
0226 
0227    }  //namespace move_detail {
0228    }  //namespace boost {
0229 
0230    #define BOOST_MOVE_RET(RET_TYPE, REF)\
0231       boost::move_detail::move_return< RET_TYPE >(REF)
0232    //
0233 
0234    #define BOOST_MOVE_BASE(BASE_TYPE, ARG) \
0235       ::boost::move((BASE_TYPE&)(ARG))
0236    //
0237 
0238    #define BOOST_MOVE_TO_LV(ARG) \
0239       ::boost::move_detail::unrv(ARG)
0240    //
0241 
0242 
0243    //////////////////////////////////////////////////////////////////////////////
0244    //
0245    //                         BOOST_MOVABLE_BUT_NOT_COPYABLE
0246    //
0247    //////////////////////////////////////////////////////////////////////////////
0248    #define BOOST_MOVABLE_BUT_NOT_COPYABLE(TYPE)\
0249       BOOST_MOVE_IMPL_NO_COPY_CTOR_OR_ASSIGN(TYPE)\
0250       public:\
0251       BOOST_MOVE_FORCEINLINE operator ::boost::rv<TYPE>&() \
0252       {  return *BOOST_MOVE_TO_RV_CAST(::boost::rv<TYPE>*, this);  }\
0253       BOOST_MOVE_FORCEINLINE operator const ::boost::rv<TYPE>&() const \
0254       {  return *BOOST_MOVE_TO_RV_CAST(const ::boost::rv<TYPE>*, this);  }\
0255       private:\
0256    //
0257 
0258    //////////////////////////////////////////////////////////////////////////////
0259    //
0260    //                         BOOST_COPYABLE_AND_MOVABLE
0261    //
0262    //////////////////////////////////////////////////////////////////////////////
0263 
0264    #define BOOST_COPYABLE_AND_MOVABLE(TYPE)\
0265       public:\
0266       BOOST_MOVE_FORCEINLINE TYPE& operator=(TYPE &t)\
0267       {  this->operator=(const_cast<const TYPE&>(t)); return *this;}\
0268       public:\
0269       BOOST_MOVE_FORCEINLINE operator ::boost::rv<TYPE>&() \
0270       {  return *BOOST_MOVE_TO_RV_CAST(::boost::rv<TYPE>*, this);  }\
0271       BOOST_MOVE_FORCEINLINE operator const ::boost::rv<TYPE>&() const \
0272       {  return *BOOST_MOVE_TO_RV_CAST(const ::boost::rv<TYPE>*, this);  }\
0273       private:\
0274    //
0275 
0276    #define BOOST_COPYABLE_AND_MOVABLE_ALT(TYPE)\
0277       public:\
0278       BOOST_MOVE_FORCEINLINE operator ::boost::rv<TYPE>&() \
0279       {  return *BOOST_MOVE_TO_RV_CAST(::boost::rv<TYPE>*, this);  }\
0280       BOOST_MOVE_FORCEINLINE operator const ::boost::rv<TYPE>&() const \
0281       {  return *BOOST_MOVE_TO_RV_CAST(const ::boost::rv<TYPE>*, this);  }\
0282       private:\
0283    //
0284 
0285    namespace boost{
0286    namespace move_detail{
0287 
0288    template< class T>
0289    struct forward_type
0290    { typedef const T &type; };
0291 
0292    template< class T>
0293    struct forward_type< boost::rv<T> >
0294    { typedef T type; };
0295 
0296    }}
0297 
0298 #else    //BOOST_NO_CXX11_RVALUE_REFERENCES
0299 
0300    //! This macro marks a type as movable but not copyable, disabling copy construction
0301    //! and assignment. The user will need to write a move constructor/assignment as explained
0302    //! in the documentation to fully write a movable but not copyable class.
0303    #define BOOST_MOVABLE_BUT_NOT_COPYABLE(TYPE)\
0304       BOOST_MOVE_IMPL_NO_COPY_CTOR_OR_ASSIGN(TYPE)\
0305       public:\
0306       typedef int boost_move_emulation_t;\
0307       private:\
0308    //
0309 
0310    //! This macro marks a type as copyable and movable.
0311    //! The user will need to write a move constructor/assignment and a copy assignment
0312    //! as explained in the documentation to fully write a copyable and movable class.
0313    #define BOOST_COPYABLE_AND_MOVABLE(TYPE)\
0314    //
0315 
0316    #if !defined(BOOST_MOVE_DOXYGEN_INVOKED)
0317    #define BOOST_COPYABLE_AND_MOVABLE_ALT(TYPE)\
0318    //
0319    #endif   //#if !defined(BOOST_MOVE_DOXYGEN_INVOKED)
0320 
0321    namespace boost {
0322 
0323    //!This trait yields to a compile-time true boolean if T was marked as
0324    //!BOOST_MOVABLE_BUT_NOT_COPYABLE or BOOST_COPYABLE_AND_MOVABLE and
0325    //!rvalue references are not available on the platform. False otherwise.
0326    template<class T>
0327    struct has_move_emulation_enabled
0328    {
0329       static const bool value = false;
0330    };
0331 
0332    template<class T>
0333    struct has_move_emulation_disabled
0334    {
0335       static const bool value = true;
0336    };
0337 
0338    }  //namespace boost{
0339 
0340    //!This macro is used to achieve portable syntax in move
0341    //!constructors and assignments for classes marked as
0342    //!BOOST_COPYABLE_AND_MOVABLE or BOOST_MOVABLE_BUT_NOT_COPYABLE
0343    #define BOOST_RV_REF(TYPE)\
0344       TYPE && \
0345    //
0346 
0347    //!This macro is used to achieve portable syntax in move
0348    //!constructors and assignments for template classes marked as
0349    //!BOOST_COPYABLE_AND_MOVABLE or BOOST_MOVABLE_BUT_NOT_COPYABLE.
0350    //!As macros have problems with comma-separated template arguments,
0351    //!the template argument must be preceded with BOOST_RV_REF_BEG
0352    //!and ended with BOOST_RV_REF_END
0353    #define BOOST_RV_REF_BEG\
0354          \
0355    //
0356 
0357    //!This macro is used to achieve portable syntax in move
0358    //!constructors and assignments for template classes marked as
0359    //!BOOST_COPYABLE_AND_MOVABLE or BOOST_MOVABLE_BUT_NOT_COPYABLE.
0360    //!As macros have problems with comma-separated template arguments,
0361    //!the template argument must be preceded with BOOST_RV_REF_BEG
0362    //!and ended with BOOST_RV_REF_END
0363    #define BOOST_RV_REF_END\
0364       && \
0365    //
0366 
0367    //!This macro expands to BOOST_RV_REF_BEG if BOOST_NO_CXX11_RVALUE_REFERENCES
0368    //!is not defined, empty otherwise
0369    #define BOOST_RV_REF_BEG_IF_CXX11 \
0370       BOOST_RV_REF_BEG \
0371    //
0372 
0373    //!This macro expands to BOOST_RV_REF_END if BOOST_NO_CXX11_RVALUE_REFERENCES
0374    //!is not defined, empty otherwise
0375    #define BOOST_RV_REF_END_IF_CXX11 \
0376       BOOST_RV_REF_END \
0377    //
0378 
0379    //!This macro is used to achieve portable syntax in copy
0380    //!assignment for classes marked as BOOST_COPYABLE_AND_MOVABLE.
0381    #define BOOST_COPY_ASSIGN_REF(TYPE)\
0382       const TYPE & \
0383    //
0384 
0385    //! This macro is used to implement portable perfect forwarding
0386    //! as explained in the documentation.
0387    #define BOOST_FWD_REF(TYPE)\
0388       TYPE && \
0389    //
0390 
0391    #if !defined(BOOST_MOVE_DOXYGEN_INVOKED)
0392 
0393    #define BOOST_RV_REF_2_TEMPL_ARGS(TYPE, ARG1, ARG2)\
0394       TYPE<ARG1, ARG2> && \
0395    //
0396 
0397    #define BOOST_RV_REF_3_TEMPL_ARGS(TYPE, ARG1, ARG2, ARG3)\
0398       TYPE<ARG1, ARG2, ARG3> && \
0399    //
0400 
0401    #define BOOST_COPY_ASSIGN_REF_BEG \
0402       const \
0403    //
0404 
0405    #define BOOST_COPY_ASSIGN_REF_END \
0406       & \
0407    //
0408 
0409    #define BOOST_COPY_ASSIGN_REF_2_TEMPL_ARGS(TYPE, ARG1, ARG2)\
0410       const TYPE<ARG1, ARG2> & \
0411    //
0412 
0413    #define BOOST_COPY_ASSIGN_REF_3_TEMPL_ARGS(TYPE, ARG1, ARG2, ARG3)\
0414       const TYPE<ARG1, ARG2, ARG3>& \
0415    //
0416 
0417    #define BOOST_CATCH_CONST_RLVALUE(TYPE)\
0418       const TYPE & \
0419    //
0420 
0421    #endif   //#if !defined(BOOST_MOVE_DOXYGEN_INVOKED)
0422 
0423    #if !defined(BOOST_MOVE_MSVC_AUTO_MOVE_RETURN_BUG) || defined(BOOST_MOVE_DOXYGEN_INVOKED)
0424 
0425       //!This macro is used to achieve portable move return semantics.
0426       //!The C++11 Standard allows implicit move returns when the object to be returned
0427       //!is designated by a lvalue and:
0428       //!   - The criteria for elision of a copy operation are met OR
0429       //!   - The criteria would be met save for the fact that the source object is a function parameter
0430       //!
0431       //!For C++11 conforming compilers this macros only yields to REF:
0432       //! <code>return BOOST_MOVE_RET(RET_TYPE, REF);</code> -> <code>return REF;</code>
0433       //!
0434       //!For compilers without rvalue references
0435       //!this macro does an explicit move if the move emulation is activated
0436       //!and the return type (RET_TYPE) is not a reference.
0437       //!
0438       //!For non-conforming compilers with rvalue references like Visual 2010 & 2012,
0439       //!an explicit move is performed if RET_TYPE is not a reference.
0440       //!
0441       //! <b>Caution</b>: When using this macro in non-conforming or C++03
0442       //!compilers, a move will be performed even if the C++11 standard does not allow it
0443       //!(e.g. returning a static variable). The user is responsible for using this macro
0444       //!only to return local objects that met C++11 criteria.
0445       #define BOOST_MOVE_RET(RET_TYPE, REF)\
0446          REF
0447       //
0448 
0449    #else //!defined(BOOST_MOVE_MSVC_AUTO_MOVE_RETURN_BUG) || defined(BOOST_MOVE_DOXYGEN_INVOKED)
0450 
0451       #include <boost/move/detail/meta_utils_core.hpp>
0452 
0453       namespace boost {
0454       namespace move_detail {
0455 
0456       template <class Ret, class T>
0457       BOOST_MOVE_FORCEINLINE typename ::boost::move_detail::enable_if_c
0458          <  ::boost::move_detail::is_lvalue_reference<Ret>::value
0459          , T&>::type
0460             move_return(T& x) BOOST_NOEXCEPT
0461       {
0462          return x;
0463       }
0464 
0465       template <class Ret, class T>
0466       BOOST_MOVE_FORCEINLINE typename ::boost::move_detail::enable_if_c
0467          < !::boost::move_detail::is_lvalue_reference<Ret>::value
0468          , Ret && >::type
0469             move_return(T&& t) BOOST_NOEXCEPT
0470       {
0471          return static_cast< Ret&& >(t);
0472       }
0473 
0474       }  //namespace move_detail {
0475       }  //namespace boost {
0476 
0477       #define BOOST_MOVE_RET(RET_TYPE, REF)\
0478          boost::move_detail::move_return< RET_TYPE >(REF)
0479       //
0480 
0481    #endif   //!defined(BOOST_MOVE_MSVC_AUTO_MOVE_RETURN_BUG) || defined(BOOST_MOVE_DOXYGEN_INVOKED)
0482 
0483    //!This macro is used to achieve portable optimal move constructors.
0484    //!
0485    //!When implementing the move constructor, in C++03 compilers the moved-from argument must be
0486    //!cast to the base type before calling `::boost::move()` due to rvalue reference limitations.
0487    //!
0488    //!In C++11 compilers the cast from a rvalue reference of a derived type to a rvalue reference of
0489    //!a base type is implicit.
0490    #define BOOST_MOVE_BASE(BASE_TYPE, ARG) \
0491       ::boost::move((BASE_TYPE&)(ARG))
0492    //
0493 
0494    //!This macro is used to achieve portable optimal move constructors.
0495    //!
0496    //!In C++03 mode, when accessing a member of type through a rvalue (implemented as a `rv<T> &` type, where rv<T> derives
0497    //!from T) triggers a potential UB as the program never creates objects of type rv<T>. This macro casts back `rv<T>` to
0498    //!`T&` so that access to member types are done through the original type.
0499    //! 
0500    //!In C++11 compilers the cast from a rvalue reference of a derived type to a rvalue reference of
0501    //!a base type is implicit, so it's a no-op.
0502    #define BOOST_MOVE_TO_LV(ARG) ARG
0503    //
0504 
0505    namespace boost {
0506    namespace move_detail {
0507 
0508    template< class T> struct forward_type { typedef T type; };
0509 
0510    }}
0511 
0512 #endif   //BOOST_NO_CXX11_RVALUE_REFERENCES
0513 
0514 #include <boost/move/detail/config_end.hpp>
0515 
0516 #endif //#ifndef BOOST_MOVE_CORE_HPP