////////////////////////////////////////////////////////////////////////////// // // (C) Copyright Ion Gaztanaga 2012-2012. // 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) // // See http://www.boost.org/libs/move for documentation. // ////////////////////////////////////////////////////////////////////////////// //! \file #ifndef BOOST_MOVE_MOVE_UTILITY_HPP #define BOOST_MOVE_MOVE_UTILITY_HPP #include #include #include #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_MOVE_DOXYGEN_INVOKED) namespace boost { template struct enable_move_utility_emulation { static const bool value = true; }; ////////////////////////////////////////////////////////////////////////////// // // move() // ////////////////////////////////////////////////////////////////////////////// template inline typename ::boost::move_detail::enable_if_c < enable_move_utility_emulation::value && !has_move_emulation_enabled::value, T&>::type move(T& x) BOOST_NOEXCEPT { return x; } template inline typename ::boost::move_detail::enable_if_c < enable_move_utility_emulation::value && has_move_emulation_enabled::value, rv&>::type move(T& x) BOOST_NOEXCEPT { return *static_cast* >(::boost::move_detail::addressof(x)); } template inline typename ::boost::move_detail::enable_if_c < enable_move_utility_emulation::value && has_move_emulation_enabled::value, rv&>::type move(rv& x) BOOST_NOEXCEPT { return x; } ////////////////////////////////////////////////////////////////////////////// // // forward() // ////////////////////////////////////////////////////////////////////////////// template inline typename ::boost::move_detail::enable_if_c < enable_move_utility_emulation::value && ::boost::move_detail::is_rv::value, T &>::type forward(const typename ::boost::move_detail::identity::type &x) BOOST_NOEXCEPT { return const_cast(x); } template inline typename ::boost::move_detail::enable_if_c < enable_move_utility_emulation::value && !::boost::move_detail::is_rv::value, const T &>::type forward(const typename ::boost::move_detail::identity::type &x) BOOST_NOEXCEPT { return x; } } //namespace boost #else //#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_MOVE_DOXYGEN_INVOKED) #if defined(BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE) #include namespace boost{ using ::std::move; using ::std::forward; } //namespace boost #else //!BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE #include namespace boost { //! This trait's internal boolean `value` is false in compilers with rvalue references //! and true in compilers without rvalue references. //! //! A user can specialize this trait for a type T to false to SFINAE out `move` and `forward` //! so that the user can define a different move emulation for that type in namespace boost //! (e.g. another Boost library for its types) and avoid any overload ambiguity. template struct enable_move_utility_emulation { static const bool value = false; }; ////////////////////////////////////////////////////////////////////////////// // // move // ////////////////////////////////////////////////////////////////////////////// #if defined(BOOST_MOVE_DOXYGEN_INVOKED) //! This function provides a way to convert a reference into a rvalue reference //! in compilers with rvalue references. For other compilers converts T & into //! ::boost::rv & so that move emulation is activated. template rvalue_reference move(input_reference) noexcept; #elif defined(BOOST_MOVE_OLD_RVALUE_REF_BINDING_RULES) //Old move approach, lvalues could bind to rvalue references template inline typename remove_reference::type && move(T&& t) BOOST_NOEXCEPT { return t; } #else //BOOST_MOVE_OLD_RVALUE_REF_BINDING_RULES template inline typename remove_reference::type && move(T&& t) BOOST_NOEXCEPT { return static_cast::type &&>(t); } #endif //BOOST_MOVE_OLD_RVALUE_REF_BINDING_RULES ////////////////////////////////////////////////////////////////////////////// // // forward // ////////////////////////////////////////////////////////////////////////////// #if defined(BOOST_MOVE_DOXYGEN_INVOKED) //! This function provides limited form of forwarding that is usually enough for //! in-place construction and avoids the exponential overloading for //! achieve the limited forwarding in C++03. //! //! For compilers with rvalue references this function provides perfect forwarding. //! //! Otherwise: //! * If input_reference binds to const ::boost::rv & then it output_reference is //! ::boost::rv & //! //! * Else, output_reference is equal to input_reference. template output_reference forward(input_reference) noexcept; #elif defined(BOOST_MOVE_OLD_RVALUE_REF_BINDING_RULES) //Old move approach, lvalues could bind to rvalue references template inline T&& forward(typename ::boost::move_detail::identity::type&& t) BOOST_NOEXCEPT { return t; } #else //Old move //Implementation #5 from N2951, thanks to Howard Hinnant template inline T&& forward(U&& t , typename ::boost::move_detail::enable_if_c< move_detail::is_lvalue_reference::value ? move_detail::is_lvalue_reference::value : true>::type * = 0/* , typename ::boost::move_detail::enable_if_c< move_detail::is_convertible ::type*, typename remove_reference::type*>::value>::type * = 0*/) BOOST_NOEXCEPT { return static_cast(t); } #endif //BOOST_MOVE_DOXYGEN_INVOKED } //namespace boost { #endif //#if defined(BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE) #endif //BOOST_NO_CXX11_RVALUE_REFERENCES #include #endif //#ifndef BOOST_MOVE_MOVE_UTILITY_HPP