Back to home page

EIC code displayed by LXR

 
 

    


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 // MS compatible compilers support #pragma once
0005 
0006 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
0007 # pragma once
0008 #endif
0009 
0010 //  Copyright 2023 Peter Dimov
0011 //  Distributed under the Boost Software License, Version 1.0.
0012 //  https://www.boost.org/LICENSE_1_0.txt
0013 
0014 #include <boost/core/max_align.hpp>
0015 #include <boost/config.hpp>
0016 #include <boost/config/workaround.hpp>
0017 #include <cstddef>
0018 
0019 // Define our own placement new to avoid the inclusion of <new>
0020 // (~9K extra lines) at Ion Gaztanhaga's request.
0021 //
0022 // We can use our own because [intro.object] p13 says:
0023 //
0024 // Any implicit or explicit invocation of a function named `operator new`
0025 // or `operator new[]` implicitly creates objects in the returned region of
0026 // storage and returns a pointer to a suitable created object.
0027 
0028 namespace boost
0029 {
0030 namespace core
0031 {
0032 namespace detail
0033 {
0034 
0035 struct placement_new_tag {};
0036 
0037 } // namespace detail
0038 } // namespace core
0039 } // namespace boost
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         // https://github.com/boostorg/container/issues/199
0072         // https://cplusplus.github.io/LWG/issue3471
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 } // namespace core
0106 } // namespace boost
0107 
0108 #endif  // #ifndef BOOST_CORE_MEMORY_RESOURCE_HPP_INCLUDED