Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:02:30

0001 /*
0002 Copyright 2014-2015 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_ALIGN_ALIGNED_ALLOCATOR_HPP
0009 #define BOOST_ALIGN_ALIGNED_ALLOCATOR_HPP
0010 
0011 #include <boost/align/detail/add_reference.hpp>
0012 #include <boost/align/detail/is_alignment_constant.hpp>
0013 #include <boost/align/detail/max_objects.hpp>
0014 #include <boost/align/detail/max_size.hpp>
0015 #include <boost/align/detail/throw_exception.hpp>
0016 #include <boost/align/aligned_alloc.hpp>
0017 #include <boost/align/aligned_allocator_forward.hpp>
0018 #include <boost/align/alignment_of.hpp>
0019 #include <boost/static_assert.hpp>
0020 #include <new>
0021 
0022 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0023 #include <utility>
0024 #endif
0025 
0026 namespace boost {
0027 namespace alignment {
0028 
0029 template<class T, std::size_t Alignment>
0030 class aligned_allocator {
0031     BOOST_STATIC_ASSERT(detail::is_alignment_constant<Alignment>::value);
0032 
0033 public:
0034     typedef T value_type;
0035     typedef T* pointer;
0036     typedef const T* const_pointer;
0037     typedef void* void_pointer;
0038     typedef const void* const_void_pointer;
0039     typedef typename detail::add_lvalue_reference<T>::type reference;
0040     typedef typename detail::add_lvalue_reference<const
0041         T>::type const_reference;
0042     typedef std::size_t size_type;
0043     typedef std::ptrdiff_t difference_type;
0044     typedef detail::true_type propagate_on_container_move_assignment;
0045     typedef detail::true_type is_always_equal;
0046 
0047     template<class U>
0048     struct rebind {
0049         typedef aligned_allocator<U, Alignment> other;
0050     };
0051 
0052 #if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS)
0053     aligned_allocator() = default;
0054 #else
0055     aligned_allocator() BOOST_NOEXCEPT { }
0056 #endif
0057 
0058     template<class U>
0059     aligned_allocator(const aligned_allocator<U, Alignment>&)
0060         BOOST_NOEXCEPT { }
0061 
0062     pointer allocate(size_type size, const_void_pointer = 0) {
0063         enum {
0064             m = detail::max_size<Alignment,
0065                 alignment_of<value_type>::value>::value
0066         };
0067         if (size == 0) {
0068             return 0;
0069         }
0070         void* p = boost::alignment::aligned_alloc(m, sizeof(T) * size);
0071         if (!p) {
0072             detail::throw_exception(std::bad_alloc());
0073         }
0074         return static_cast<T*>(p);
0075     }
0076 
0077     void deallocate(pointer ptr, size_type) {
0078         boost::alignment::aligned_free(ptr);
0079     }
0080 
0081     BOOST_CONSTEXPR size_type max_size() const BOOST_NOEXCEPT {
0082         return detail::max_objects<T>::value;
0083     }
0084 
0085 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0086 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
0087     template<class U, class... Args>
0088     void construct(U* ptr, Args&&... args) {
0089         ::new((void*)ptr) U(std::forward<Args>(args)...);
0090     }
0091 #else
0092     template<class U, class V>
0093     void construct(U* ptr, V&& value) {
0094         ::new((void*)ptr) U(std::forward<V>(value));
0095     }
0096 #endif
0097 #else
0098     template<class U, class V>
0099     void construct(U* ptr, const V& value) {
0100         ::new((void*)ptr) U(value);
0101     }
0102 
0103     template<class U, class V>
0104     void construct(U* ptr, V& value) {
0105         ::new((void*)ptr) U(value);
0106     }
0107 #endif
0108 
0109     template<class U>
0110     void construct(U* ptr) {
0111         ::new((void*)ptr) U();
0112     }
0113 
0114     template<class U>
0115     void destroy(U* ptr) {
0116         (void)ptr;
0117         ptr->~U();
0118     }
0119 };
0120 
0121 template<class T, class U, std::size_t Alignment>
0122 inline bool
0123 operator==(const aligned_allocator<T, Alignment>&,
0124     const aligned_allocator<U, Alignment>&) BOOST_NOEXCEPT
0125 {
0126     return true;
0127 }
0128 
0129 template<class T, class U, std::size_t Alignment>
0130 inline bool
0131 operator!=(const aligned_allocator<T, Alignment>&,
0132     const aligned_allocator<U, Alignment>&) BOOST_NOEXCEPT
0133 {
0134     return false;
0135 }
0136 
0137 } /* alignment */
0138 } /* boost */
0139 
0140 #endif