File indexing completed on 2025-01-18 09:30:30
0001 #ifndef BOOST_CORE_MEMORY_RESOURCE_HPP_INCLUDED
0002 #define BOOST_CORE_MEMORY_RESOURCE_HPP_INCLUDED
0003
0004
0005
0006 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
0007 # pragma once
0008 #endif
0009
0010
0011
0012
0013
0014 #include <boost/core/max_align.hpp>
0015 #include <boost/config.hpp>
0016 #include <boost/config/workaround.hpp>
0017 #include <cstddef>
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 namespace boost
0029 {
0030 namespace core
0031 {
0032 namespace detail
0033 {
0034
0035 struct placement_new_tag {};
0036
0037 }
0038 }
0039 }
0040
0041 inline void* operator new( std::size_t, void* p, boost::core::detail::placement_new_tag )
0042 {
0043 return p;
0044 }
0045
0046 inline void operator delete( void*, void*, boost::core::detail::placement_new_tag )
0047 {
0048 }
0049
0050 namespace boost
0051 {
0052 namespace core
0053 {
0054
0055 class memory_resource
0056 {
0057 public:
0058
0059 #if defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) || BOOST_WORKAROUND(BOOST_GCC, < 40700)
0060
0061 virtual ~memory_resource() {}
0062
0063 #else
0064
0065 virtual ~memory_resource() = default;
0066
0067 #endif
0068
0069 BOOST_ATTRIBUTE_NODISCARD void* allocate( std::size_t bytes, std::size_t alignment = max_align )
0070 {
0071
0072
0073
0074 return ::operator new( bytes, do_allocate( bytes, alignment ), core::detail::placement_new_tag() );
0075 }
0076
0077 void deallocate( void* p, std::size_t bytes, std::size_t alignment = max_align )
0078 {
0079 do_deallocate( p, bytes, alignment );
0080 }
0081
0082 bool is_equal( memory_resource const & other ) const BOOST_NOEXCEPT
0083 {
0084 return do_is_equal( other );
0085 }
0086
0087 private:
0088
0089 virtual void* do_allocate( std::size_t bytes, std::size_t alignment ) = 0;
0090 virtual void do_deallocate( void* p, std::size_t bytes, std::size_t alignment ) = 0;
0091
0092 virtual bool do_is_equal( memory_resource const & other ) const BOOST_NOEXCEPT = 0;
0093 };
0094
0095 inline bool operator==( memory_resource const& a, memory_resource const& b ) BOOST_NOEXCEPT
0096 {
0097 return &a == &b || a.is_equal( b );
0098 }
0099
0100 inline bool operator!=( memory_resource const& a, memory_resource const& b ) BOOST_NOEXCEPT
0101 {
0102 return !( a == b );
0103 }
0104
0105 }
0106 }
0107
0108 #endif