21 #ifndef INCLUDE_LIBINT2_UTIL_ARRAY_ADAPTOR_H_ 22 #define INCLUDE_LIBINT2_UTIL_ARRAY_ADAPTOR_H_ 27 #include <type_traits> 35 template <
class T, std::
size_t N>
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_) {}
67 template <typename U, typename = typename std::enable_if<std::is_same<const U,T>::value>>
69 : stack_(const_cast<T*>(&array[0])), free_(stack_) {}
76 T* allocate(std::size_t n) {
77 assert(stack_ !=
nullptr &&
"array_view_allocator not initialized");
78 if (stack_ + N - free_ >=
79 static_cast<std::ptrdiff_t>(n)) {
80 const auto result = free_;
87 void deallocate(T* p, std::size_t n) noexcept {
88 if (pointer_on_stack(p)) {
89 assert(p + n == free_ &&
"stack deallocation out of order");
96 template <
class T1, std::
size_t N1>
97 friend bool operator==(
const ext_stack_allocator<T1, N1>& x,
98 const ext_stack_allocator<T1, N1>& y) noexcept;
101 bool pointer_on_stack(T* ptr)
const {
102 return stack_ <= ptr && ptr < stack_ + N;
106 template <
class T, std::
size_t N>
107 inline bool operator==(
const ext_stack_allocator<T, N>& x,
108 const ext_stack_allocator<T, N>& y) noexcept {
109 return x.stack_ == y.stack_ && x.free_ == y.free_;
112 template <
class T, std::
size_t N>
113 inline bool operator!=(
const ext_stack_allocator<T, N>& x,
114 const ext_stack_allocator<T, N>& y) noexcept {
120 #endif // INCLUDE_LIBINT2_UTIL_ARRAY_ADAPTOR_H_ Definition: array_adaptor.h:72
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:24
allocator that uses an externally-managed stack-allocated array for allocations up to max_size,...
Definition: array_adaptor.h:36