20#include <initializer_list>
26#if COMMS_IS_GCC_12 && defined(NDEBUG)
30COMMS_GNU_WARNING_DISABLE(
"-Warray-bounds")
33COMMS_MSVC_WARNING_PUSH
34COMMS_MSVC_WARNING_DISABLE(4324)
50 using size_type = std::size_t;
52 using const_reference =
const T&;
54 using const_pointer =
const T*;
55 using iterator = pointer;
56 using const_iterator = const_pointer;
57 using reverse_iterator = std::reverse_iterator<iterator>;
58 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
59 using CellType = comms::util::AlignedStorage<
sizeof(T), std::alignment_of<T>::value>;
61 static_assert(
sizeof(CellType) ==
sizeof(T),
"Type T must be padded");
63 StaticVectorBase(CellType* dataPtr, std::size_t cap)
69 ~StaticVectorBase() noexcept
74 StaticVectorBase(
const StaticVectorBase&) =
delete;
75 StaticVectorBase& operator=(
const StaticVectorBase&) =
delete;
78 std::size_t size()
const
83 std::size_t capacity()
const
95 COMMS_MSVC_WARNING_SUPPRESS(4189)
96 auto& lastElem = back();
104 return elem(size() - 1);
107 const T& back()
const
110 return elem(size() - 1);
119 const T& front()
const
125 template <
typename TIter>
126 void assign(TIter from, TIter to)
129 for (
auto iter = from; iter != to; ++iter) {
130 if (capacity() <= size()) {
131 static constexpr bool Not_all_elements_are_copied =
false;
132 static_cast<void>(Not_all_elements_are_copied);
137 new (cellPtr(size())) T(*(
reinterpret_cast<const T*
>(&*iter)));
142 void fill(std::size_t count,
const T& value)
146 for (
auto idx = 0U; idx < count; ++idx) {
147 new (cellPtr(idx)) T(value);
153 for (
auto idx = 0U; idx < size(); ++idx) {
169 const T* begin()
const
174 const T* cbegin()
const
185 return begin() + size();
193 const T* cend()
const
195 return cbegin() + size();
198 T& at(std::size_t pos)
204 const T& at(std::size_t pos)
const
210 T& operator[](std::size_t pos)
215 const T& operator[](std::size_t pos)
const
229 const T* data()
const
238 template <
typename U>
239 T* insert(
const T* pos, U&& value)
244 push_back(std::forward<U>(value));
249 push_back(std::move(back()));
250 auto* insertIter = begin() + std::distance(cbegin(), pos);
251 std::move_backward(insertIter, end() - 2, end() - 1);
252 *insertIter = std::forward<U>(value);
256 T* insert(
const T* pos, std::size_t count,
const T& value)
260 auto dist = std::distance(cbegin(), pos);
261 COMMS_ASSERT((0 <= dist) &&
static_cast<std::size_t
>(dist) < size());
262 auto* posIter = begin() + dist;
263 if (end() <= posIter) {
272 auto tailCount =
static_cast<std::size_t
>(std::distance(posIter, end()));
273 if (count <= tailCount) {
274 auto pushBegIter = end() - count;
275 auto pushEndIter = end();
276 for (
auto iter = pushBegIter; iter != pushEndIter; ++iter) {
277 push_back(std::move(*iter));
280 auto moveBegIter = posIter;
281 auto moveEndIter = moveBegIter + (tailCount - count);
284 COMMS_GNU_WARNING_PUSH
285#if COMMS_IS_GCC_12 && defined(NDEBUG)
288 COMMS_GNU_WARNING_DISABLE(
"-Wstringop-overflow")
290 std::move_backward(moveBegIter, moveEndIter, pushEndIter);
291 COMMS_GNU_WARNING_POP
293 auto* assignBegIter = posIter;
294 auto* assignEndIter = assignBegIter + count;
295 for (
auto iter = assignBegIter; iter != assignEndIter; ++iter) {
301 auto pushValueCount = count - tailCount;
302 for (
auto idx = 0U; idx < pushValueCount; ++idx) {
306 auto* pushBegIter = posIter;
307 auto* pushEndIter = pushBegIter + tailCount;
308 for (
auto iter = pushBegIter; iter != pushEndIter; ++iter) {
309 push_back(std::move(*iter));
312 auto assignBegIter = posIter;
313 auto assignEndIter = assignBegIter + tailCount;
314 for (
auto iter = assignBegIter; iter != assignEndIter; ++iter) {
320 template <
typename TIter>
321 T* insert(
const T* pos, TIter from, TIter to)
323 using Tag =
typename std::iterator_traits<TIter>::iterator_category;
324 return insert_internal(pos, from, to, Tag());
327 template <
typename... TArgs>
328 T* emplace(
const T* iter, TArgs&&... args)
330 auto* insertIter = begin() + std::distance(cbegin(), iter);
331 if (iter == cend()) {
332 emplace_back(std::forward<TArgs>(args)...);
337 push_back(std::move(back()));
338 std::move_backward(insertIter, end() - 2, end() - 1);
340 new (insertIter) T(std::forward<TArgs>(args)...);
344 T* erase(
const T* from,
const T* to)
350 auto tailCount =
static_cast<std::size_t
>(std::distance(to, cend()));
351 auto eraseCount =
static_cast<std::size_t
>(std::distance(from, to));
353 auto* moveSrc = begin() + std::distance(cbegin(), to);
354 auto* moveDest = begin() + std::distance(cbegin(), from);
355 std::move(moveSrc, end(), moveDest);
357 auto* eraseFrom = moveDest + tailCount;
358 auto* eraseTo = end();
361 COMMS_ASSERT(
static_cast<std::size_t
>(std::distance(eraseFrom, eraseTo)) == eraseCount);
362 for (
auto iter = eraseFrom; iter != eraseTo; ++iter) {
365 m_size -= eraseCount;
369 template <
typename U>
370 void push_back(U&& value)
373 new (cellPtr(size())) T(std::forward<U>(value));
377 template <
typename... TArgs>
378 void emplace_back(TArgs&&... args)
381 new (cellPtr(size())) T(std::forward<TArgs>(args)...);
385 void resize(std::size_t count,
const T& value)
387 if (count < size()) {
388 erase(begin() + count, end());
393 while (size() < count) {
398 void swap(StaticVectorBase<T>& other)
400 auto swapSize = std::min(other.size(), size());
401 for (
auto idx = 0U; idx < swapSize; ++idx) {
402 std::swap(this->
operator[](idx), other[idx]);
405 auto otherSize = other.size();
406 auto thisSize = size();
408 if (otherSize == thisSize) {
412 if (otherSize < thisSize) {
413 auto limit = std::min(thisSize, other.capacity());
414 for (
auto idx = swapSize; idx < limit; ++idx) {
415 new (other.cellPtr(idx)) T(std::move(elem(idx)));
418 other.m_size = thisSize;
419 erase(begin() + otherSize, end());
423 auto limit = std::min(otherSize, capacity());
424 for (
auto idx = swapSize; idx < limit; ++idx) {
425 new (cellPtr(idx)) T(std::move(other.elem(idx)));
428 other.erase(other.begin() + thisSize, other.end());
432 CellType& cell(std::size_t idx)
438 const CellType& cell(std::size_t idx)
const
444 CellType* cellPtr(std::size_t idx)
450 T& elem(std::size_t idx)
452 return reinterpret_cast<T&
>(cell(idx));
455 const T& elem(std::size_t idx)
const
457 return reinterpret_cast<const T&
>(cell(idx));
460 template <
typename TIter>
461 T* insert_random_access(
const T* pos, TIter from, TIter to)
464 auto* posIter = begin() + std::distance(cbegin(), pos);
465 if (end() <= posIter) {
466 for (; from != to; ++from) {
473 auto count =
static_cast<std::size_t
>(std::distance(from, to));
475 auto tailCount =
static_cast<std::size_t
>(std::distance(posIter, end()));
476 if (count <= tailCount) {
477 auto pushBegIter = end() - count;
478 auto pushEndIter = end();
479 for (
auto iter = pushBegIter; iter != pushEndIter; ++iter) {
480 push_back(std::move(*iter));
483 auto moveBegIter = posIter;
484 auto moveEndIter = moveBegIter + (tailCount - count);
486 std::move_backward(moveBegIter, moveEndIter, pushEndIter);
488 auto* assignBegIter = posIter;
489 auto* assignEndIter = assignBegIter + count;
490 for (
auto iter = assignBegIter; iter != assignEndIter; ++iter) {
497 auto pushValueCount = count - tailCount;
498 auto pushInsertedBegIter = to - pushValueCount;
499 for (
auto idx = 0U; idx < pushValueCount; ++idx) {
500 push_back(*pushInsertedBegIter);
501 ++pushInsertedBegIter;
504 auto* pushBegIter = posIter;
505 auto* pushEndIter = pushBegIter + tailCount;
506 for (
auto iter = pushBegIter; iter != pushEndIter; ++iter) {
507 push_back(std::move(*iter));
510 auto assignBegIter = posIter;
511 auto assignEndIter = assignBegIter + tailCount;
512 for (
auto iter = assignBegIter; iter != assignEndIter; ++iter) {
520 template <
typename TIter>
521 T* insert_input(
const T* pos, TIter from, TIter to)
524 for (; from != to; ++from) {
525 if (ret ==
nullptr) {
526 ret = begin() + std::distance(cbegin(), pos);
534 template <
typename TIter>
535 T* insert_internal(
const T* pos, TIter from, TIter to, std::random_access_iterator_tag)
537 return insert_random_access(pos, from, to);
540 template <
typename TIter>
541 T* insert_internal(
const T* pos, TIter from, TIter to, std::input_iterator_tag)
543 return insert_input(pos, from, to);
547 CellType* m_data =
nullptr;
548 std::size_t m_capacity = 0;
549 std::size_t m_size = 0;
552template <
typename T, std::
size_t TSize>
553struct StaticVectorStorageBase
555 using ElementType = comms::util::AlignedStorage<
sizeof(T), std::alignment_of<T>::value>;
556 using StorageType = std::array<ElementType, TSize>;
557 alignas(
alignof(T)) StorageType m_data;
560template <
typename T, std::
size_t TSize>
561class StaticVectorGeneric :
562 public StaticVectorStorageBase<T, TSize>,
563 public StaticVectorBase<T>
565 using StorageBase = StaticVectorStorageBase<T, TSize>;
566 using Base = StaticVectorBase<T>;
569 using value_type =
typename Base::value_type;
570 using size_type =
typename Base::size_type;
571 using difference_type =
typename StorageBase::StorageType::difference_type;
572 using reference =
typename Base::reference;
573 using const_reference =
typename Base::const_reference;
574 using pointer =
typename Base::pointer;
575 using const_pointer =
typename Base::const_pointer;
576 using iterator =
typename Base::iterator;
577 using const_iterator =
typename Base::const_iterator;
578 using reverse_iterator =
typename Base::reverse_iterator;
579 using const_reverse_iterator =
typename Base::const_reverse_iterator;
581 StaticVectorGeneric()
582 : Base(StorageBase::m_data.data(), StorageBase::m_data.size())
586 StaticVectorGeneric(size_type count,
const T& value)
587 : Base(StorageBase::m_data.data(), StorageBase::m_data.size())
592 explicit StaticVectorGeneric(size_type count)
593 : Base(StorageBase::m_data.data(), StorageBase::m_data.size())
597 Base::emplace_back();
602 template <
typename TIter>
603 StaticVectorGeneric(TIter from, TIter to)
604 : Base(StorageBase::m_data.data(), StorageBase::m_data.size())
609 template <std::
size_t TOtherSize>
610 StaticVectorGeneric(
const StaticVectorGeneric<T, TOtherSize>& other)
611 : Base(StorageBase::m_data.data(), StorageBase::m_data.size())
613 assign(other.begin(), other.end());
616 StaticVectorGeneric(
const StaticVectorGeneric& other)
617 : Base(StorageBase::m_data.data(), StorageBase::m_data.size())
619 assign(other.begin(), other.end());
622 StaticVectorGeneric(std::initializer_list<value_type> init)
623 : Base(StorageBase::m_data.data(), StorageBase::m_data.size())
625 assign(init.begin(), init.end());
628 ~StaticVectorGeneric() noexcept = default;
630 StaticVectorGeneric& operator=(const StaticVectorGeneric& other)
632 if (&other ==
this) {
636 assign(other.begin(), other.end());
640 template <std::
size_t TOtherSize>
641 StaticVectorGeneric& operator=(
const StaticVectorGeneric<T, TOtherSize>& other)
643 assign(other.cbegin(), other.cend());
647 StaticVectorGeneric& operator=(std::initializer_list<value_type> init)
653 void assign(size_type count,
const T& value)
656 Base::fill(count, value);
659 template <
typename TIter>
660 void assign(TIter from, TIter to)
662 Base::assign(from, to);
665 void assign(std::initializer_list<value_type> init)
667 assign(init.begin(), init.end());
670 void reserve(size_type new_cap)
672 static_cast<void>(new_cap);
677template <
typename TOrig,
typename TCast, std::
size_t TSize>
678class StaticVectorCasted :
public StaticVectorGeneric<TCast, TSize>
680 using Base = StaticVectorGeneric<TCast, TSize>;
681 static_assert(
sizeof(TOrig) ==
sizeof(TCast),
"The sizes are not equal");
684 using value_type = TOrig;
685 using size_type =
typename Base::size_type;
686 using difference_type =
typename Base::difference_type;
687 using reference = value_type&;
688 using const_reference =
const value_type&;
689 using pointer = value_type*;
690 using const_pointer =
const value_type*;
691 using iterator = pointer;
692 using const_iterator = const_pointer;
694 StaticVectorCasted() =
default;
696 StaticVectorCasted(size_type count, const_reference& value)
697 : Base(count, *(reinterpret_cast<typename Base::const_pointer>(&value)))
701 explicit StaticVectorCasted(size_type count)
706 template <
typename TIter>
707 StaticVectorCasted(TIter from, TIter to)
712 template <std::
size_t TOtherSize>
713 StaticVectorCasted(
const StaticVectorCasted<TOrig, TCast, TOtherSize>& other)
718 StaticVectorCasted(
const StaticVectorCasted& other)
723 StaticVectorCasted(std::initializer_list<value_type> init)
724 : Base(init.begin(), init.end())
728 ~StaticVectorCasted() noexcept = default;
730 StaticVectorCasted& operator=(const StaticVectorCasted&) = default;
732 template <
std::
size_t TOtherSize>
733 StaticVectorCasted& operator=(const StaticVectorCasted<TOrig, TCast, TOtherSize>& other)
735 Base::operator=(other);
739 StaticVectorCasted& operator=(std::initializer_list<value_type> init)
741 Base::operator=(init);
745 void assign(size_type count, const_reference& value)
747 Base::assign(count, value);
750 template <
typename TIter>
751 void assign(TIter from, TIter to)
753 Base::assign(from, to);
756 void assign(std::initializer_list<value_type> init)
758 assign(init.begin(), init.end());
761 reference at(size_type pos)
763 return *(
reinterpret_cast<pointer
>(&(Base::at(pos))));
766 const_reference at(size_type pos)
const
768 return *(
reinterpret_cast<const_pointer
>(&(Base::at(pos))));
771 reference operator[](size_type pos)
773 return *(
reinterpret_cast<pointer
>(&(Base::operator[](pos))));
776 const_reference operator[](size_type pos)
const
778 return *(
reinterpret_cast<const_pointer
>(&(Base::operator[](pos))));
783 return *(
reinterpret_cast<pointer
>(&(Base::front())));
786 const_reference front()
const
788 return *(
reinterpret_cast<const_pointer
>(&(Base::front())));
793 return *(
reinterpret_cast<pointer
>(&(Base::back())));
796 const_reference back()
const
798 return *(
reinterpret_cast<const_pointer
>(&(Base::back())));
803 return reinterpret_cast<pointer
>(Base::data());
806 const_pointer data()
const
808 return reinterpret_cast<const_pointer
>(Base::data());
813 return reinterpret_cast<iterator
>(Base::begin());
816 const_iterator begin()
const
821 const_iterator cbegin()
const
823 return reinterpret_cast<const_iterator
>(Base::cbegin());
828 return reinterpret_cast<iterator
>(Base::end());
831 const_iterator end()
const
836 const_iterator cend()
const
838 return reinterpret_cast<const_iterator
>(Base::cend());
841 iterator insert(const_iterator iter, const_reference value)
844 reinterpret_cast<iterator
>(
846 reinterpret_cast<typename Base::const_iterator
>(iter),
847 *(
reinterpret_cast<typename Base::const_pointer
>(&value))));
850 iterator insert(const_iterator iter, TCast&& value)
853 reinterpret_cast<iterator
>(
855 reinterpret_cast<typename Base::const_iterator
>(iter),
856 std::move(*(
reinterpret_cast<typename Base::pointer
>(&value)))));
859 iterator insert(const_iterator iter, size_type count, const_reference value)
862 reinterpret_cast<iterator
>(
864 reinterpret_cast<typename Base::const_iterator
>(iter),
866 *(
reinterpret_cast<typename Base::const_pointer
>(&value))));
869 template <
typename TIter>
870 iterator insert(const_iterator iter, TIter from, TIter to)
873 reinterpret_cast<iterator
>(
875 reinterpret_cast<typename Base::const_iterator
>(iter),
880 iterator insert(const_iterator iter, std::initializer_list<value_type> init)
883 reinterpret_cast<iterator
>(
885 reinterpret_cast<typename Base::const_iterator
>(iter),
890 template <
typename... TArgs>
891 iterator emplace(const_iterator iter, TArgs&&... args)
894 reinterpret_cast<iterator
>(
896 reinterpret_cast<typename Base::const_iterator
>(iter),
897 std::forward<TArgs>(args)...));
900 iterator erase(const_iterator iter)
902 return erase(iter, iter + 1);
907 iterator erase(const_iterator from, const_iterator to)
910 reinterpret_cast<iterator
>(
912 reinterpret_cast<typename Base::const_iterator
>(from),
913 reinterpret_cast<typename Base::const_iterator
>(to)));
916 void push_back(const_reference value)
918 Base::push_back(*(
reinterpret_cast<typename Base::const_pointer
>(&value)));
921 void push_back(TCast&& value)
923 Base::push_back(std::move(*(
reinterpret_cast<TCast*
>(&value))));
927template <
bool TSignedIntegral>
928struct StaticVectorBaseSignedIntegral;
931struct StaticVectorBaseSignedIntegral<true>
933 template <
typename T, std::
size_t TSize>
934 using Type = StaticVectorCasted<T, typename std::make_unsigned<T>::type, TSize>;
938struct StaticVectorBaseSignedIntegral<false>
940 template <
typename T, std::
size_t TSize>
941 using Type = StaticVectorGeneric<T, TSize>;
944template <
typename T, std::
size_t TSize>
945using ChooseStaticVectorBase =
946 typename StaticVectorBaseSignedIntegral<std::is_integral<T>::value && std::is_signed<T>::value>::template Type<T, TSize>;
959template <
typename T, std::
size_t TSize>
962 using Base = details::ChooseStaticVectorBase<T, TSize>;
963 using ElementType =
typename Base::ElementType;
965 static_assert(
sizeof(T) ==
sizeof(ElementType),
966 "Sizes are not equal as expected.");
968 template <
typename U, std::
size_t TOtherSize>
1011 : Base(count, value)
1024 template <
typename TIter>
1032 template <std::
size_t TOtherSize>
1061 template <
std::
size_t TOtherSize>
1064 Base::operator=(other);
1072 Base::operator=(init);
1080 Base::assign(count, value);
1085 template <
typename TIter>
1088 Base::assign(from, to);
1093 void assign(std::initializer_list<value_type> init)
1095 assign(init.begin(), init.end());
1106 return Base::at(pos);
1117 return Base::at(pos);
1124 return Base::operator[](pos);
1131 return Base::operator[](pos);
1139 return Base::front();
1147 return Base::front();
1155 return Base::back();
1163 return Base::back();
1170 return Base::data();
1177 return Base::data();
1184 return Base::begin();
1198 return Base::cbegin();
1219 return Base::cend();
1268 return Base::empty();
1275 return Base::size();
1292 return Base::reserve(new_cap);
1301 return Base::capacity();
1322 return Base::insert(iter, value);
1329 return Base::insert(iter, std::move(value));
1336 return Base::insert(iter, count, value);
1341 template <
typename TIter>
1344 return Base::insert(iter, from, to);
1351 return Base::insert(iter, init.begin(), init.end());
1356 template <
typename... TArgs>
1359 return Base::emplace(iter, std::forward<TArgs>(args)...);
1366 return erase(iter, iter + 1);
1373 return Base::erase(from, to);
1381 Base::push_back(value);
1389 Base::push_back(std::move(value));
1395 template <
typename... TArgs>
1398 Base::emplace_back(std::forward<TArgs>(args)...);
1422 Base::resize(count, value);
1428 template <std::
size_t TOtherSize>
1436template <
typename T>
1437class StaticVector<T, 0U>
1439 using StorageType = std::array<T, 0U>;
1441 template <
typename U, std::
size_t TOtherSize>
1442 friend class StaticVector;
1445 using value_type =
typename StorageType::value_type;
1446 using size_type =
typename StorageType::size_type;
1447 using difference_type =
typename StorageType::difference_type;
1448 using reference =
typename StorageType::reference;
1449 using const_reference =
typename StorageType::const_reference;
1450 using pointer =
typename StorageType::pointer;
1451 using const_pointer =
typename StorageType::const_pointer;
1452 using iterator =
typename StorageType::iterator;
1453 using const_iterator =
typename StorageType::const_iterator;
1454 using reverse_iterator =
typename StorageType::reverse_iterator;
1455 using const_reverse_iterator =
typename StorageType::const_reverse_iterator;
1457 StaticVector() =
default;
1459 StaticVector(size_type count,
const T& value)
1461 static_cast<void>(value);
1466 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1467 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1468 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1471 explicit StaticVector(size_type count)
1477 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1478 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1479 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1482 template <
typename TIter>
1483 StaticVector(TIter from, TIter to)
1489 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1490 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1491 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1494 template <std::
size_t TOtherSize>
1495 StaticVector(
const StaticVector<T, TOtherSize>& other)
1497 static_cast<void>(other);
1498 if (TOtherSize == 0U) {
1502 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1503 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1504 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1507 StaticVector(
const StaticVector& other)
1509 static_cast<void>(other);
1512 StaticVector(std::initializer_list<value_type> init)
1514 if (std::begin(init) == std::end(init)) {
1518 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1519 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1520 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1523 ~StaticVector() noexcept = default;
1525 StaticVector& operator=(const StaticVector&) = default;
1527 template <
std::
size_t TOtherSize>
1528 StaticVector& operator=(const StaticVector<T, TOtherSize>& other)
1530 static_cast<void>(other);
1531 if (TOtherSize == 0U) {
1535 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1536 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1537 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1541 StaticVector& operator=(std::initializer_list<value_type> init)
1543 if (std::begin(init) == std::end(init)) {
1547 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1548 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1549 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1553 void assign(size_type count,
const T& value)
1555 static_cast<void>(value);
1560 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1561 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1562 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1565 template <
typename TIter>
1566 void assign(TIter from, TIter to)
1572 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1573 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1574 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1577 void assign(std::initializer_list<value_type> init)
1579 if (std::begin(init) == std::end(init)) {
1583 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1584 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1585 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1588 reference at(size_type pos)
1590 static_cast<void>(pos);
1591 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1592 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1593 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1597 const_reference at(size_type pos)
const
1599 static_cast<void>(pos);
1600 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1601 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1602 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1606 reference operator[](size_type pos)
1608 static_cast<void>(pos);
1609 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1610 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1611 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1615 const_reference operator[](size_type pos)
const
1617 static_cast<void>(pos);
1618 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1619 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1620 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1626 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1627 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1628 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1629 return m_data.front();
1632 const_reference front()
const
1634 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1635 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1636 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1637 return m_data.front();
1642 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1643 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1644 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1645 return m_data.back();
1648 const_reference back()
const
1650 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1651 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1652 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1653 return m_data.back();
1658 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1659 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1660 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1661 return m_data.data();
1664 const_pointer data()
const
1666 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1667 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1668 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1669 return m_data.data();
1674 return m_data.begin();
1677 const_iterator begin()
const
1679 return m_data.begin();
1682 const_iterator cbegin()
const
1684 return m_data.cbegin();
1689 return m_data.end();
1692 const_iterator end()
const
1694 return m_data.end();
1697 const_iterator cend()
const
1699 return m_data.cend();
1702 reverse_iterator rbegin()
1704 return m_data.rbegin();
1707 const_reverse_iterator rbegin()
const
1709 return m_data.rbegin();
1712 const_reverse_iterator crbegin()
const
1714 return m_data.crbegin();
1717 reverse_iterator rend()
1719 return m_data.rend();
1722 const_reverse_iterator rend()
const
1724 return m_data.rend();
1727 const_reverse_iterator crend()
const
1729 return m_data.crend();
1734 return m_data.empty();
1737 size_type size()
const
1739 return m_data.size();
1742 size_type max_size()
const
1744 return m_data.max_size();
1747 void reserve(size_type new_cap)
1749 static_cast<void>(new_cap);
1750 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1751 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1752 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1755 size_type capacity()
const
1760 void shrink_to_fit()
1768 iterator insert(const_iterator iter,
const T& value)
1770 static_cast<void>(iter);
1771 static_cast<void>(value);
1772 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1773 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1774 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1775 return m_data.end();
1778 iterator insert(const_iterator iter, T&& value)
1780 static_cast<void>(iter);
1781 static_cast<void>(value);
1782 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1783 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1784 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1785 return m_data.end();
1788 iterator insert(const_iterator iter, size_type count,
const T& value)
1790 static_cast<void>(iter);
1791 static_cast<void>(count);
1792 static_cast<void>(value);
1793 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1794 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1795 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1796 return m_data.end();
1799 template <
typename TIter>
1800 iterator insert(const_iterator iter, TIter from, TIter to)
1802 static_cast<void>(iter);
1803 static_cast<void>(from);
1804 static_cast<void>(to);
1805 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1806 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1807 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1808 return m_data.end();
1811 iterator insert(const_iterator iter, std::initializer_list<value_type> init)
1813 static_cast<void>(iter);
1814 static_cast<void>(init);
1815 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1816 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1817 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1818 return m_data.end();
1821 template <
typename... TArgs>
1822 iterator emplace(const_iterator iter, TArgs&&...)
1824 static_cast<void>(iter);
1825 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1826 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1827 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1828 return m_data.end();
1831 iterator erase(const_iterator iter)
1833 static_cast<void>(iter);
1834 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1835 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1836 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1837 return m_data.end();
1840 iterator erase(const_iterator from, const_iterator to)
1843 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1844 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1845 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1847 return m_data.end();
1850 void push_back(
const T& value)
1852 static_cast<void>(value);
1853 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1854 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1855 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1858 void push_back(T&& value)
1860 static_cast<void>(value);
1861 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1862 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1863 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1866 template <
typename... TArgs>
1867 void emplace_back(TArgs&&...)
1869 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1870 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1871 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1876 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1877 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1878 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1881 void resize(size_type count)
1887 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1888 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1889 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1892 void resize(size_type count,
const value_type& value)
1894 static_cast<void>(value);
1899 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1900 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1901 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1904 template <std::
size_t TOtherSize>
1905 void swap(StaticVector<T, TOtherSize>& other)
1907 static_cast<void>(other);
1908 if (TOtherSize != 0U) {
1909 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1910 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1911 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1922template <
typename T, std::
size_t TSize1, std::
size_t TSize2>
1925 return std::lexicographical_compare(v1.begin(), v1.end(), v2.begin(), v2.end());
1931template <
typename T, std::
size_t TSize1, std::
size_t TSize2>
1940template <
typename T, std::
size_t TSize1, std::
size_t TSize2>
1949template <
typename T, std::
size_t TSize1, std::
size_t TSize2>
1958template <
typename T, std::
size_t TSize1, std::
size_t TSize2>
1961 return (v1.size() == v2.size()) &&
1969template <
typename T, std::
size_t TSize1, std::
size_t TSize2>
1979template <
typename T>
1980struct IsStaticVector
1982 static const bool Value =
false;
1985template <
typename T, std::
size_t TSize>
1988 static const bool Value =
true;
1996template <
typename T>
1999 return details::IsStaticVector<T>::Value;
2012template <
typename T, std::
size_t TSize1, std::
size_t TSize2>
2020COMMS_MSVC_WARNING_POP
2021COMMS_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:961
const_iterator cend() const
Returns an iterator to the end.
Definition StaticVector.h:1217
void assign(std::initializer_list< value_type > init)
Assigns values to the container.
Definition StaticVector.h:1093
reference at(size_type pos)
Access specified element with bounds checking.
Definition StaticVector.h:1104
size_type max_size() const
Returns the maximum possible number of elements.
Definition StaticVector.h:1282
typename Base::const_reference const_reference
Const reference to single element.
Definition StaticVector.h:985
void assign(size_type count, const T &value)
Assigns values to the container.
Definition StaticVector.h:1078
void resize(size_type count)
Changes the number of elements stored.
Definition StaticVector.h:1412
const_reverse_iterator rbegin() const
Returns a reverse iterator to the beginning.
Definition StaticVector.h:1231
iterator begin()
Returns an iterator to the beginning.
Definition StaticVector.h:1182
static constexpr bool isStaticVector()
Compile time check whether the provided type is a variant of comms::util::StaticVector.
Definition StaticVector.h:1997
void swap(StaticVector< T, TOtherSize > &other)
Swaps the contents.
Definition StaticVector.h:1429
const_iterator begin() const
Returns an iterator to the beginning.
Definition StaticVector.h:1189
const_reference at(size_type pos) const
Access specified element with bounds checking.
Definition StaticVector.h:1115
StaticVector(TIter from, TIter to)
Constructor.
Definition StaticVector.h:1025
typename Base::reference reference
Reference to single element.
Definition StaticVector.h:982
StaticVector(const StaticVector< T, TOtherSize > &other)
Copy constructor.
Definition StaticVector.h:1033
bool operator!=(const StaticVector< T, TSize1 > &v1, const StaticVector< T, TSize2 > &v2)
Lexicographically compares the values in the vector.
Definition StaticVector.h:1970
StaticVector(size_type count)
Constructor.
Definition StaticVector.h:1017
StaticVector(const StaticVector &other)
Copy constructor.
Definition StaticVector.h:1040
iterator insert(const_iterator iter, std::initializer_list< value_type > init)
Inserts elements.
Definition StaticVector.h:1349
const_reference operator[](size_type pos) const
Access specified element without bounds checking.
Definition StaticVector.h:1129
size_type capacity() const
Returns the number of elements that can be held in currently allocated storage.
Definition StaticVector.h:1299
void assign(TIter from, TIter to)
Assigns values to the container.
Definition StaticVector.h:1086
reference front()
Access the first element.
Definition StaticVector.h:1137
const_reference back() const
Access the last element.
Definition StaticVector.h:1161
void clear()
Clears the contents.
Definition StaticVector.h:1313
reference back()
Access the last element.
Definition StaticVector.h:1153
const_reference front() const
Access the first element.
Definition StaticVector.h:1145
bool operator<(const StaticVector< T, TSize1 > &v1, const StaticVector< T, TSize2 > &v2)
Lexicographically compares the values in the vector.
Definition StaticVector.h:1923
bool operator<=(const StaticVector< T, TSize1 > &v1, const StaticVector< T, TSize2 > &v2)
Lexicographically compares the values in the vector.
Definition StaticVector.h:1932
iterator insert(const_iterator iter, T &&value)
Inserts elements.
Definition StaticVector.h:1327
const_iterator end() const
Returns an iterator to the end.
Definition StaticVector.h:1210
typename Base::size_type size_type
Type used for size information.
Definition StaticVector.h:976
StaticVector(std::initializer_list< value_type > init)
Constructor.
Definition StaticVector.h:1047
StaticVector()=default
Default constructor.
StaticVector(size_type count, const T &value)
Constructor.
Definition StaticVector.h:1010
const_reverse_iterator rend() const
Returns a reverse iterator to the end.
Definition StaticVector.h:1252
void pop_back()
Removes the last element.
Definition StaticVector.h:1404
void resize(size_type count, const value_type &value)
Changes the number of elements stored.
Definition StaticVector.h:1420
void shrink_to_fit()
Reduces memory usage by freeing unused memory.
Definition StaticVector.h:1307
typename Base::iterator iterator
Type of the iterator.
Definition StaticVector.h:994
iterator insert(const_iterator iter, TIter from, TIter to)
Inserts elements.
Definition StaticVector.h:1342
const_reverse_iterator crbegin() const
Returns a reverse iterator to the beginning.
Definition StaticVector.h:1238
iterator insert(const_iterator iter, const T &value)
Inserts elements.
Definition StaticVector.h:1320
reverse_iterator rend()
Returns a reverse iterator to the end.
Definition StaticVector.h:1245
reverse_iterator rbegin()
Returns a reverse iterator to the beginning.
Definition StaticVector.h:1224
typename Base::StorageType::difference_type difference_type
Type used in pointer arithmetics.
Definition StaticVector.h:979
iterator end()
Returns an iterator to the end.
Definition StaticVector.h:1203
bool operator>(const StaticVector< T, TSize1 > &v1, const StaticVector< T, TSize2 > &v2)
Lexicographically compares the values in the vector.
Definition StaticVector.h:1941
void push_back(const T &value)
Adds an element to the end.
Definition StaticVector.h:1379
typename Base::value_type value_type
Type of single element.
Definition StaticVector.h:973
iterator erase(const_iterator from, const_iterator to)
Erases elements.
Definition StaticVector.h:1371
void swap(comms::util::StaticVector< T, TSize1 > &v1, comms::util::StaticVector< T, TSize2 > &v2)
Specializes the std::swap algorithm.
Definition StaticVector.h:2013
void reserve(size_type new_cap)
Reserves storage.
Definition StaticVector.h:1290
iterator insert(const_iterator iter, size_type count, const T &value)
Inserts elements.
Definition StaticVector.h:1334
size_type size() const
Returns the number of elements.
Definition StaticVector.h:1273
typename Base::const_reverse_iterator const_reverse_iterator
Type of the const reverse iterator.
Definition StaticVector.h:1003
bool operator==(const StaticVector< T, TSize1 > &v1, const StaticVector< T, TSize2 > &v2)
Lexicographically compares the values in the vector.
Definition StaticVector.h:1959
void push_back(T &&value)
Adds an element to the end.
Definition StaticVector.h:1387
typename Base::const_pointer const_pointer
Const pointer to single element.
Definition StaticVector.h:991
bool operator>=(const StaticVector< T, TSize1 > &v1, const StaticVector< T, TSize2 > &v2)
Lexicographically compares the values in the vector.
Definition StaticVector.h:1950
iterator emplace(const_iterator iter, TArgs &&... args)
Constructs elements in place.
Definition StaticVector.h:1357
void emplace_back(TArgs &&... args)
Constructs an element in place at the end.
Definition StaticVector.h:1396
typename Base::const_iterator const_iterator
Type of the const iterator.
Definition StaticVector.h:997
~StaticVector() noexcept=default
Destructor.
iterator erase(const_iterator iter)
Erases elements.
Definition StaticVector.h:1364
StaticVector & operator=(std::initializer_list< value_type > init)
Copy assignement.
Definition StaticVector.h:1070
bool empty() const
Checks whether the container is empty.
Definition StaticVector.h:1266
const_pointer data() const
Direct access to the underlying array.
Definition StaticVector.h:1175
pointer data()
Direct access to the underlying array.
Definition StaticVector.h:1168
typename Base::reverse_iterator reverse_iterator
Type of the reverse iterator.
Definition StaticVector.h:1000
typename Base::pointer pointer
Pointer to single element.
Definition StaticVector.h:988
const_reverse_iterator crend() const
Returns a reverse iterator to the end.
Definition StaticVector.h:1259
reference operator[](size_type pos)
Access specified element without bounds checking.
Definition StaticVector.h:1122
const_iterator cbegin() const
Returns an iterator to the beginning.
Definition StaticVector.h:1196
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.