Edit: /usr/include/boost/align/aligned_allocator.hpp (3725B)
/*
Copyright 2014-2015 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_ALIGN_ALIGNED_ALLOCATOR_HPP
#define BOOST_ALIGN_ALIGNED_ALLOCATOR_HPP
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
#include
#endif
namespace boost {
namespace alignment {
template
class aligned_allocator {
BOOST_STATIC_ASSERT(detail::is_alignment_constant::value);
public:
typedef T value_type;
typedef T* pointer;
typedef const T* const_pointer;
typedef void* void_pointer;
typedef const void* const_void_pointer;
typedef typename detail::add_lvalue_reference::type reference;
typedef typename detail::add_lvalue_reference::type const_reference;
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef detail::true_type propagate_on_container_move_assignment;
typedef detail::true_type is_always_equal;
template
struct rebind {
typedef aligned_allocator other;
};
#if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS)
aligned_allocator() = default;
#else
aligned_allocator() BOOST_NOEXCEPT { }
#endif
template
aligned_allocator(const aligned_allocator&)
BOOST_NOEXCEPT { }
pointer allocate(size_type size, const_void_pointer = 0) {
enum {
m = detail::max_size::value>::value
};
if (size == 0) {
return 0;
}
void* p = boost::alignment::aligned_alloc(m, sizeof(T) * size);
if (!p) {
detail::throw_exception(std::bad_alloc());
}
return static_cast(p);
}
void deallocate(pointer ptr, size_type) {
boost::alignment::aligned_free(ptr);
}
BOOST_CONSTEXPR size_type max_size() const BOOST_NOEXCEPT {
return detail::max_objects::value;
}
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template
void construct(U* ptr, Args&&... args) {
::new((void*)ptr) U(std::forward(args)...);
}
#else
template
void construct(U* ptr, V&& value) {
::new((void*)ptr) U(std::forward(value));
}
#endif
#else
template
void construct(U* ptr, const V& value) {
::new((void*)ptr) U(value);
}
template
void construct(U* ptr, V& value) {
::new((void*)ptr) U(value);
}
#endif
template
void construct(U* ptr) {
::new((void*)ptr) U();
}
template
void destroy(U* ptr) {
(void)ptr;
ptr->~U();
}
};
template
inline bool
operator==(const aligned_allocator&,
const aligned_allocator&) BOOST_NOEXCEPT
{
return true;
}
template
inline bool
operator!=(const aligned_allocator&,
const aligned_allocator&) BOOST_NOEXCEPT
{
return false;
}
} /* alignment */
} /* boost */
#endif