17#include <initializer_list>
25#if COMMS_IS_GCC_12 && defined(NDEBUG)
29COMMS_GNU_WARNING_DISABLE(
"-Warray-bounds")
32COMMS_MSVC_WARNING_PUSH
33COMMS_MSVC_WARNING_DISABLE(4324)
49 using size_type = std::size_t;
51 using const_reference =
const T&;
53 using const_pointer =
const T*;
54 using iterator = pointer;
55 using const_iterator = const_pointer;
56 using reverse_iterator = std::reverse_iterator<iterator>;
57 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
58 using CellType = comms::util::AlignedStorage<
sizeof(T), std::alignment_of<T>::value>;
60 static_assert(
sizeof(CellType) ==
sizeof(T),
"Type T must be padded");
62 StaticVectorBase(CellType* dataPtr, std::size_t cap)
68 ~StaticVectorBase() noexcept
73 StaticVectorBase(
const StaticVectorBase&) =
delete;
74 StaticVectorBase& operator=(
const StaticVectorBase&) =
delete;
77 std::size_t size()
const
82 std::size_t capacity()
const
94 COMMS_MSVC_WARNING_SUPPRESS(4189)
95 auto& lastElem = back();
103 return elem(size() - 1);
106 const T& back()
const
109 return elem(size() - 1);
118 const T& front()
const
124 template <
typename TIter>
125 void assign(TIter from, TIter to)
128 for (
auto iter = from; iter != to; ++iter) {
129 if (capacity() <= size()) {
130 static constexpr bool Not_all_elements_are_copied =
false;
131 static_cast<void>(Not_all_elements_are_copied);
136 new (cellPtr(size())) T(*(
reinterpret_cast<const T*
>(&*iter)));
141 void fill(std::size_t count,
const T& value)
145 for (
auto idx = 0U; idx < count; ++idx) {
146 new (cellPtr(idx)) T(value);
152 for (
auto idx = 0U; idx < size(); ++idx) {
168 const T* begin()
const
173 const T* cbegin()
const
184 return begin() + size();
192 const T* cend()
const
194 return cbegin() + size();
197 T& at(std::size_t pos)
203 const T& at(std::size_t pos)
const
209 T& operator[](std::size_t pos)
214 const T& operator[](std::size_t pos)
const
228 const T* data()
const
237 template <
typename U>
238 T* insert(
const T* pos, U&& value)
243 push_back(std::forward<U>(value));
248 push_back(std::move(back()));
249 auto* insertIter = begin() + std::distance(cbegin(), pos);
250 std::move_backward(insertIter, end() - 2, end() - 1);
251 *insertIter = std::forward<U>(value);
255 T* insert(
const T* pos, std::size_t count,
const T& value)
259 auto dist = std::distance(cbegin(), pos);
260 COMMS_ASSERT((0 <= dist) &&
static_cast<std::size_t
>(dist) < size());
261 auto* posIter = begin() + dist;
262 if (end() <= posIter) {
271 auto tailCount =
static_cast<std::size_t
>(std::distance(posIter, end()));
272 if (count <= tailCount) {
273 auto pushBegIter = end() - count;
274 auto pushEndIter = end();
275 for (
auto iter = pushBegIter; iter != pushEndIter; ++iter) {
276 push_back(std::move(*iter));
279 auto moveBegIter = posIter;
280 auto moveEndIter = moveBegIter + (tailCount - count);
283 COMMS_GNU_WARNING_PUSH
284#if COMMS_IS_GCC_12 && defined(NDEBUG)
287 COMMS_GNU_WARNING_DISABLE(
"-Wstringop-overflow")
289 std::move_backward(moveBegIter, moveEndIter, pushEndIter);
290 COMMS_GNU_WARNING_POP
292 auto* assignBegIter = posIter;
293 auto* assignEndIter = assignBegIter + count;
294 for (
auto iter = assignBegIter; iter != assignEndIter; ++iter) {
300 auto pushValueCount = count - tailCount;
301 for (
auto idx = 0U; idx < pushValueCount; ++idx) {
305 auto* pushBegIter = posIter;
306 auto* pushEndIter = pushBegIter + tailCount;
307 for (
auto iter = pushBegIter; iter != pushEndIter; ++iter) {
308 push_back(std::move(*iter));
311 auto assignBegIter = posIter;
312 auto assignEndIter = assignBegIter + tailCount;
313 for (
auto iter = assignBegIter; iter != assignEndIter; ++iter) {
319 template <
typename TIter>
320 T* insert(
const T* pos, TIter from, TIter to)
322 using Tag =
typename std::iterator_traits<TIter>::iterator_category;
323 return insert_internal(pos, from, to, Tag());
326 template <
typename... TArgs>
327 T* emplace(
const T* iter, TArgs&&... args)
329 auto* insertIter = begin() + std::distance(cbegin(), iter);
330 if (iter == cend()) {
331 emplace_back(std::forward<TArgs>(args)...);
336 push_back(std::move(back()));
337 std::move_backward(insertIter, end() - 2, end() - 1);
339 new (insertIter) T(std::forward<TArgs>(args)...);
343 T* erase(
const T* from,
const T* to)
349 auto tailCount =
static_cast<std::size_t
>(std::distance(to, cend()));
350 auto eraseCount =
static_cast<std::size_t
>(std::distance(from, to));
352 auto* moveSrc = begin() + std::distance(cbegin(), to);
353 auto* moveDest = begin() + std::distance(cbegin(), from);
354 std::move(moveSrc, end(), moveDest);
356 auto* eraseFrom = moveDest + tailCount;
357 auto* eraseTo = end();
360 COMMS_ASSERT(
static_cast<std::size_t
>(std::distance(eraseFrom, eraseTo)) == eraseCount);
361 for (
auto iter = eraseFrom; iter != eraseTo; ++iter) {
368 template <
typename U>
369 void push_back(U&& value)
372 new (cellPtr(size())) T(std::forward<U>(value));
376 template <
typename... TArgs>
377 void emplace_back(TArgs&&... args)
380 new (cellPtr(size())) T(std::forward<TArgs>(args)...);
384 void resize(std::size_t count,
const T& value)
386 if (count < size()) {
387 erase(begin() + count, end());
392 while (size() < count) {
397 void swap(StaticVectorBase<T>& other)
399 auto swapSize = std::min(other.size(), size());
400 for (
auto idx = 0U; idx < swapSize; ++idx) {
401 std::swap(this->
operator[](idx), other[idx]);
404 auto otherSize = other.size();
405 auto thisSize = size();
407 if (otherSize == thisSize) {
411 if (otherSize < thisSize) {
412 auto limit = std::min(thisSize, other.capacity());
413 for (
auto idx = swapSize; idx < limit; ++idx) {
414 new (other.cellPtr(idx)) T(std::move(elem(idx)));
417 other.size_ = thisSize;
418 erase(begin() + otherSize, end());
422 auto limit = std::min(otherSize, capacity());
423 for (
auto idx = swapSize; idx < limit; ++idx) {
424 new (cellPtr(idx)) T(std::move(other.elem(idx)));
427 other.erase(other.begin() + thisSize, other.end());
431 CellType& cell(std::size_t idx)
437 const CellType& cell(std::size_t idx)
const
443 CellType* cellPtr(std::size_t idx)
449 T& elem(std::size_t idx)
451 return reinterpret_cast<T&
>(cell(idx));
454 const T& elem(std::size_t idx)
const
456 return reinterpret_cast<const T&
>(cell(idx));
459 template <
typename TIter>
460 T* insert_random_access(
const T* pos, TIter from, TIter to)
463 auto* posIter = begin() + std::distance(cbegin(), pos);
464 if (end() <= posIter) {
465 for (; from != to; ++from) {
472 auto count =
static_cast<std::size_t
>(std::distance(from, to));
474 auto tailCount =
static_cast<std::size_t
>(std::distance(posIter, end()));
475 if (count <= tailCount) {
476 auto pushBegIter = end() - count;
477 auto pushEndIter = end();
478 for (
auto iter = pushBegIter; iter != pushEndIter; ++iter) {
479 push_back(std::move(*iter));
482 auto moveBegIter = posIter;
483 auto moveEndIter = moveBegIter + (tailCount - count);
485 std::move_backward(moveBegIter, moveEndIter, pushEndIter);
487 auto* assignBegIter = posIter;
488 auto* assignEndIter = assignBegIter + count;
489 for (
auto iter = assignBegIter; iter != assignEndIter; ++iter) {
496 auto pushValueCount = count - tailCount;
497 auto pushInsertedBegIter = to - pushValueCount;
498 for (
auto idx = 0U; idx < pushValueCount; ++idx) {
499 push_back(*pushInsertedBegIter);
500 ++pushInsertedBegIter;
503 auto* pushBegIter = posIter;
504 auto* pushEndIter = pushBegIter + tailCount;
505 for (
auto iter = pushBegIter; iter != pushEndIter; ++iter) {
506 push_back(std::move(*iter));
509 auto assignBegIter = posIter;
510 auto assignEndIter = assignBegIter + tailCount;
511 for (
auto iter = assignBegIter; iter != assignEndIter; ++iter) {
519 template <
typename TIter>
520 T* insert_input(
const T* pos, TIter from, TIter to)
523 for (; from != to; ++from) {
524 if (ret ==
nullptr) {
525 ret = begin() + std::distance(cbegin(), pos);
533 template <
typename TIter>
534 T* insert_internal(
const T* pos, TIter from, TIter to, std::random_access_iterator_tag)
536 return insert_random_access(pos, from, to);
539 template <
typename TIter>
540 T* insert_internal(
const T* pos, TIter from, TIter to, std::input_iterator_tag)
542 return insert_input(pos, from, to);
546 CellType* data_ =
nullptr;
547 std::size_t capacity_ = 0;
548 std::size_t size_ = 0;
551template <
typename T, std::
size_t TSize>
552struct StaticVectorStorageBase
554 using ElementType = comms::util::AlignedStorage<
sizeof(T), std::alignment_of<T>::value>;
555 using StorageType = std::array<ElementType, TSize>;
556 alignas(
alignof(T)) StorageType data_;
559template <
typename T, std::
size_t TSize>
560class StaticVectorGeneric :
561 public StaticVectorStorageBase<T, TSize>,
562 public StaticVectorBase<T>
564 using StorageBase = StaticVectorStorageBase<T, TSize>;
565 using Base = StaticVectorBase<T>;
568 using value_type =
typename Base::value_type;
569 using size_type =
typename Base::size_type;
570 using difference_type =
typename StorageBase::StorageType::difference_type;
571 using reference =
typename Base::reference;
572 using const_reference =
typename Base::const_reference;
573 using pointer =
typename Base::pointer;
574 using const_pointer =
typename Base::const_pointer;
575 using iterator =
typename Base::iterator;
576 using const_iterator =
typename Base::const_iterator;
577 using reverse_iterator =
typename Base::reverse_iterator;
578 using const_reverse_iterator =
typename Base::const_reverse_iterator;
580 StaticVectorGeneric()
581 : Base(StorageBase::data_.data(), StorageBase::data_.size())
585 StaticVectorGeneric(size_type count,
const T& value)
586 : Base(StorageBase::data_.data(), StorageBase::data_.size())
591 explicit StaticVectorGeneric(size_type count)
592 : Base(StorageBase::data_.data(), StorageBase::data_.size())
596 Base::emplace_back();
601 template <
typename TIter>
602 StaticVectorGeneric(TIter from, TIter to)
603 : Base(StorageBase::data_.data(), StorageBase::data_.size())
608 template <std::
size_t TOtherSize>
609 StaticVectorGeneric(
const StaticVectorGeneric<T, TOtherSize>& other)
610 : Base(StorageBase::data_.data(), StorageBase::data_.size())
612 assign(other.begin(), other.end());
615 StaticVectorGeneric(
const StaticVectorGeneric& other)
616 : Base(StorageBase::data_.data(), StorageBase::data_.size())
618 assign(other.begin(), other.end());
621 StaticVectorGeneric(std::initializer_list<value_type> init)
622 : Base(StorageBase::data_.data(), StorageBase::data_.size())
624 assign(init.begin(), init.end());
627 ~StaticVectorGeneric() noexcept = default;
629 StaticVectorGeneric& operator=(const StaticVectorGeneric& other)
631 if (&other ==
this) {
635 assign(other.begin(), other.end());
639 template <std::
size_t TOtherSize>
640 StaticVectorGeneric& operator=(
const StaticVectorGeneric<T, TOtherSize>& other)
642 assign(other.cbegin(), other.cend());
646 StaticVectorGeneric& operator=(std::initializer_list<value_type> init)
652 void assign(size_type count,
const T& value)
655 Base::fill(count, value);
658 template <
typename TIter>
659 void assign(TIter from, TIter to)
661 Base::assign(from, to);
664 void assign(std::initializer_list<value_type> init)
666 assign(init.begin(), init.end());
669 void reserve(size_type new_cap)
671 static_cast<void>(new_cap);
676template <
typename TOrig,
typename TCast, std::
size_t TSize>
677class StaticVectorCasted :
public StaticVectorGeneric<TCast, TSize>
679 using Base = StaticVectorGeneric<TCast, TSize>;
680 static_assert(
sizeof(TOrig) ==
sizeof(TCast),
"The sizes are not equal");
683 using value_type = TOrig;
684 using size_type =
typename Base::size_type;
685 using difference_type =
typename Base::difference_type;
686 using reference = value_type&;
687 using const_reference =
const value_type&;
688 using pointer = value_type*;
689 using const_pointer =
const value_type*;
690 using iterator = pointer;
691 using const_iterator = const_pointer;
693 StaticVectorCasted() =
default;
695 StaticVectorCasted(size_type count, const_reference& value)
696 : Base(count, *(reinterpret_cast<typename Base::const_pointer>(&value)))
700 explicit StaticVectorCasted(size_type count)
705 template <
typename TIter>
706 StaticVectorCasted(TIter from, TIter to)
711 template <std::
size_t TOtherSize>
712 StaticVectorCasted(
const StaticVectorCasted<TOrig, TCast, TOtherSize>& other)
717 StaticVectorCasted(
const StaticVectorCasted& other)
722 StaticVectorCasted(std::initializer_list<value_type> init)
723 : Base(init.begin(), init.end())
727 ~StaticVectorCasted() noexcept = default;
729 StaticVectorCasted& operator=(const StaticVectorCasted&) = default;
731 template <
std::
size_t TOtherSize>
732 StaticVectorCasted& operator=(const StaticVectorCasted<TOrig, TCast, TOtherSize>& other)
734 Base::operator=(other);
738 StaticVectorCasted& operator=(std::initializer_list<value_type> init)
740 Base::operator=(init);
744 void assign(size_type count, const_reference& value)
746 Base::assign(count, value);
749 template <
typename TIter>
750 void assign(TIter from, TIter to)
752 Base::assign(from, to);
755 void assign(std::initializer_list<value_type> init)
757 assign(init.begin(), init.end());
760 reference at(size_type pos)
762 return *(
reinterpret_cast<pointer
>(&(Base::at(pos))));
765 const_reference at(size_type pos)
const
767 return *(
reinterpret_cast<const_pointer
>(&(Base::at(pos))));
770 reference operator[](size_type pos)
772 return *(
reinterpret_cast<pointer
>(&(Base::operator[](pos))));
775 const_reference operator[](size_type pos)
const
777 return *(
reinterpret_cast<const_pointer
>(&(Base::operator[](pos))));
782 return *(
reinterpret_cast<pointer
>(&(Base::front())));
785 const_reference front()
const
787 return *(
reinterpret_cast<const_pointer
>(&(Base::front())));
792 return *(
reinterpret_cast<pointer
>(&(Base::back())));
795 const_reference back()
const
797 return *(
reinterpret_cast<const_pointer
>(&(Base::back())));
802 return reinterpret_cast<pointer
>(Base::data());
805 const_pointer data()
const
807 return reinterpret_cast<const_pointer
>(Base::data());
812 return reinterpret_cast<iterator
>(Base::begin());
815 const_iterator begin()
const
820 const_iterator cbegin()
const
822 return reinterpret_cast<const_iterator
>(Base::cbegin());
827 return reinterpret_cast<iterator
>(Base::end());
830 const_iterator end()
const
835 const_iterator cend()
const
837 return reinterpret_cast<const_iterator
>(Base::cend());
840 iterator insert(const_iterator iter, const_reference value)
843 reinterpret_cast<iterator
>(
845 reinterpret_cast<typename Base::const_iterator
>(iter),
846 *(
reinterpret_cast<typename Base::const_pointer
>(&value))));
849 iterator insert(const_iterator iter, TCast&& value)
852 reinterpret_cast<iterator
>(
854 reinterpret_cast<typename Base::const_iterator
>(iter),
855 std::move(*(
reinterpret_cast<typename Base::pointer
>(&value)))));
858 iterator insert(const_iterator iter, size_type count, const_reference value)
861 reinterpret_cast<iterator
>(
863 reinterpret_cast<typename Base::const_iterator
>(iter),
865 *(
reinterpret_cast<typename Base::const_pointer
>(&value))));
868 template <
typename TIter>
869 iterator insert(const_iterator iter, TIter from, TIter to)
872 reinterpret_cast<iterator
>(
874 reinterpret_cast<typename Base::const_iterator
>(iter),
879 iterator insert(const_iterator iter, std::initializer_list<value_type> init)
882 reinterpret_cast<iterator
>(
884 reinterpret_cast<typename Base::const_iterator
>(iter),
889 template <
typename... TArgs>
890 iterator emplace(const_iterator iter, TArgs&&... args)
893 reinterpret_cast<iterator
>(
895 reinterpret_cast<typename Base::const_iterator
>(iter),
896 std::forward<TArgs>(args)...));
899 iterator erase(const_iterator iter)
901 return erase(iter, iter + 1);
906 iterator erase(const_iterator from, const_iterator to)
909 reinterpret_cast<iterator
>(
911 reinterpret_cast<typename Base::const_iterator
>(from),
912 reinterpret_cast<typename Base::const_iterator
>(to)));
915 void push_back(const_reference value)
917 Base::push_back(*(
reinterpret_cast<typename Base::const_pointer
>(&value)));
920 void push_back(TCast&& value)
922 Base::push_back(std::move(*(
reinterpret_cast<TCast*
>(&value))));
926template <
bool TSignedIntegral>
927struct StaticVectorBaseSignedIntegral;
930struct StaticVectorBaseSignedIntegral<true>
932 template <
typename T, std::
size_t TSize>
933 using Type = StaticVectorCasted<T, typename std::make_unsigned<T>::type, TSize>;
937struct StaticVectorBaseSignedIntegral<false>
939 template <
typename T, std::
size_t TSize>
940 using Type = StaticVectorGeneric<T, TSize>;
943template <
typename T, std::
size_t TSize>
944using ChooseStaticVectorBase =
945 typename StaticVectorBaseSignedIntegral<std::is_integral<T>::value && std::is_signed<T>::value>::template Type<T, TSize>;
958template <
typename T, std::
size_t TSize>
961 using Base = details::ChooseStaticVectorBase<T, TSize>;
962 using ElementType =
typename Base::ElementType;
964 static_assert(
sizeof(T) ==
sizeof(ElementType),
965 "Sizes are not equal as expected.");
967 template <
typename U, std::
size_t TOtherSize>
1010 : Base(count, value)
1023 template <
typename TIter>
1031 template <std::
size_t TOtherSize>
1060 template <
std::
size_t TOtherSize>
1063 Base::operator=(other);
1071 Base::operator=(init);
1079 Base::assign(count, value);
1084 template <
typename TIter>
1087 Base::assign(from, to);
1092 void assign(std::initializer_list<value_type> init)
1094 assign(init.begin(), init.end());
1105 return Base::at(pos);
1115 return Base::at(pos);
1122 return Base::operator[](pos);
1129 return Base::operator[](pos);
1137 return Base::front();
1145 return Base::front();
1153 return Base::back();
1161 return Base::back();
1168 return Base::data();
1175 return Base::data();
1182 return Base::begin();
1196 return Base::cbegin();
1217 return Base::cend();
1266 return Base::empty();
1273 return Base::size();
1290 return Base::reserve(new_cap);
1299 return Base::capacity();
1320 return Base::insert(iter, value);
1327 return Base::insert(iter, std::move(value));
1334 return Base::insert(iter, count, value);
1339 template <
typename TIter>
1342 return Base::insert(iter, from, to);
1349 return Base::insert(iter, init.begin(), init.end());
1354 template <
typename... TArgs>
1357 return Base::emplace(iter, std::forward<TArgs>(args)...);
1364 return erase(iter, iter + 1);
1371 return Base::erase(from, to);
1379 Base::push_back(value);
1387 Base::push_back(std::move(value));
1393 template <
typename... TArgs>
1396 Base::emplace_back(std::forward<TArgs>(args)...);
1420 Base::resize(count, value);
1426 template <std::
size_t TOtherSize>
1434template <
typename T>
1435class StaticVector<T, 0U>
1437 using StorageType = std::array<T, 0U>;
1439 template <
typename U, std::
size_t TOtherSize>
1440 friend class StaticVector;
1443 using value_type =
typename StorageType::value_type;
1444 using size_type =
typename StorageType::size_type;
1445 using difference_type =
typename StorageType::difference_type;
1446 using reference =
typename StorageType::reference;
1447 using const_reference =
typename StorageType::const_reference;
1448 using pointer =
typename StorageType::pointer;
1449 using const_pointer =
typename StorageType::const_pointer;
1450 using iterator =
typename StorageType::iterator;
1451 using const_iterator =
typename StorageType::const_iterator;
1452 using reverse_iterator =
typename StorageType::reverse_iterator;
1453 using const_reverse_iterator =
typename StorageType::const_reverse_iterator;
1455 StaticVector() =
default;
1457 StaticVector(size_type count,
const T& value)
1459 static_cast<void>(value);
1464 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1465 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1466 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1469 explicit StaticVector(size_type count)
1475 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1476 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1477 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1480 template <
typename TIter>
1481 StaticVector(TIter from, TIter to)
1487 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1488 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1489 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1492 template <std::
size_t TOtherSize>
1493 StaticVector(
const StaticVector<T, TOtherSize>& other)
1495 static_cast<void>(other);
1496 if (TOtherSize == 0U) {
1500 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1501 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1502 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1505 StaticVector(
const StaticVector& other)
1507 static_cast<void>(other);
1510 StaticVector(std::initializer_list<value_type> init)
1512 if (std::begin(init) == std::end(init)) {
1516 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1517 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1518 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1521 ~StaticVector() noexcept = default;
1523 StaticVector& operator=(const StaticVector&) = default;
1525 template <
std::
size_t TOtherSize>
1526 StaticVector& operator=(const StaticVector<T, TOtherSize>& other)
1528 static_cast<void>(other);
1529 if (TOtherSize == 0U) {
1533 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1534 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1535 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1539 StaticVector& operator=(std::initializer_list<value_type> init)
1541 if (std::begin(init) == std::end(init)) {
1545 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1546 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1547 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1551 void assign(size_type count,
const T& value)
1553 static_cast<void>(value);
1558 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1559 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1560 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1563 template <
typename TIter>
1564 void assign(TIter from, TIter to)
1570 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1571 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1572 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1575 void assign(std::initializer_list<value_type> init)
1577 if (std::begin(init) == std::end(init)) {
1581 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1582 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1583 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1586 reference at(size_type pos)
1588 static_cast<void>(pos);
1589 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1590 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1591 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1595 const_reference at(size_type pos)
const
1597 static_cast<void>(pos);
1598 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1599 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1600 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1604 reference operator[](size_type pos)
1606 static_cast<void>(pos);
1607 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1608 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1609 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1613 const_reference operator[](size_type pos)
const
1615 static_cast<void>(pos);
1616 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1617 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1618 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1624 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1625 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1626 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1627 return m_data.front();
1630 const_reference front()
const
1632 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1633 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1634 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1635 return m_data.front();
1640 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1641 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1642 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1643 return m_data.back();
1646 const_reference back()
const
1648 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1649 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1650 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1651 return m_data.back();
1656 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1657 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1658 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1659 return m_data.data();
1662 const_pointer data()
const
1664 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1665 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1666 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1667 return m_data.data();
1672 return m_data.begin();
1675 const_iterator begin()
const
1677 return m_data.begin();
1680 const_iterator cbegin()
const
1682 return m_data.cbegin();
1687 return m_data.end();
1690 const_iterator end()
const
1692 return m_data.end();
1695 const_iterator cend()
const
1697 return m_data.cend();
1700 reverse_iterator rbegin()
1702 return m_data.rbegin();
1705 const_reverse_iterator rbegin()
const
1707 return m_data.rbegin();
1710 const_reverse_iterator crbegin()
const
1712 return m_data.crbegin();
1715 reverse_iterator rend()
1717 return m_data.rend();
1720 const_reverse_iterator rend()
const
1722 return m_data.rend();
1725 const_reverse_iterator crend()
const
1727 return m_data.crend();
1732 return m_data.empty();
1735 size_type size()
const
1737 return m_data.size();
1740 size_type max_size()
const
1742 return m_data.max_size();
1745 void reserve(size_type new_cap)
1747 static_cast<void>(new_cap);
1748 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1749 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1750 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1753 size_type capacity()
const
1758 void shrink_to_fit()
1766 iterator insert(const_iterator iter,
const T& value)
1768 static_cast<void>(iter);
1769 static_cast<void>(value);
1770 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1771 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1772 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1773 return m_data.end();
1776 iterator insert(const_iterator iter, T&& value)
1778 static_cast<void>(iter);
1779 static_cast<void>(value);
1780 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1781 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1782 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1783 return m_data.end();
1786 iterator insert(const_iterator iter, size_type count,
const T& value)
1788 static_cast<void>(iter);
1789 static_cast<void>(count);
1790 static_cast<void>(value);
1791 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1792 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1793 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1794 return m_data.end();
1797 template <
typename TIter>
1798 iterator insert(const_iterator iter, TIter from, TIter to)
1800 static_cast<void>(iter);
1801 static_cast<void>(from);
1802 static_cast<void>(to);
1803 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1804 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1805 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1806 return m_data.end();
1809 iterator insert(const_iterator iter, std::initializer_list<value_type> init)
1811 static_cast<void>(iter);
1812 static_cast<void>(init);
1813 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1814 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1815 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1816 return m_data.end();
1819 template <
typename... TArgs>
1820 iterator emplace(const_iterator iter, TArgs&&...)
1822 static_cast<void>(iter);
1823 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1824 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1825 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1826 return m_data.end();
1829 iterator erase(const_iterator iter)
1831 static_cast<void>(iter);
1832 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1833 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1834 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1835 return m_data.end();
1838 iterator erase(const_iterator from, const_iterator to)
1841 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1842 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1843 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1845 return m_data.end();
1848 void push_back(
const T& value)
1850 static_cast<void>(value);
1851 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1852 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1853 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1856 void push_back(T&& value)
1858 static_cast<void>(value);
1859 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1860 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1861 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1864 template <
typename... TArgs>
1865 void emplace_back(TArgs&&...)
1867 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1868 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1869 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1874 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1875 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1876 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1879 void resize(size_type count)
1885 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1886 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1887 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1890 void resize(size_type count,
const value_type& value)
1892 static_cast<void>(value);
1897 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1898 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1899 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1902 template <std::
size_t TOtherSize>
1903 void swap(StaticVector<T, TOtherSize>& other)
1905 static_cast<void>(other);
1906 if (TOtherSize != 0U) {
1907 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1908 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1909 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1920template <
typename T, std::
size_t TSize1, std::
size_t TSize2>
1923 return std::lexicographical_compare(v1.begin(), v1.end(), v2.begin(), v2.end());
1929template <
typename T, std::
size_t TSize1, std::
size_t TSize2>
1938template <
typename T, std::
size_t TSize1, std::
size_t TSize2>
1947template <
typename T, std::
size_t TSize1, std::
size_t TSize2>
1956template <
typename T, std::
size_t TSize1, std::
size_t TSize2>
1959 return (v1.size() == v2.size()) &&
1967template <
typename T, std::
size_t TSize1, std::
size_t TSize2>
1977template <
typename T>
1978struct IsStaticVector
1980 static const bool Value =
false;
1983template <
typename T, std::
size_t TSize>
1986 static const bool Value =
true;
1994template <
typename T>
1997 return details::IsStaticVector<T>::Value;
2010template <
typename T, std::
size_t TSize1, std::
size_t TSize2>
2018COMMS_MSVC_WARNING_POP
2019COMMS_GNU_WARNING_POP
Replacement of std::aligned_storage due to deprecation since C++23.
This file contains classes required for generic custom assertion functionality.
#define COMMS_ASSERT(expr)
Generic assert macro.
Definition Assert.h:170
Contains various compiler related definitions.
Replacement to std::vector when no dynamic memory allocation is allowed.
Definition StaticVector.h:960
const_iterator cend() const
Returns an iterator to the end.
Definition StaticVector.h:1215
void assign(std::initializer_list< value_type > init)
Assigns values to the container.
Definition StaticVector.h:1092
reference at(size_type pos)
Access specified element with bounds checking.
Definition StaticVector.h:1103
size_type max_size() const
Returns the maximum possible number of elements.
Definition StaticVector.h:1280
typename Base::const_reference const_reference
Const reference to single element.
Definition StaticVector.h:984
void assign(size_type count, const T &value)
Assigns values to the container.
Definition StaticVector.h:1077
void resize(size_type count)
Changes the number of elements stored.
Definition StaticVector.h:1410
const_reverse_iterator rbegin() const
Returns a reverse iterator to the beginning.
Definition StaticVector.h:1229
iterator begin()
Returns an iterator to the beginning.
Definition StaticVector.h:1180
static constexpr bool isStaticVector()
Compile time check whether the provided type is a variant of comms::util::StaticVector.
Definition StaticVector.h:1995
void swap(StaticVector< T, TOtherSize > &other)
Swaps the contents.
Definition StaticVector.h:1427
const_iterator begin() const
Returns an iterator to the beginning.
Definition StaticVector.h:1187
const_reference at(size_type pos) const
Access specified element with bounds checking.
Definition StaticVector.h:1113
StaticVector(TIter from, TIter to)
Constructor.
Definition StaticVector.h:1024
typename Base::reference reference
Reference to single element.
Definition StaticVector.h:981
StaticVector(const StaticVector< T, TOtherSize > &other)
Copy constructor.
Definition StaticVector.h:1032
bool operator!=(const StaticVector< T, TSize1 > &v1, const StaticVector< T, TSize2 > &v2)
Lexicographically compares the values in the vector.
Definition StaticVector.h:1968
StaticVector(size_type count)
Constructor.
Definition StaticVector.h:1016
StaticVector(const StaticVector &other)
Copy constructor.
Definition StaticVector.h:1039
iterator insert(const_iterator iter, std::initializer_list< value_type > init)
Inserts elements.
Definition StaticVector.h:1347
const_reference operator[](size_type pos) const
Access specified element without bounds checking.
Definition StaticVector.h:1127
size_type capacity() const
Returns the number of elements that can be held in currently allocated storage.
Definition StaticVector.h:1297
void assign(TIter from, TIter to)
Assigns values to the container.
Definition StaticVector.h:1085
reference front()
Access the first element.
Definition StaticVector.h:1135
const_reference back() const
Access the last element.
Definition StaticVector.h:1159
void clear()
Clears the contents.
Definition StaticVector.h:1311
reference back()
Access the last element.
Definition StaticVector.h:1151
const_reference front() const
Access the first element.
Definition StaticVector.h:1143
bool operator<(const StaticVector< T, TSize1 > &v1, const StaticVector< T, TSize2 > &v2)
Lexicographically compares the values in the vector.
Definition StaticVector.h:1921
bool operator<=(const StaticVector< T, TSize1 > &v1, const StaticVector< T, TSize2 > &v2)
Lexicographically compares the values in the vector.
Definition StaticVector.h:1930
iterator insert(const_iterator iter, T &&value)
Inserts elements.
Definition StaticVector.h:1325
const_iterator end() const
Returns an iterator to the end.
Definition StaticVector.h:1208
typename Base::size_type size_type
Type used for size information.
Definition StaticVector.h:975
StaticVector(std::initializer_list< value_type > init)
Constructor.
Definition StaticVector.h:1046
StaticVector()=default
Default constructor.
StaticVector(size_type count, const T &value)
Constructor.
Definition StaticVector.h:1009
const_reverse_iterator rend() const
Returns a reverse iterator to the end.
Definition StaticVector.h:1250
void pop_back()
Removes the last element.
Definition StaticVector.h:1402
void resize(size_type count, const value_type &value)
Changes the number of elements stored.
Definition StaticVector.h:1418
void shrink_to_fit()
Reduces memory usage by freeing unused memory.
Definition StaticVector.h:1305
typename Base::iterator iterator
Type of the iterator.
Definition StaticVector.h:993
iterator insert(const_iterator iter, TIter from, TIter to)
Inserts elements.
Definition StaticVector.h:1340
const_reverse_iterator crbegin() const
Returns a reverse iterator to the beginning.
Definition StaticVector.h:1236
iterator insert(const_iterator iter, const T &value)
Inserts elements.
Definition StaticVector.h:1318
reverse_iterator rend()
Returns a reverse iterator to the end.
Definition StaticVector.h:1243
reverse_iterator rbegin()
Returns a reverse iterator to the beginning.
Definition StaticVector.h:1222
typename Base::StorageType::difference_type difference_type
Type used in pointer arithmetics.
Definition StaticVector.h:978
iterator end()
Returns an iterator to the end.
Definition StaticVector.h:1201
bool operator>(const StaticVector< T, TSize1 > &v1, const StaticVector< T, TSize2 > &v2)
Lexicographically compares the values in the vector.
Definition StaticVector.h:1939
void push_back(const T &value)
Adds an element to the end.
Definition StaticVector.h:1377
typename Base::value_type value_type
Type of single element.
Definition StaticVector.h:972
iterator erase(const_iterator from, const_iterator to)
Erases elements.
Definition StaticVector.h:1369
void swap(comms::util::StaticVector< T, TSize1 > &v1, comms::util::StaticVector< T, TSize2 > &v2)
Specializes the std::swap algorithm.
Definition StaticVector.h:2011
void reserve(size_type new_cap)
Reserves storage.
Definition StaticVector.h:1288
iterator insert(const_iterator iter, size_type count, const T &value)
Inserts elements.
Definition StaticVector.h:1332
size_type size() const
Returns the number of elements.
Definition StaticVector.h:1271
typename Base::const_reverse_iterator const_reverse_iterator
Type of the const reverse iterator.
Definition StaticVector.h:1002
bool operator==(const StaticVector< T, TSize1 > &v1, const StaticVector< T, TSize2 > &v2)
Lexicographically compares the values in the vector.
Definition StaticVector.h:1957
void push_back(T &&value)
Adds an element to the end.
Definition StaticVector.h:1385
typename Base::const_pointer const_pointer
Const pointer to single element.
Definition StaticVector.h:990
bool operator>=(const StaticVector< T, TSize1 > &v1, const StaticVector< T, TSize2 > &v2)
Lexicographically compares the values in the vector.
Definition StaticVector.h:1948
iterator emplace(const_iterator iter, TArgs &&... args)
Constructs elements in place.
Definition StaticVector.h:1355
void emplace_back(TArgs &&... args)
Constructs an element in place at the end.
Definition StaticVector.h:1394
typename Base::const_iterator const_iterator
Type of the const iterator.
Definition StaticVector.h:996
~StaticVector() noexcept=default
Destructor.
iterator erase(const_iterator iter)
Erases elements.
Definition StaticVector.h:1362
StaticVector & operator=(std::initializer_list< value_type > init)
Copy assignement.
Definition StaticVector.h:1069
bool empty() const
Checks whether the container is empty.
Definition StaticVector.h:1264
const_pointer data() const
Direct access to the underlying array.
Definition StaticVector.h:1173
pointer data()
Direct access to the underlying array.
Definition StaticVector.h:1166
typename Base::reverse_iterator reverse_iterator
Type of the reverse iterator.
Definition StaticVector.h:999
typename Base::pointer pointer
Pointer to single element.
Definition StaticVector.h:987
const_reverse_iterator crend() const
Returns a reverse iterator to the end.
Definition StaticVector.h:1257
reference operator[](size_type pos)
Access specified element without bounds checking.
Definition StaticVector.h:1120
const_iterator cbegin() const
Returns an iterator to the beginning.
Definition StaticVector.h:1194
void assign(T &obj, TIter from, TIter to)
Assigns a new value to provided object.
Definition assign.h:39
Main namespace for all classes / functions of COMMS library.