6#ifndef NUMERICAL_BUFFER_HPP
7#define NUMERICAL_BUFFER_HPP
57 static constexpr std::size_t
huge_page {std::size_t {1} << 21U};
65 static constexpr std::size_t
huge_least {std::size_t {1} << 24U};
84 return std::allocator<T>::allocate(n);
86 static std::atomic<std::size_t>
colour {0};
87 const std::size_t offset {((
colour.fetch_add(1) %
huge_colours) * 4096) +
alignof(std::max_align_t) * 4};
91 std::byte*
const data {start + offset};
92 std::memcpy(data -
sizeof(std::size_t), &offset,
sizeof(std::size_t));
93 return reinterpret_cast<T*
>(data);
98 std::size_t n)
noexcept
101 std::allocator<T>::deallocate(at, n);
114 auto*
const data {
reinterpret_cast<std::byte*
>(at)};
115 std::size_t offset {};
116 std::memcpy(&offset, data -
sizeof(std::size_t),
sizeof(std::size_t));
123 template <
typename U>
124 void construct(
U* at)
noexcept(std::is_nothrow_default_constructible_v<U>)
126 ::new (
static_cast<void*
>(at))
U;
130 template <
typename U,
135 ::new (
static_cast<void*
>(at))
U(std::forward<Args>(
args)...);
143 template <
typename T>
145 const std::vector<T>& other)
147 return std::equal(
buffer.begin(),
buffer.end(), other.begin(), other.end());
156 template <
typename T>
157 using buffer = std::vector<T, detail::default_init_allocator<T>>;
bool operator==(const std::vector< T, default_init_allocator< T > > &buffer, const std::vector< T > &other)
Element-wise equality of a numerical::buffer and a std::vector, found by argument-dependent lookup th...
The NumericAL public API.
std::vector< T, detail::default_init_allocator< T > > buffer
The storage of vector, matrix and tensor, namely a std::vector whose buffer<T>(n) and resize(n) leave...
The allocator of another element type, as std::allocator_traits rebinds it.
The allocator of numerical::buffer. An element constructed with no value is default-initialised,...
void construct(U *at, Args &&... args)
Constructs the element at at from args.
void construct(U *at) noexcept(std::is_nothrow_default_constructible_v< U >)
Default-initialises the element at at.
T value_type
The element type.
default_init_allocator() noexcept=default