26#include <fmt/format.h>
46template <
typename Value,
typename Container = std::deque<Value>>
83 [[nodiscard]]
auto empty() const noexcept ->
bool {
176 if (max_index < current_min_index || current_max_index <
min_index) {
178 const auto next_size =
188 const auto num_added =
189 static_cast<std::size_t
>(current_min_index -
min_index);
191 }
else if (
min_index > current_min_index) {
199 const auto num_added =
200 static_cast<std::size_t
>(
max_index - current_max_index);
202 }
else if (
max_index < current_max_index) {
254 const auto result =
static_cast<std::size_t
>(index -
origin_index_);
279 fmt::format(
"Index out of range (index: {}, range: [{}, {}])",
297 bool should_resize =
false;
298 if (next_min > index) {
300 should_resize =
true;
302 if (next_max < index) {
304 should_resize =
true;
307 resize(next_min, next_max);
321 std::numeric_limits<index_type>::min() - offset;
323 return max_index() <= std::numeric_limits<index_type>::max() - offset;
Definition of assertion macros.
#define NUM_COLLECT_ASSERT(CONDITION)
Macro to check whether a condition is satisfied.
Class of exception on invalid arguments.
Class to save data in a sequence which can be extended even toward negative direction.
void throw_out_of_range(index_type index) const
Throw exception for indices out of range.
index_type origin_index_
Index of origin.
auto is_safe_offset(index_type offset) const noexcept -> bool
Check whether the given offset is safe to move.
auto at(index_type index) -> value_type &
Access a value with checks.
auto operator[](index_type index) -> value_type &
Access a value without checks.
bidirectional_vector()=default
Constructor.
auto operator[](index_type index) const -> const value_type &
Access a value without checks.
void resize(index_type min_index, index_type max_index, const value_type &value=value_type())
Change the position of this object.
container_type container_
Internal container.
auto max_index() const noexcept -> index_type
Get the maximum index.
auto container() const noexcept -> const container_type &
Get the internal container.
bidirectional_vector(container_type container, index_type origin_index)
Constructor.
auto min_index() const noexcept -> index_type
Get the minimum index. (Equal to the index of the origin.)
auto get_or_prepare(index_type index) -> value_type &
Access a value preparing it if needed.
void prepare_for(index_type index)
Prepare space for an index.
auto at(index_type index) const -> const value_type &
Access a value with checks.
Value value_type
Type of values.
Container container_type
Type of the internal container.
auto empty() const noexcept -> bool
Check whether this object is empty.
void push_front(const value_type &value)
Add a value to the beginning.
auto unsafe_container_index(index_type index) const noexcept -> std::size_t
Calculate the index in the container without checks.
auto container_index(index_type index) const -> std::size_t
Calculate the index in the container with checks.
void push_back(const value_type &value)
Add a value to the end.
void move_position(index_type offset)
Move the position of this object.
Definition of exceptions.
Definition of index_type type.
Definition of macros for logging.
#define NUM_COLLECT_LOG_AND_THROW(EXCEPTION_TYPE,...)
Write an error log and throw an exception for an error.
std::ptrdiff_t index_type
Type of indices in this library.