27 template <
typename FromBufferRef,
typename T>
28 concept BufferReference = std::ranges::contiguous_range<FromBufferRef> && std::is_reference_v<FromBufferRef>
29 && (
sizeof(std::ranges::range_value_t<FromBufferRef>) <=
sizeof(T));
31 template <
typename FromBufferRef,
typename T>
42 template <
typename To, BufferReference<To> FromBufferRef>
53 static constexpr bool is_const = std::is_const_v<To>;
56 using buffer_reference = std::conditional_t<is_const, const FromBufferRef, FromBufferRef>;
58 using size_type = std::remove_cvref_t<buffer_reference>::size_type;
116 [[nodiscard]] constexpr
bool empty() const noexcept;
132 template <class InputIt>
133 requires
std::input_iterator<InputIt>
139 template <class... Args>
165 static constexpr
size_type m_to_from_size_ratio = static_cast<
size_type>(1. / m_from_to_size_ratio);
168 index_for_buffer(
size_type idx) const noexcept
170 return idx * m_to_from_size_ratio;
173 [[nodiscard]] std::remove_cvref_t<buffer_reference>::const_iterator
176 const difference_type index = std::distance(
cbegin(), pos);
177 const auto idx_for_buffer = index_for_buffer(
static_cast<size_type
>(index));
179 return std::next(m_buffer.cbegin(),
static_cast<difference_type
>(idx_for_buffer));
183 size_type m_max_size;
191 template <
class... Args>
193 :
value(
std::forward<Args>(args)...)
200 template <
typename To, BufferReference<To> FromBufferRef>
205 , m_max_size(m_buffer.
max_size() / m_to_from_size_ratio)
209 template <
typename To, BufferReference<To> FromBufferRef>
213 , m_max_size(m_buffer.max_size() / m_to_from_size_ratio)
217 template <
typename To, BufferReference<To> FromBufferRef>
218 requires T_is_const_if_FromBufferRef_is_const<FromBufferRef, To>
226 template <
typename To, BufferReference<To> FromBufferRef>
234 template <
typename To, BufferReference<To> FromBufferRef>
244 template <
typename To, BufferReference<To> FromBufferRef>
253 template <
typename To, BufferReference<To> FromBufferRef>
262 template <
typename To, BufferReference<To> FromBufferRef>
271 template <
typename To, BufferReference<To> FromBufferRef>
280 template <
typename To, BufferReference<To> FromBufferRef>
289 template <
typename To, BufferReference<To> FromBufferRef>
298 template <
typename To, BufferReference<To> FromBufferRef>
307 template <
typename To, BufferReference<To> FromBufferRef>
315 template <
typename To, BufferReference<To> FromBufferRef>
323 template <
typename To, BufferReference<To> FromBufferRef>
331 template <
typename To, BufferReference<To> FromBufferRef>
339 template <
typename To, BufferReference<To> FromBufferRef>
348 template <
typename To, BufferReference<To> FromBufferRef>
357 template <
typename To, BufferReference<To> FromBufferRef>
365 template <
typename To, BufferReference<To> FromBufferRef>
373 template <
typename To, BufferReference<To> FromBufferRef>
381 template <
typename To, BufferReference<To> FromBufferRef>
391 template <
typename To, BufferReference<To> FromBufferRef>
396 const double new_size =
static_cast<double>(m_buffer.size()) * m_from_to_size_ratio;
398 std::trunc(new_size) == new_size,
399 "The size of the buffer is not a multiple of the size of the new type"
404 template <
typename To, BufferReference<To> FromBufferRef>
412 template <
typename To, BufferReference<To> FromBufferRef>
417 return m_buffer.capacity() / m_to_from_size_ratio;
420 template <
typename To, BufferReference<To> FromBufferRef>
424 return m_buffer.empty();
427 template <
typename To, BufferReference<To> FromBufferRef>
432 m_buffer.reserve(new_cap * m_to_from_size_ratio);
435 template <
typename To, BufferReference<To> FromBufferRef>
440 m_buffer.shrink_to_fit();
445 template <
typename To, BufferReference<To> FromBufferRef>
453 template <
typename To, BufferReference<To> FromBufferRef>
462 const auto buffer_pos = get_buffer_reference_iterator(pos);
463 m_buffer.insert(buffer_pos, m_to_from_size_ratio, 0);
465 return std::next(
begin(), index);
468 template <
typename To, BufferReference<To> FromBufferRef>
477 const auto buffer_pos = get_buffer_reference_iterator(pos);
478 m_buffer.insert(buffer_pos, count * m_to_from_size_ratio, 0);
481 data()[
static_cast<size_t>(index) + i] = value;
483 return std::next(
begin(), index);
486 template <
typename To, BufferReference<To> FromBufferRef>
488 template <
class InputIt>
489 requires std::input_iterator<InputIt>
498 const auto buffer_pos = get_buffer_reference_iterator(pos);
499 m_buffer.insert(buffer_pos,
static_cast<size_type>(count) * m_to_from_size_ratio, 0);
500 std::copy(first, last,
data() + index);
501 return std::next(
begin(), index);
504 template <
typename To, BufferReference<To> FromBufferRef>
510 return insert(pos, ilist.begin(), ilist.end());
513 template <
typename To, BufferReference<To> FromBufferRef>
515 template <
class... Args>
523 const auto buffer_pos = get_buffer_reference_iterator(pos);
524 m_buffer.insert(buffer_pos, m_to_from_size_ratio, 0);
526 return std::next(
begin(), index);
529 template <
typename To, BufferReference<To> FromBufferRef>
542 const auto idx_for_buffer = index_for_buffer(
static_cast<size_type>(index));
546 std::next(m_buffer.cbegin(),
static_cast<difference_type>(idx_for_buffer)),
547 std::next(m_buffer.cbegin(),
static_cast<difference_type>(idx_for_buffer + m_to_from_size_ratio))
549 return std::next(
begin(), index);
552 template <
typename To, BufferReference<To> FromBufferRef>
566 const auto idx_for_buffer_first = index_for_buffer(
static_cast<size_type>(index_first));
568 const auto idx_for_buffer_last = index_for_buffer(
static_cast<size_type>(index_last));
571 std::next(m_buffer.cbegin(),
static_cast<difference_type>(idx_for_buffer_first)),
572 std::next(m_buffer.cbegin(),
static_cast<difference_type>(idx_for_buffer_last))
574 return std::next(
begin(), index_first);
577 template <
typename To, BufferReference<To> FromBufferRef>
585 template <
typename To, BufferReference<To> FromBufferRef>
593 template <
typename To, BufferReference<To> FromBufferRef>
598 const auto new_size_for_buffer =
static_cast<size_type>(
599 static_cast<double>(new_size) / m_from_to_size_ratio
601 m_buffer.resize(new_size_for_buffer);
604 template <
typename To, BufferReference<To> FromBufferRef>
610 const auto new_size_for_buffer =
static_cast<size_type>(
611 static_cast<double>(new_size) / m_from_to_size_ratio
613 m_buffer.resize(new_size_for_buffer, 0);
614 for (
size_type i = original_size; i < new_size; ++i)
620 template <
typename To,
class FromBufferRef>
623 constexpr bool is_const = std::is_const_v<FromBufferRef>;
624 using RealToType = std::conditional_t<is_const, const To, To>;
Class which have internally a reference to a contiguous container of a certain type and provides an A...
constexpr size_type capacity() const noexcept
constexpr void clear() noexcept
constexpr iterator begin() noexcept
constexpr reference front()
std::remove_cvref_t< buffer_reference >::size_type size_type
const value_type & const_reference
constexpr const_iterator cbegin() const noexcept
constexpr const_iterator cend() const noexcept
constexpr reference back()
pointer_iterator< pointer > iterator
constexpr pointer data() noexcept
static constexpr bool is_const
constexpr reverse_iterator rbegin() noexcept
buffer_adaptor(FromBufferRef buf)
pointer_iterator< const_pointer > const_iterator
constexpr void shrink_to_fit()
constexpr void push_back(const value_type &value)
constexpr size_type size() const noexcept
constexpr bool empty() const noexcept
constexpr void pop_back()
constexpr const_reverse_iterator crend() const noexcept
constexpr iterator emplace(const_iterator pos, Args &&... args)
buffer_adaptor(const FromBufferRef buf)
constexpr iterator erase(const_iterator pos)
std::remove_cvref_t< FromBufferRef >::value_type buffer_reference_value_type
constexpr reverse_iterator rend() noexcept
std::reverse_iterator< iterator > reverse_iterator
constexpr size_type max_size() const noexcept
std::conditional_t< is_const, const FromBufferRef, FromBufferRef > buffer_reference
std::remove_cvref_t< buffer_reference >::difference_type difference_type
constexpr iterator end() noexcept
constexpr const_reverse_iterator crbegin() const noexcept
constexpr void reserve(size_type new_cap)
constexpr void resize(size_type new_size)
constexpr iterator insert(const_iterator pos, const value_type &value)
constexpr reference operator[](size_type idx)
std::reverse_iterator< const_iterator > const_reverse_iterator
const value_type * const_pointer
#define SPARROW_ASSERT_TRUE(expr__)
#define SPARROW_ASSERT(expr__, message__)
auto make_buffer_adaptor(FromBufferRef &buf)