Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 09:56:20

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 defines core utilities to ease the development
0014 //! of move-aware functions. This header minimizes dependencies
0015 //! from other libraries.
0016 
0017 #ifndef BOOST_MOVE_MOVE_UTILITY_CORE_HPP
0018 #define BOOST_MOVE_MOVE_UTILITY_CORE_HPP
0019 
0020 #ifndef BOOST_CONFIG_HPP
0021 #  include <boost/config.hpp>
0022 #endif
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>  //forceinline
0030 #include <boost/move/core.hpp>
0031 #include <boost/move/detail/meta_utils.hpp>
0032 
0033 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_MOVE_DOXYGEN_INVOKED)
0034 
0035    namespace boost {
0036 
0037    template<class T>
0038    struct enable_move_utility_emulation
0039    {
0040       static const bool value = true;
0041    };
0042     
0043    //////////////////////////////////////////////////////////////////////////////
0044    //
0045    //                            move()
0046    //
0047    //////////////////////////////////////////////////////////////////////////////
0048 
0049    template <class T>
0050    BOOST_MOVE_FORCEINLINE typename ::boost::move_detail::enable_if_and
0051       < T &
0052       , enable_move_utility_emulation<T>
0053       , has_move_emulation_disabled<T>
0054       >::type
0055          move(T& x) BOOST_NOEXCEPT
0056    {
0057       return x;
0058    }
0059 
0060    template <class T>
0061    BOOST_MOVE_FORCEINLINE typename ::boost::move_detail::enable_if_and
0062       < rv<T>&
0063       , enable_move_utility_emulation<T>
0064       , has_move_emulation_enabled<T>
0065       >::type
0066          move(T& x) BOOST_NOEXCEPT
0067    {
0068       return *BOOST_MOVE_TO_RV_CAST(::boost::rv<T>*, ::boost::move_detail::addressof(x) );
0069    }
0070 
0071    template <class T>
0072    BOOST_MOVE_FORCEINLINE typename ::boost::move_detail::enable_if_and
0073       < rv<T>&
0074       , enable_move_utility_emulation<T>
0075       , has_move_emulation_enabled<T>
0076       >::type
0077          move(rv<T>& x) BOOST_NOEXCEPT
0078    {
0079       return x;
0080    }
0081 
0082    //////////////////////////////////////////////////////////////////////////////
0083    //
0084    //                            forward()
0085    //
0086    //////////////////////////////////////////////////////////////////////////////
0087 
0088    template <class T>
0089    BOOST_MOVE_FORCEINLINE typename ::boost::move_detail::enable_if_and
0090       < T &
0091       , enable_move_utility_emulation<T>
0092       , ::boost::move_detail::is_rv<T>
0093       >::type
0094          forward(const typename ::boost::move_detail::identity<T>::type &x) BOOST_NOEXCEPT
0095    {
0096       return const_cast<T&>(x);
0097    }
0098 
0099    template <class T>
0100    BOOST_MOVE_FORCEINLINE typename ::boost::move_detail::enable_if_and
0101       < const T &
0102       , enable_move_utility_emulation<T>
0103       , ::boost::move_detail::is_not_rv<T>
0104       >::type
0105          forward(const typename ::boost::move_detail::identity<T>::type &x) BOOST_NOEXCEPT
0106    {
0107       return x;
0108    }
0109 
0110    //////////////////////////////////////////////////////////////////////////////
0111    //
0112    //                        move_if_not_lvalue_reference()
0113    //
0114    //////////////////////////////////////////////////////////////////////////////
0115 
0116    template <class T>
0117    BOOST_MOVE_FORCEINLINE typename ::boost::move_detail::enable_if_and
0118       < T &
0119       , enable_move_utility_emulation<T>
0120       , ::boost::move_detail::is_rv<T>
0121       >::type
0122          move_if_not_lvalue_reference(const typename ::boost::move_detail::identity<T>::type &x) BOOST_NOEXCEPT
0123    {
0124       return const_cast<T&>(x);
0125    }
0126 
0127    template <class T>
0128    BOOST_MOVE_FORCEINLINE typename ::boost::move_detail::enable_if_and
0129       < typename ::boost::move_detail::add_lvalue_reference<T>::type
0130       , enable_move_utility_emulation<T>
0131       , ::boost::move_detail::is_not_rv<T>
0132       , ::boost::move_detail::or_
0133          < ::boost::move_detail::is_lvalue_reference<T>
0134          , has_move_emulation_disabled<T>
0135          >
0136       >::type
0137          move_if_not_lvalue_reference(typename ::boost::move_detail::remove_reference<T>::type &x) BOOST_NOEXCEPT
0138    {
0139       return x;
0140    }
0141 
0142    template <class T>
0143    BOOST_MOVE_FORCEINLINE typename ::boost::move_detail::enable_if_and
0144       < rv<T>&
0145       , enable_move_utility_emulation<T>
0146       , ::boost::move_detail::is_not_rv<T>
0147       , ::boost::move_detail::and_
0148          < ::boost::move_detail::not_< ::boost::move_detail::is_lvalue_reference<T> >
0149          , has_move_emulation_enabled<T>
0150          >
0151       >::type
0152          move_if_not_lvalue_reference(typename ::boost::move_detail::remove_reference<T>::type &x) BOOST_NOEXCEPT
0153    {
0154       return move(x);
0155    }
0156 
0157    }  //namespace boost
0158 
0159 #else    //#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_MOVE_DOXYGEN_INVOKED)
0160 
0161    #if defined(BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE)
0162       #include <utility>
0163 
0164       namespace boost{
0165 
0166       using ::std::move;
0167       using ::std::forward;
0168 
0169       }  //namespace boost
0170 
0171    #else //!BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE
0172 
0173       namespace boost {
0174 
0175       //! This trait's internal boolean `value` is false in compilers with rvalue references
0176       //! and true in compilers without rvalue references.
0177       //!
0178       //! A user can specialize this trait for a type T to false to SFINAE out `move` and `forward`
0179       //! so that the user can define a different move emulation for that type in namespace boost
0180       //! (e.g. another Boost library for its types) and avoid any overload ambiguity.
0181       template<class T>
0182       struct enable_move_utility_emulation
0183       {
0184          static const bool value = false;
0185       };
0186 
0187       //////////////////////////////////////////////////////////////////////////////
0188       //
0189       //                                  move
0190       //
0191       //////////////////////////////////////////////////////////////////////////////
0192 
0193       #if defined(BOOST_MOVE_DOXYGEN_INVOKED)
0194          //! This function provides a way to convert a reference into a rvalue reference
0195          //! in compilers with rvalue references. For other compilers if `T` is Boost.Move
0196          //! enabled type then it converts `T&` into <tt>::boost::rv<T> &</tt> so that
0197          //! move emulation is activated, else it returns `T &`.
0198          template <class T>
0199          rvalue_reference move(input_reference) noexcept;
0200 
0201       #elif defined(BOOST_MOVE_OLD_RVALUE_REF_BINDING_RULES)
0202 
0203          //Old move approach, lvalues could bind to rvalue references
0204          template <class T>
0205          BOOST_MOVE_FORCEINLINE typename ::boost::move_detail::remove_reference<T>::type && move(T&& t) BOOST_NOEXCEPT
0206          {  return t;   }
0207 
0208       #else //BOOST_MOVE_OLD_RVALUE_REF_BINDING_RULES
0209 
0210          template <class T>
0211          BOOST_MOVE_INTRINSIC_CAST
0212          typename ::boost::move_detail::remove_reference<T>::type && move(T&& t) BOOST_NOEXCEPT
0213          { return static_cast<typename ::boost::move_detail::remove_reference<T>::type &&>(t); }
0214 
0215       #endif   //BOOST_MOVE_OLD_RVALUE_REF_BINDING_RULES
0216 
0217       //////////////////////////////////////////////////////////////////////////////
0218       //
0219       //                                  forward
0220       //
0221       //////////////////////////////////////////////////////////////////////////////
0222 
0223 
0224       #if defined(BOOST_MOVE_DOXYGEN_INVOKED)
0225          //! This function provides limited form of forwarding that is usually enough for
0226          //! in-place construction and avoids the exponential overloading for
0227          //! achieve the limited forwarding in C++03.
0228          //!
0229          //! For compilers with rvalue references this function provides perfect forwarding.
0230          //!
0231          //! Otherwise:
0232          //! * If input_reference binds to const ::boost::rv<T> & then it output_reference is
0233          //!   ::boost::rv<T> &
0234          //!
0235          //! * Else, output_reference is equal to input_reference.
0236          template <class T> output_reference forward(input_reference) noexcept;
0237       #elif defined(BOOST_MOVE_OLD_RVALUE_REF_BINDING_RULES)
0238 
0239          //Old move approach, lvalues could bind to rvalue references
0240 
0241          template <class T>
0242          BOOST_MOVE_FORCEINLINE T&& forward(typename ::boost::move_detail::identity<T>::type&& t) BOOST_NOEXCEPT
0243          {  return t;   }
0244 
0245       #else //Old move
0246 
0247          template <class T>
0248          BOOST_MOVE_INTRINSIC_CAST
0249          T&& forward(typename ::boost::move_detail::remove_reference<T>::type& t) BOOST_NOEXCEPT
0250          {  return static_cast<T&&>(t);   }
0251 
0252          template <class T>
0253          BOOST_MOVE_INTRINSIC_CAST
0254          T&& forward(typename ::boost::move_detail::remove_reference<T>::type&& t) BOOST_NOEXCEPT
0255          {
0256             //"boost::forward<T> error: 'T' is a lvalue reference, can't forward as rvalue.";
0257             BOOST_MOVE_STATIC_ASSERT(!boost::move_detail::is_lvalue_reference<T>::value);
0258             return static_cast<T&&>(t);
0259          }
0260 
0261       #endif   //BOOST_MOVE_DOXYGEN_INVOKED
0262 
0263       }  //namespace boost {
0264 
0265    #endif   //BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE
0266 
0267    //////////////////////////////////////////////////////////////////////////////
0268    //
0269    //                         move_if_not_lvalue_reference
0270    //
0271    //////////////////////////////////////////////////////////////////////////////
0272 
0273    namespace boost {
0274 
0275    #if defined(BOOST_MOVE_DOXYGEN_INVOKED)
0276       //! <b>Effects</b>: Calls `boost::move` if `input_reference` is not a lvalue reference.
0277       //!   Otherwise returns the reference
0278       template <class T> output_reference move_if_not_lvalue_reference(input_reference) noexcept;
0279    #elif defined(BOOST_MOVE_OLD_RVALUE_REF_BINDING_RULES)
0280 
0281       //Old move approach, lvalues could bind to rvalue references
0282 
0283       template <class T>
0284       BOOST_MOVE_FORCEINLINE T&& move_if_not_lvalue_reference(typename ::boost::move_detail::identity<T>::type&& t) BOOST_NOEXCEPT
0285       {  return t;   }
0286 
0287    #else //Old move
0288 
0289       template <class T>
0290       BOOST_MOVE_FORCEINLINE T&& move_if_not_lvalue_reference(typename ::boost::move_detail::remove_reference<T>::type& t) BOOST_NOEXCEPT
0291       {  return static_cast<T&&>(t);   }
0292 
0293       template <class T>
0294       BOOST_MOVE_FORCEINLINE T&& move_if_not_lvalue_reference(typename ::boost::move_detail::remove_reference<T>::type&& t) BOOST_NOEXCEPT
0295       {
0296          //"boost::forward<T> error: 'T' is a lvalue reference, can't forward as rvalue.";
0297          BOOST_MOVE_STATIC_ASSERT(!boost::move_detail::is_lvalue_reference<T>::value);
0298          return static_cast<T&&>(t);
0299       }
0300 
0301    #endif   //BOOST_MOVE_DOXYGEN_INVOKED
0302 
0303    }  //namespace boost {
0304 
0305 #endif   //BOOST_NO_CXX11_RVALUE_REFERENCES
0306 
0307 #if !defined(BOOST_MOVE_DOXYGEN_INVOKED)
0308 
0309 namespace boost{
0310 namespace move_detail{
0311 
0312 template <typename T>
0313 typename boost::move_detail::add_rvalue_reference<T>::type declval();
0314 
0315 }  //namespace move_detail{
0316 }  //namespace boost{
0317 
0318 #endif   //#if !defined(BOOST_MOVE_DOXYGEN_INVOKED)
0319 
0320 
0321 #include <boost/move/detail/config_end.hpp>
0322 
0323 #endif //#ifndef BOOST_MOVE_MOVE_UTILITY_CORE_HPP