40 using difference_type =
41 typename std::pointer_traits<pointer>::difference_type;
42 using size_type =
typename std::make_unsigned<difference_type>::type;
43 using propagate_on_container_copy_assignment = std::true_type;
44 using propagate_on_container_move_assignment = std::true_type;
46 static auto constexpr size = N;
47 typedef T array_type[N];
57 : stack_(other.stack_), free_(other.free_) {}
60 stack_ = other.stack_;
66 : stack_(&array[0]), free_(stack_) {}
68 typename =
typename std::enable_if<std::is_same<const U, T>::value>>
70 : stack_(
const_cast<T*
>(&array[0])), free_(stack_) {}
77 T* allocate(std::size_t n) {
78 assert(stack_ !=
nullptr &&
"array_view_allocator not initialized");
79 if (stack_ + N - free_ >=
80 static_cast<std::ptrdiff_t
>(n)) {
81 const auto result = free_;
88 void deallocate(T* p, std::size_t n)
noexcept {
89 if (pointer_on_stack(p)) {
90 assert(p + n == free_ &&
"stack deallocation out of order");
97 template <
class T1, std::
size_t N1>
98 friend bool operator==(
const ext_stack_allocator<T1, N1>& x,
99 const ext_stack_allocator<T1, N1>& y)
noexcept;
102 bool pointer_on_stack(T* ptr)
const {
103 return stack_ <= ptr && ptr < stack_ + N;