Warning, file /include/boost/container/new_allocator.hpp was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
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 { BOOST_STATIC_CONSTEXPR 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 inline new_allocator() BOOST_NOEXCEPT_OR_NOTHROW
0133 {}
0134
0135
0136
0137 inline new_allocator(const new_allocator &) BOOST_NOEXCEPT_OR_NOTHROW
0138 {}
0139
0140
0141
0142 inline new_allocator& operator=(const new_allocator &) BOOST_NOEXCEPT_OR_NOTHROW
0143 { return *this; }
0144
0145
0146
0147 template<class T2>
0148 inline new_allocator(const new_allocator<T2> &) BOOST_NOEXCEPT_OR_NOTHROW
0149 {}
0150
0151
0152
0153 pointer allocate(size_type count)
0154 {
0155 const std::size_t max_count = std::size_t(-1)/(2*sizeof(T));
0156 if(BOOST_UNLIKELY(count > max_count))
0157 throw_bad_alloc();
0158 return static_cast<T*>(::operator new(count*sizeof(T)));
0159 }
0160
0161
0162
0163 void deallocate(pointer ptr, size_type n) BOOST_NOEXCEPT_OR_NOTHROW
0164 {
0165 (void)n;
0166 # if __cpp_sized_deallocation
0167 ::operator delete((void*)ptr, n * sizeof(T));
0168 #else
0169 ::operator delete((void*)ptr);
0170 # endif
0171 }
0172
0173
0174
0175 inline size_type max_size() const BOOST_NOEXCEPT_OR_NOTHROW
0176 { return std::size_t(-1)/(2*sizeof(T)); }
0177
0178
0179
0180 inline friend void swap(new_allocator &, new_allocator &) BOOST_NOEXCEPT_OR_NOTHROW
0181 {}
0182
0183
0184
0185 inline friend bool operator==(const new_allocator &, const new_allocator &) BOOST_NOEXCEPT_OR_NOTHROW
0186 { return true; }
0187
0188
0189
0190 inline friend bool operator!=(const new_allocator &, const new_allocator &) BOOST_NOEXCEPT_OR_NOTHROW
0191 { return false; }
0192 };
0193
0194 }
0195 }
0196
0197 #include <boost/container/detail/config_end.hpp>
0198
0199 #endif