Pixie
Loading...
Searching...
No Matches
permutable_sequence.h
Go to the documentation of this file.
1#pragma once
2
8
10
11#include <concepts>
12#include <cstddef>
13#include <ranges>
14#include <utility>
15
16namespace pixie {
23enum class ElementStorage { automatic, packed, indirect };
24
50template <class Impl, class T, class ConstReference>
51 requires(std::same_as<ConstReference, T> ||
52 std::same_as<ConstReference, const T&>)
54 public:
56 using value_type = T;
58 using const_reference = ConstReference;
60 using size_type = std::size_t;
76 template <std::ranges::input_range Range>
77 requires std::
78 constructible_from<T, std::ranges::range_rvalue_reference_t<Range>>
79 static Impl from_range(Range&& range) {
80 return Impl::from_range_impl(std::forward<Range>(range));
81 }
82
87 size_type size() const noexcept { return impl().size_impl(); }
93 bool empty() const noexcept { return size() == 0; }
106 return impl().value_at_impl(position);
107 }
108
121 void insert_at(size_type position, T value) {
122 impl().insert_at_impl(position, std::move(value));
123 }
124
136 void rotate_left(size_type left, size_type right, size_type distance) {
137 impl().rotate_left_impl(left, right, distance);
138 }
139
151 void merge(Impl& donor) { impl().merge_impl(donor); }
162 size_type memory_usage_bytes() const noexcept {
163 return impl().memory_usage_bytes_impl();
164 }
165
166 private:
167 Impl& impl() noexcept { return static_cast<Impl&>(*this); }
168 const Impl& impl() const noexcept { return static_cast<const Impl&>(*this); }
169};
170} // namespace pixie
CRTP contract for exclusively owned sequences with immutable reads.
Definition permutable_sequence.h:53
T value_type
Stored element type.
Definition permutable_sequence.h:56
size_type memory_usage_bytes() const noexcept
Explicitly account for requested live storage.
Definition permutable_sequence.h:162
void rotate_left(size_type left, size_type right, size_type distance)
Rotate [left,right) left while preserving outside values.
Definition permutable_sequence.h:136
bool empty() const noexcept
Test emptiness.
Definition permutable_sequence.h:93
void merge(Impl &donor)
Append unchanged donor values and consume donor ownership.
Definition permutable_sequence.h:151
size_type size() const noexcept
Return the logical element count.
Definition permutable_sequence.h:87
ConstReference const_reference
Immutable result type.
Definition permutable_sequence.h:58
static Impl from_range(Range &&range)
Consume a possibly single-pass input range into an owning sequence.
Definition permutable_sequence.h:79
const_reference operator[](size_type position) const
Read a checked zero-based element without exposing mutation.
Definition permutable_sequence.h:105
std::size_t size_type
Count and position type.
Definition permutable_sequence.h:60
void insert_at(size_type position, T value)
Insert one value at a zero-based position.
Definition permutable_sequence.h:121
ElementStorage
Compile-time element storage selection.
Definition permutable_sequence.h:23
Shared compile-time sequence tuning options.