From a21f594af69729e9788999db9387f77873e3e23f Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 5 Nov 2019 18:48:15 +0200 Subject: [PATCH] Use std::reference_wrapper --- include/boost/core/ref.hpp | 86 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/include/boost/core/ref.hpp b/include/boost/core/ref.hpp index 77ef2b6..7ae88ff 100644 --- a/include/boost/core/ref.hpp +++ b/include/boost/core/ref.hpp @@ -7,6 +7,90 @@ # pragma once #endif +#if 1 + +#include +#include + +namespace boost +{ + +using std::reference_wrapper; +using std::ref; +using std::cref; + +// is_reference_wrapper + +template struct is_reference_wrapper +{ + BOOST_STATIC_CONSTANT( bool, value = false ); +}; + +template struct is_reference_wrapper< reference_wrapper > +{ + BOOST_STATIC_CONSTANT( bool, value = true ); +}; + +template struct is_reference_wrapper< reference_wrapper const > +{ + BOOST_STATIC_CONSTANT( bool, value = true ); +}; + +template struct is_reference_wrapper< reference_wrapper volatile > +{ + BOOST_STATIC_CONSTANT( bool, value = true ); +}; + +template struct is_reference_wrapper< reference_wrapper const volatile > +{ + BOOST_STATIC_CONSTANT( bool, value = true ); +}; + +// unwrap_reference + +template struct unwrap_reference +{ + typedef T type; +}; + +template struct unwrap_reference< reference_wrapper > +{ + typedef T type; +}; + +template struct unwrap_reference< reference_wrapper const > +{ + typedef T type; +}; + +template struct unwrap_reference< reference_wrapper volatile > +{ + typedef T type; +}; + +template struct unwrap_reference< reference_wrapper const volatile > +{ + typedef T type; +}; + +// unwrap_ref + +template BOOST_FORCEINLINE typename unwrap_reference::type& unwrap_ref( T & t ) +{ + return t; +} + +// get_pointer + +template BOOST_FORCEINLINE T* get_pointer( reference_wrapper const & r ) +{ + return std::addressof( r.get() ); +} + +} // namespace boost + +#else + #include #include #include @@ -299,4 +383,6 @@ template BOOST_FORCEINLINE T* get_pointer( reference_wrapper const & } // namespace boost +#endif + #endif // #ifndef BOOST_CORE_REF_HPP