Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-20 08:40:05

0001 /*
0002 Copyright 2019 Glen Joseph Fernandes
0003 (glenjofe@gmail.com)
0004 
0005 Distributed under the Boost Software License, Version 1.0.
0006 (http://www.boost.org/LICENSE_1_0.txt)
0007 */
0008 #ifndef BOOST_CORE_DEFAULT_ALLOCATOR_HPP
0009 #define BOOST_CORE_DEFAULT_ALLOCATOR_HPP
0010 
0011 #include <boost/config.hpp>
0012 #include <new>
0013 #include <cstddef>
0014 
0015 namespace boost {
0016 
0017 #if defined(BOOST_NO_EXCEPTIONS)
0018 BOOST_NORETURN void throw_exception(const std::exception&);
0019 #endif
0020 
0021 namespace default_ {
0022 
0023 template<bool V>
0024 struct bool_constant {
0025     typedef bool value_type;
0026     typedef bool_constant type;
0027 
0028     static const bool value = V;
0029 
0030     operator bool() const BOOST_NOEXCEPT {
0031         return V;
0032     }
0033 
0034     bool operator()() const BOOST_NOEXCEPT {
0035         return V;
0036     }
0037 };
0038 
0039 template<bool V>
0040 const bool bool_constant<V>::value;
0041 
0042 template<class T>
0043 struct add_reference {
0044     typedef T& type;
0045 };
0046 
0047 template<>
0048 struct add_reference<void> {
0049     typedef void type;
0050 };
0051 
0052 template<>
0053 struct add_reference<const void> {
0054     typedef const void type;
0055 };
0056 
0057 template<class T>
0058 struct default_allocator {
0059     typedef T value_type;
0060     typedef T* pointer;
0061     typedef const T* const_pointer;
0062     typedef typename add_reference<T>::type reference;
0063     typedef typename add_reference<const T>::type const_reference;
0064     typedef std::size_t size_type;
0065     typedef std::ptrdiff_t difference_type;
0066     typedef bool_constant<true> propagate_on_container_move_assignment;
0067     typedef bool_constant<true> is_always_equal;
0068 
0069     template<class U>
0070     struct rebind {
0071         typedef default_allocator<U> other;
0072     };
0073 
0074 #if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS)
0075     default_allocator() = default;
0076 #else
0077     BOOST_CONSTEXPR default_allocator() BOOST_NOEXCEPT { }
0078 #endif
0079 
0080     template<class U>
0081     BOOST_CONSTEXPR default_allocator(const default_allocator<U>&)
0082         BOOST_NOEXCEPT { }
0083 
0084     BOOST_CONSTEXPR std::size_t max_size() const BOOST_NOEXCEPT {
0085         return static_cast<std::size_t>(-1) / (2 < sizeof(T) ? sizeof(T) : 2);
0086     }
0087 
0088 #if !defined(BOOST_NO_EXCEPTIONS)
0089     T* allocate(std::size_t n) {
0090         if (n > max_size()) {
0091             throw std::bad_alloc();
0092         }
0093         return static_cast<T*>(::operator new(sizeof(T) * n));
0094     }
0095 
0096     void deallocate(T* p, std::size_t) {
0097         ::operator delete(p);
0098     }
0099 #else
0100     T* allocate(std::size_t n) {
0101         if (n > max_size()) {
0102             boost::throw_exception(std::bad_alloc());
0103         }
0104         void* p = ::operator new(sizeof(T) * n, std::nothrow);
0105         if (!p) {
0106             boost::throw_exception(std::bad_alloc());
0107         }
0108         return static_cast<T*>(p);
0109     }
0110 
0111     void deallocate(T* p, std::size_t) {
0112         ::operator delete(p, std::nothrow);
0113     }
0114 #endif
0115 
0116 #if defined(BOOST_NO_CXX11_ALLOCATOR)
0117     T* allocate(std::size_t n, const void*) {
0118         return allocate(n);
0119     }
0120 #endif
0121 
0122 #if (defined(BOOST_LIBSTDCXX_VERSION) && BOOST_LIBSTDCXX_VERSION < 60000) || \
0123     defined(BOOST_NO_CXX11_ALLOCATOR)
0124     template<class U, class V>
0125     void construct(U* p, const V& v) {
0126         ::new(p) U(v);
0127     }
0128 
0129     template<class U>
0130     void destroy(U* p) {
0131         p->~U();
0132         (void)p;
0133     }
0134 #endif
0135 };
0136 
0137 template<class T, class U>
0138 BOOST_CONSTEXPR inline bool
0139 operator==(const default_allocator<T>&,
0140     const default_allocator<U>&) BOOST_NOEXCEPT
0141 {
0142     return true;
0143 }
0144 
0145 template<class T, class U>
0146 BOOST_CONSTEXPR inline bool
0147 operator!=(const default_allocator<T>&,
0148     const default_allocator<U>&) BOOST_NOEXCEPT
0149 {
0150     return false;
0151 }
0152 
0153 } /* default_ */
0154 
0155 using default_::default_allocator;
0156 
0157 } /* boost */
0158 
0159 #endif