File indexing completed on 2025-01-18 09:30:18
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_CONTAINER_NEW_ALLOCATOR_HPP
0012 #define BOOST_CONTAINER_NEW_ALLOCATOR_HPP
0013
0014 #ifndef BOOST_CONFIG_HPP
0015 # include <boost/config.hpp>
0016 #endif
0017
0018 #if defined(BOOST_HAS_PRAGMA_ONCE)
0019 # pragma once
0020 #endif
0021
0022 #include <boost/container/detail/config_begin.hpp>
0023 #include <boost/container/detail/workaround.hpp>
0024 #include <boost/container/throw_exception.hpp>
0025 #include <cstddef>
0026
0027
0028
0029 namespace boost {
0030 namespace container {
0031
0032
0033
0034 template<bool Value>
0035 struct new_allocator_bool
0036 { static const bool value = Value; };
0037
0038 template<class T>
0039 class new_allocator;
0040
0041
0042
0043
0044 template<>
0045 class new_allocator<void>
0046 {
0047 public:
0048 typedef void value_type;
0049 typedef void * pointer;
0050 typedef const void* const_pointer;
0051
0052 typedef BOOST_CONTAINER_IMPDEF(new_allocator_bool<true>) propagate_on_container_move_assignment;
0053
0054 typedef BOOST_CONTAINER_IMPDEF(new_allocator_bool<true>) is_always_equal;
0055
0056
0057
0058
0059 template<class T2>
0060 struct rebind
0061 {
0062 typedef new_allocator< T2> other;
0063 };
0064
0065
0066
0067 new_allocator() BOOST_NOEXCEPT_OR_NOTHROW
0068 {}
0069
0070
0071
0072 new_allocator(const new_allocator &) BOOST_NOEXCEPT_OR_NOTHROW
0073 {}
0074
0075
0076
0077 new_allocator& operator=(const new_allocator &) BOOST_NOEXCEPT_OR_NOTHROW
0078 {
0079 return *this;
0080 }
0081
0082
0083
0084 template<class T2>
0085 new_allocator(const new_allocator<T2> &) BOOST_NOEXCEPT_OR_NOTHROW
0086 {}
0087
0088
0089
0090 friend void swap(new_allocator &, new_allocator &) BOOST_NOEXCEPT_OR_NOTHROW
0091 {}
0092
0093
0094
0095 friend bool operator==(const new_allocator &, const new_allocator &) BOOST_NOEXCEPT_OR_NOTHROW
0096 { return true; }
0097
0098
0099
0100 friend bool operator!=(const new_allocator &, const new_allocator &) BOOST_NOEXCEPT_OR_NOTHROW
0101 { return false; }
0102 };
0103
0104
0105
0106 template<class T>
0107 class new_allocator
0108 {
0109 public:
0110 typedef T value_type;
0111 typedef T * pointer;
0112 typedef const T * const_pointer;
0113 typedef T & reference;
0114 typedef const T & const_reference;
0115 typedef std::size_t size_type;
0116 typedef std::ptrdiff_t difference_type;
0117
0118 typedef BOOST_CONTAINER_IMPDEF(new_allocator_bool<true>) propagate_on_container_move_assignment;
0119
0120 typedef BOOST_CONTAINER_IMPDEF(new_allocator_bool<true>) is_always_equal;
0121
0122
0123
0124 template<class T2>
0125 struct rebind
0126 {
0127 typedef new_allocator<T2> other;
0128 };
0129
0130
0131
0132 new_allocator() BOOST_NOEXCEPT_OR_NOTHROW
0133 {}
0134
0135
0136
0137 new_allocator(const new_allocator &) BOOST_NOEXCEPT_OR_NOTHROW
0138 {}
0139
0140
0141
0142 new_allocator& operator=(const new_allocator &) BOOST_NOEXCEPT_OR_NOTHROW
0143 {
0144 return *this;
0145 }
0146
0147
0148
0149 template<class T2>
0150 new_allocator(const new_allocator<T2> &) BOOST_NOEXCEPT_OR_NOTHROW
0151 {}
0152
0153
0154
0155 pointer allocate(size_type count)
0156 {
0157 const std::size_t max_count = std::size_t(-1)/(2*sizeof(T));
0158 if(BOOST_UNLIKELY(count > max_count))
0159 throw_bad_alloc();
0160 return static_cast<T*>(::operator new(count*sizeof(T)));
0161 }
0162
0163
0164
0165 void deallocate(pointer ptr, size_type n) BOOST_NOEXCEPT_OR_NOTHROW
0166 {
0167 (void)n;
0168 # if __cpp_sized_deallocation
0169 ::operator delete((void*)ptr, n * sizeof(T));
0170 #else
0171 ::operator delete((void*)ptr);
0172 # endif
0173 }
0174
0175
0176
0177 size_type max_size() const BOOST_NOEXCEPT_OR_NOTHROW
0178 { return std::size_t(-1)/(2*sizeof(T)); }
0179
0180
0181
0182 friend void swap(new_allocator &, new_allocator &) BOOST_NOEXCEPT_OR_NOTHROW
0183 {}
0184
0185
0186
0187 friend bool operator==(const new_allocator &, const new_allocator &) BOOST_NOEXCEPT_OR_NOTHROW
0188 { return true; }
0189
0190
0191
0192 friend bool operator!=(const new_allocator &, const new_allocator &) BOOST_NOEXCEPT_OR_NOTHROW
0193 { return false; }
0194 };
0195
0196 }
0197 }
0198
0199 #include <boost/container/detail/config_end.hpp>
0200
0201 #endif