1
0
forked from boostorg/move

Use [[msvc::intrinsic] attribute if available in move/forward in order to improve debug experience

This commit is contained in:
Ion Gaztañaga
2023-03-13 13:32:29 +01:00
parent 0865eb3a80
commit f1fbb45134
3 changed files with 22 additions and 5 deletions

View File

@ -130,5 +130,19 @@ template<unsigned> struct static_assert_test {};
#endif
#if !defined(__has_cpp_attribute) || defined(__CUDACC__)
#define BOOST_MOVE_HAS_MSVC_ATTRIBUTE(ATTR) 0
#else
#define BOOST_MOVE_HAS_MSVC_ATTRIBUTE(ATTR) __has_cpp_attribute(msvc::ATTR)
#endif
// See https://devblogs.microsoft.com/cppblog/improving-the-state-of-debug-performance-in-c/
// for details on how MSVC has improved debug experience, specifically for move/forward-like utilities
#if BOOST_MOVE_HAS_MSVC_ATTRIBUTE(intrinsic)
#define BOOST_MOVE_INTRINSIC_CAST [[msvc::intrinsic]]
#else
#define BOOST_MOVE_INTRINSIC_CAST BOOST_MOVE_FORCEINLINE
#endif
#endif //#ifndef BOOST_MOVE_DETAIL_WORKAROUND_HPP

View File

@ -126,13 +126,13 @@
#else //BOOST_MOVE_DOXYGEN_INVOKED
template <class T>
BOOST_MOVE_FORCEINLINE typename ::boost::move_detail::enable_if_c
BOOST_MOVE_INTRINSIC_CAST typename ::boost::move_detail::enable_if_c
< ::boost::move_detail::is_nothrow_move_constructible_or_uncopyable<T>::value, T&&>::type
move_if_noexcept(T& x) BOOST_NOEXCEPT
{ return ::boost::move(x); }
template <class T>
BOOST_MOVE_FORCEINLINE typename ::boost::move_detail::enable_if_c
BOOST_MOVE_INTRINSIC_CAST typename ::boost::move_detail::enable_if_c
< !::boost::move_detail::is_nothrow_move_constructible_or_uncopyable<T>::value, const T&>::type
move_if_noexcept(T& x) BOOST_NOEXCEPT
{ return x; }

View File

@ -208,7 +208,8 @@
#else //BOOST_MOVE_OLD_RVALUE_REF_BINDING_RULES
template <class T>
BOOST_MOVE_FORCEINLINE typename ::boost::move_detail::remove_reference<T>::type && move(T&& t) BOOST_NOEXCEPT
BOOST_MOVE_INTRINSIC_CAST
typename ::boost::move_detail::remove_reference<T>::type && move(T&& t) BOOST_NOEXCEPT
{ return static_cast<typename ::boost::move_detail::remove_reference<T>::type &&>(t); }
#endif //BOOST_MOVE_OLD_RVALUE_REF_BINDING_RULES
@ -244,11 +245,13 @@
#else //Old move
template <class T>
BOOST_MOVE_FORCEINLINE T&& forward(typename ::boost::move_detail::remove_reference<T>::type& t) BOOST_NOEXCEPT
BOOST_MOVE_INTRINSIC_CAST
T&& forward(typename ::boost::move_detail::remove_reference<T>::type& t) BOOST_NOEXCEPT
{ return static_cast<T&&>(t); }
template <class T>
BOOST_MOVE_FORCEINLINE T&& forward(typename ::boost::move_detail::remove_reference<T>::type&& t) BOOST_NOEXCEPT
BOOST_MOVE_INTRINSIC_CAST
T&& forward(typename ::boost::move_detail::remove_reference<T>::type&& t) BOOST_NOEXCEPT
{
//"boost::forward<T> error: 'T' is a lvalue reference, can't forward as rvalue.";
BOOST_MOVE_STATIC_ASSERT(!boost::move_detail::is_lvalue_reference<T>::value);