36void throwVectorIndexOutOfRange(std::uintmax_t requestedIndex, std::uintmax_t actualSize);
40void throwVectorCopyOverflowImpl(std::uintmax_t targetCapacity, std::uintmax_t sourceItemCount);
66template <
typename ItemType,
typename SizeType>
69 static_assert(std::is_nothrow_destructible<ItemType>::value,
"ItemType must be nothrow-destructible");
71 static_assert(std::is_integral<SizeType>::value,
"SizeType must be integral");
72 static_assert(std::is_unsigned<SizeType>::value,
"SizeType must be unsigned");
73 static_assert(!std::is_same<SizeType, bool>::value,
"SizeType must not be bool");
158 return (size_ == 0) ? items_ : (items_ + size_);
166 return (size_ == 0) ? items_ : (items_ + size_);
201 assert(index < size_);
203 return items_[index];
214 assert(index < size_);
216 return items_[index];
226 if ONIXS_CMEMDH_LIKELY(index < size_)
227 return items_[index];
229 details::throwVectorIndexOutOfRange(
static_cast<std::uintmax_t
>(index),
static_cast<std::uintmax_t
>(size_));
239 if ONIXS_CMEMDH_LIKELY(index < size_)
240 return items_[index];
242 details::throwVectorIndexOutOfRange(
static_cast<std::uintmax_t
>(index),
static_cast<std::uintmax_t
>(size_));
257 static_assert(std::is_nothrow_copy_constructible<Item>::value,
"Item must be nothrow-copy-constructible");
259 assert(index < size_);
261 Item*
const toBeUpdated = items_ + index;
263 Item* target = items_ + size_ - 1;
265 while (target != toBeUpdated)
269 new (target)
Item(*(target - 1));
284 static_assert(std::is_nothrow_move_constructible<Item>::value,
"Item must be nothrow-move-constructible");
286 assert(index < size_);
289 Item*
const toBeErased = items_ + index;
291 Item* target = toBeErased;
292 Item* source = toBeErased + 1;
294 while (source != theEnd)
298 new (target)
Item(std::move(*source));
330 static_assert(std::is_default_constructible<Item>::value,
"Item must be default-constructible");
331 static_assert(std::is_copy_constructible<Item>::value,
"Item must be copy-constructible");
333 assert(newSize <= capacity_);
336 growTo(newSize,
Item {});
355 static_assert(std::is_copy_constructible<Item>::value,
"Item must be copy-constructible");
357 assert(newSize <= capacity_);
360 growTo(newSize, item);
366 void growTo(Size newSize,
const Item& item)
368 while (size_ < newSize)
370 new (items_ + size_) Item(item);
375 void shrinkTo(Size newSize)
noexcept
377 while (size_ > newSize)
378 (items_ + --size_)->~Item();
381 Item* items_ =
nullptr;
384 const Size capacity_ = 0;
386 VectorOverArray(
const VectorOverArray&) =
delete;
387 VectorOverArray& operator=(
const VectorOverArray&) =
delete;
388 VectorOverArray(VectorOverArray&&) =
delete;
389 VectorOverArray& operator=(VectorOverArray&&) =
delete;
398template <
typename TargetSize,
typename SourceSize>
401 details::throwVectorCopyOverflowImpl(
static_cast<std::uintmax_t
>(targetCapacity),
static_cast<std::uintmax_t
>(sourceItemCount));
420template <
typename TargetItem,
typename TargetSize,
typename SourceItem,
typename SourceSize,
typename ItemCount>
423 static_assert(std::is_assignable<TargetItem&, const SourceItem&>::value,
"TargetItem must be assignable from the SourceItem");
425 std::uintmax_t remainingCount =
static_cast<std::uintmax_t
>(itemCount);
426 const std::uintmax_t sourceSize =
static_cast<std::uintmax_t
>(source.
size());
427 remainingCount = (remainingCount > sourceSize) ? sourceSize : remainingCount;
429 if ONIXS_CMEMDH_UNLIKELY(remainingCount >
static_cast<std::uintmax_t
>(target.
capacity()))
432 target.
resize(
static_cast<TargetSize
>(remainingCount));
434 while (remainingCount)
438 target[
static_cast<TargetSize
>(remainingCount)] = source[
static_cast<SourceSize
>(remainingCount)];
445template <
typename TargetItem,
typename TargetSize,
typename SourceItem,
typename SourceSize>
448 copy(target, source, source.
size());
#define ONIXS_CMEMDH_NAMESPACE_BEGIN
#define ONIXS_CMEMDH_NAMESPACE_END
#define ONIXS_CMEMDH_COLDPATH
#define ONIXS_CMEMDH_EXPORTED
#define ONIXS_CMEMDH_NORETURN
#define ONIXS_CMEMDH_NODISCARD
Provides vector-like access to caller-owned, fixed-capacity storage.
~VectorOverArray() noexcept
Destroys all active items without deallocating the backing storage.
VectorOverArray() noexcept=default
Creates an empty container without backing storage.
void resize(Size newSize)
Changes the number of active items within the fixed capacity.
Item & insertExtrude(Size index) noexcept
Opens a position by shifting subsequent items toward the end.
bool empty() const noexcept
Checks whether the container has no active items.
ConstIterator begin() const noexcept
Obtains a read-only iterator to the first item.
void erase(Size index) noexcept
Erases an item and shifts subsequent items toward the beginning.
Iterator begin() noexcept
Obtains a mutable iterator to the first item.
Item & at(Size index)
Accesses an active item with bounds checking.
Size size() const noexcept
Obtains the number of active items.
Size capacity() const noexcept
const Item & operator[](Size index) const noexcept
Accesses an active item without runtime bounds checking.
const Item & front() const noexcept
Accesses the first active item.
void resize(Size newSize, const Item &item)
Changes the number of active items within the fixed capacity.
ConstIterator end() const noexcept
Obtains a read-only iterator past the last active item.
const Item * ConstIterator
Item & operator[](Size index) noexcept
Accesses an active item without runtime bounds checking.
Iterator end() noexcept
Obtains a mutable iterator past the last active item.
Item & front() noexcept
Accesses the first active item.
const Item & at(Size index) const
Accesses an active item with bounds checking.
MboBook & copy(MboBook &target, const MboBook &source)
Copies content of MBO book to the other one.
void throwVectorCopyOverflow(TargetSize targetCapacity, SourceSize sourceItemCount)
Reports that a source range does not fit in a target container.