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;
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) {
167 const T* begin()
const
172 const T* cbegin()
const
183 return begin() + size();
191 const T* cend()
const
193 return cbegin() + size();
196 T& at(std::size_t pos)
202 const T& at(std::size_t pos)
const
208 T& operator[](std::size_t pos)
213 const T& operator[](std::size_t pos)
const
227 const T* data()
const
236 template <
typename U>
237 T* insert(
const T* pos, U&& value)
242 push_back(std::forward<U>(value));
247 push_back(std::move(back()));
248 auto* insertIter = begin() + std::distance(cbegin(), pos);
249 std::move_backward(insertIter, end() - 2, end() - 1);
250 *insertIter = std::forward<U>(value);
254 T* insert(
const T* pos, std::size_t count,
const T& value)
258 auto dist = std::distance(cbegin(), pos);
259 COMMS_ASSERT((0 <= dist) &&
static_cast<std::size_t
>(dist) < size());
260 auto* posIter = begin() + dist;
261 if (end() <= posIter) {
270 auto tailCount =
static_cast<std::size_t
>(std::distance(posIter, end()));
271 if (count <= tailCount) {
272 auto pushBegIter = end() - count;
273 auto pushEndIter = end();
274 for (
auto iter = pushBegIter; iter != pushEndIter; ++iter) {
275 push_back(std::move(*iter));
278 auto moveBegIter = posIter;
279 auto moveEndIter = moveBegIter + (tailCount - count);
282 COMMS_GNU_WARNING_PUSH
283#if COMMS_IS_GCC_12 && defined(NDEBUG)
286 COMMS_GNU_WARNING_DISABLE(
"-Wstringop-overflow")
288 std::move_backward(moveBegIter, moveEndIter, pushEndIter);
289 COMMS_GNU_WARNING_POP
291 auto* assignBegIter = posIter;
292 auto* assignEndIter = assignBegIter + count;
293 for (
auto iter = assignBegIter; iter != assignEndIter; ++iter) {
299 auto pushValueCount = count - tailCount;
300 for (
auto idx = 0U; idx < pushValueCount; ++idx) {
304 auto* pushBegIter = posIter;
305 auto* pushEndIter = pushBegIter + tailCount;
306 for (
auto iter = pushBegIter; iter != pushEndIter; ++iter) {
307 push_back(std::move(*iter));
310 auto assignBegIter = posIter;
311 auto assignEndIter = assignBegIter + tailCount;
312 for (
auto iter = assignBegIter; iter != assignEndIter; ++iter) {
318 template <
typename TIter>
319 T* insert(
const T* pos, TIter from, TIter to)
321 using Tag =
typename std::iterator_traits<TIter>::iterator_category;
322 return insert_internal(pos, from, to, Tag());
325 template <
typename... TArgs>
326 T* emplace(
const T* iter, TArgs&&... args)
328 auto* insertIter = begin() + std::distance(cbegin(), iter);
329 if (iter == cend()) {
330 emplace_back(std::forward<TArgs>(args)...);
335 push_back(std::move(back()));
336 std::move_backward(insertIter, end() - 2, end() - 1);
338 new (insertIter) T(std::forward<TArgs>(args)...);
342 T* erase(
const T* from,
const T* to)
348 auto tailCount =
static_cast<std::size_t
>(std::distance(to, cend()));
349 auto eraseCount =
static_cast<std::size_t
>(std::distance(from, to));
351 auto* moveSrc = begin() + std::distance(cbegin(), to);
352 auto* moveDest = begin() + std::distance(cbegin(), from);
353 std::move(moveSrc, end(), moveDest);
355 auto* eraseFrom = moveDest + tailCount;
356 auto* eraseTo = end();
359 COMMS_ASSERT(
static_cast<std::size_t
>(std::distance(eraseFrom, eraseTo)) == eraseCount);
360 for (
auto iter = eraseFrom; iter != eraseTo; ++iter) {
363 m_size -= eraseCount;
367 template <
typename U>
368 void push_back(U&& value)
371 new (cellPtr(size())) T(std::forward<U>(value));
375 template <
typename... TArgs>
376 void emplace_back(TArgs&&... args)
379 new (cellPtr(size())) T(std::forward<TArgs>(args)...);
383 void resize(std::size_t count,
const T& value)
385 if (count < size()) {
386 erase(begin() + count, end());
391 while (size() < count) {
396 void swap(StaticVectorBase<T>& other)
398 auto swapSize = std::min(other.size(), size());
399 for (
auto idx = 0U; idx < swapSize; ++idx) {
400 std::swap(this->
operator[](idx), other[idx]);
403 auto otherSize = other.size();
404 auto thisSize = size();
406 if (otherSize == thisSize) {
410 if (otherSize < thisSize) {
411 auto limit = std::min(thisSize, other.capacity());
412 for (
auto idx = swapSize; idx < limit; ++idx) {
413 new (other.cellPtr(idx)) T(std::move(elem(idx)));
416 other.m_size = thisSize;
417 erase(begin() + otherSize, end());
421 auto limit = std::min(otherSize, capacity());
422 for (
auto idx = swapSize; idx < limit; ++idx) {
423 new (cellPtr(idx)) T(std::move(other.elem(idx)));
426 other.erase(other.begin() + thisSize, other.end());
430 CellType& cell(std::size_t idx)
436 const CellType& cell(std::size_t idx)
const
442 CellType* cellPtr(std::size_t idx)
448 T& elem(std::size_t idx)
450 return reinterpret_cast<T&
>(cell(idx));
453 const T& elem(std::size_t idx)
const
455 return reinterpret_cast<const T&
>(cell(idx));
458 template <
typename TIter>
459 T* insert_random_access(
const T* pos, TIter from, TIter to)
462 auto* posIter = begin() + std::distance(cbegin(), pos);
463 if (end() <= posIter) {
464 for (; from != to; ++from) {
471 auto count =
static_cast<std::size_t
>(std::distance(from, to));
473 auto tailCount =
static_cast<std::size_t
>(std::distance(posIter, end()));
474 if (count <= tailCount) {
475 auto pushBegIter = end() - count;
476 auto pushEndIter = end();
477 for (
auto iter = pushBegIter; iter != pushEndIter; ++iter) {
478 push_back(std::move(*iter));
481 auto moveBegIter = posIter;
482 auto moveEndIter = moveBegIter + (tailCount - count);
484 std::move_backward(moveBegIter, moveEndIter, pushEndIter);
486 auto* assignBegIter = posIter;
487 auto* assignEndIter = assignBegIter + count;
488 for (
auto iter = assignBegIter; iter != assignEndIter; ++iter) {
495 auto pushValueCount = count - tailCount;
496 auto pushInsertedBegIter = to - pushValueCount;
497 for (
auto idx = 0U; idx < pushValueCount; ++idx) {
498 push_back(*pushInsertedBegIter);
499 ++pushInsertedBegIter;
502 auto* pushBegIter = posIter;
503 auto* pushEndIter = pushBegIter + tailCount;
504 for (
auto iter = pushBegIter; iter != pushEndIter; ++iter) {
505 push_back(std::move(*iter));
508 auto assignBegIter = posIter;
509 auto assignEndIter = assignBegIter + tailCount;
510 for (
auto iter = assignBegIter; iter != assignEndIter; ++iter) {
518 template <
typename TIter>
519 T* insert_input(
const T* pos, TIter from, TIter to)
522 for (; from != to; ++from) {
523 if (ret ==
nullptr) {
524 ret = begin() + std::distance(cbegin(), pos);
532 template <
typename TIter>
533 T* insert_internal(
const T* pos, TIter from, TIter to, std::random_access_iterator_tag)
535 return insert_random_access(pos, from, to);
538 template <
typename TIter>
539 T* insert_internal(
const T* pos, TIter from, TIter to, std::input_iterator_tag)
541 return insert_input(pos, from, to);
544 CellType* m_data =
nullptr;
545 std::size_t m_capacity = 0;
546 std::size_t m_size = 0;
549template <
typename T, std::
size_t TSize>
550struct StaticVectorStorageBase
552 using ElementType = comms::util::AlignedStorage<
sizeof(T), std::alignment_of<T>::value>;
553 using StorageType = std::array<ElementType, TSize>;
554 alignas(
alignof(T)) StorageType m_data;
557template <
typename T, std::
size_t TSize>
558class StaticVectorGeneric :
559 public StaticVectorStorageBase<T, TSize>,
560 public StaticVectorBase<T>
562 using StorageBase = StaticVectorStorageBase<T, TSize>;
563 using Base = StaticVectorBase<T>;
566 using value_type =
typename Base::value_type;
567 using size_type =
typename Base::size_type;
568 using difference_type =
typename StorageBase::StorageType::difference_type;
569 using reference =
typename Base::reference;
570 using const_reference =
typename Base::const_reference;
571 using pointer =
typename Base::pointer;
572 using const_pointer =
typename Base::const_pointer;
573 using iterator =
typename Base::iterator;
574 using const_iterator =
typename Base::const_iterator;
575 using reverse_iterator =
typename Base::reverse_iterator;
576 using const_reverse_iterator =
typename Base::const_reverse_iterator;
578 StaticVectorGeneric()
579 : Base(StorageBase::m_data.data(), StorageBase::m_data.size())
583 StaticVectorGeneric(size_type count,
const T& value)
584 : Base(StorageBase::m_data.data(), StorageBase::m_data.size())
589 explicit StaticVectorGeneric(size_type count)
590 : Base(StorageBase::m_data.data(), StorageBase::m_data.size())
594 Base::emplace_back();
599 template <
typename TIter>
600 StaticVectorGeneric(TIter from, TIter to)
601 : Base(StorageBase::m_data.data(), StorageBase::m_data.size())
606 template <std::
size_t TOtherSize>
607 StaticVectorGeneric(
const StaticVectorGeneric<T, TOtherSize>& other)
608 : Base(StorageBase::m_data.data(), StorageBase::m_data.size())
610 assign(other.begin(), other.end());
613 StaticVectorGeneric(
const StaticVectorGeneric& other)
614 : Base(StorageBase::m_data.data(), StorageBase::m_data.size())
616 assign(other.begin(), other.end());
619 StaticVectorGeneric(std::initializer_list<value_type> init)
620 : Base(StorageBase::m_data.data(), StorageBase::m_data.size())
622 assign(init.begin(), init.end());
625 ~StaticVectorGeneric() noexcept = default;
627 StaticVectorGeneric& operator=(const StaticVectorGeneric& other)
629 if (&other ==
this) {
633 assign(other.begin(), other.end());
637 template <std::
size_t TOtherSize>
638 StaticVectorGeneric& operator=(
const StaticVectorGeneric<T, TOtherSize>& other)
640 assign(other.cbegin(), other.cend());
644 StaticVectorGeneric& operator=(std::initializer_list<value_type> init)
650 void assign(size_type count,
const T& value)
653 Base::fill(count, value);
656 template <
typename TIter>
657 void assign(TIter from, TIter to)
659 Base::assign(from, to);
662 void assign(std::initializer_list<value_type> init)
664 assign(init.begin(), init.end());
667 void reserve(size_type new_cap)
669 static_cast<void>(new_cap);
674template <
typename TOrig,
typename TCast, std::
size_t TSize>
675class StaticVectorCasted :
public StaticVectorGeneric<TCast, TSize>
677 using Base = StaticVectorGeneric<TCast, TSize>;
678 static_assert(
sizeof(TOrig) ==
sizeof(TCast),
"The sizes are not equal");
681 using value_type = TOrig;
682 using size_type =
typename Base::size_type;
683 using difference_type =
typename Base::difference_type;
684 using reference = value_type&;
685 using const_reference =
const value_type&;
686 using pointer = value_type*;
687 using const_pointer =
const value_type*;
688 using iterator = pointer;
689 using const_iterator = const_pointer;
691 StaticVectorCasted() =
default;
693 StaticVectorCasted(size_type count, const_reference& value)
694 : Base(count, *(reinterpret_cast<typename Base::const_pointer>(&value)))
698 explicit StaticVectorCasted(size_type count)
703 template <
typename TIter>
704 StaticVectorCasted(TIter from, TIter to)
709 template <std::
size_t TOtherSize>
710 StaticVectorCasted(
const StaticVectorCasted<TOrig, TCast, TOtherSize>& other)
715 StaticVectorCasted(
const StaticVectorCasted& other)
720 StaticVectorCasted(std::initializer_list<value_type> init)
721 : Base(init.begin(), init.end())
725 ~StaticVectorCasted() noexcept = default;
727 StaticVectorCasted& operator=(const StaticVectorCasted&) = default;
729 template <
std::
size_t TOtherSize>
730 StaticVectorCasted& operator=(const StaticVectorCasted<TOrig, TCast, TOtherSize>& other)
732 Base::operator=(other);
736 StaticVectorCasted& operator=(std::initializer_list<value_type> init)
738 Base::operator=(init);
742 void assign(size_type count, const_reference& value)
744 Base::assign(count, value);
747 template <
typename TIter>
748 void assign(TIter from, TIter to)
750 Base::assign(from, to);
753 void assign(std::initializer_list<value_type> init)
755 assign(init.begin(), init.end());
758 reference at(size_type pos)
760 return *(
reinterpret_cast<pointer
>(&(Base::at(pos))));
763 const_reference at(size_type pos)
const
765 return *(
reinterpret_cast<const_pointer
>(&(Base::at(pos))));
768 reference operator[](size_type pos)
770 return *(
reinterpret_cast<pointer
>(&(Base::operator[](pos))));
773 const_reference operator[](size_type pos)
const
775 return *(
reinterpret_cast<const_pointer
>(&(Base::operator[](pos))));
780 return *(
reinterpret_cast<pointer
>(&(Base::front())));
783 const_reference front()
const
785 return *(
reinterpret_cast<const_pointer
>(&(Base::front())));
790 return *(
reinterpret_cast<pointer
>(&(Base::back())));
793 const_reference back()
const
795 return *(
reinterpret_cast<const_pointer
>(&(Base::back())));
800 return reinterpret_cast<pointer
>(Base::data());
803 const_pointer data()
const
805 return reinterpret_cast<const_pointer
>(Base::data());
810 return reinterpret_cast<iterator
>(Base::begin());
813 const_iterator begin()
const
818 const_iterator cbegin()
const
820 return reinterpret_cast<const_iterator
>(Base::cbegin());
825 return reinterpret_cast<iterator
>(Base::end());
828 const_iterator end()
const
833 const_iterator cend()
const
835 return reinterpret_cast<const_iterator
>(Base::cend());
838 iterator insert(const_iterator iter, const_reference value)
841 reinterpret_cast<iterator
>(
843 reinterpret_cast<typename Base::const_iterator
>(iter),
844 *(
reinterpret_cast<typename Base::const_pointer
>(&value))));
847 iterator insert(const_iterator iter, TCast&& value)
850 reinterpret_cast<iterator
>(
852 reinterpret_cast<typename Base::const_iterator
>(iter),
853 std::move(*(
reinterpret_cast<typename Base::pointer
>(&value)))));
856 iterator insert(const_iterator iter, size_type count, const_reference value)
859 reinterpret_cast<iterator
>(
861 reinterpret_cast<typename Base::const_iterator
>(iter),
863 *(
reinterpret_cast<typename Base::const_pointer
>(&value))));
866 template <
typename TIter>
867 iterator insert(const_iterator iter, TIter from, TIter to)
870 reinterpret_cast<iterator
>(
872 reinterpret_cast<typename Base::const_iterator
>(iter),
877 iterator insert(const_iterator iter, std::initializer_list<value_type> init)
880 reinterpret_cast<iterator
>(
882 reinterpret_cast<typename Base::const_iterator
>(iter),
887 template <
typename... TArgs>
888 iterator emplace(const_iterator iter, TArgs&&... args)
891 reinterpret_cast<iterator
>(
893 reinterpret_cast<typename Base::const_iterator
>(iter),
894 std::forward<TArgs>(args)...));
897 iterator erase(const_iterator iter)
899 return erase(iter, iter + 1);
904 iterator erase(const_iterator from, const_iterator to)
907 reinterpret_cast<iterator
>(
909 reinterpret_cast<typename Base::const_iterator
>(from),
910 reinterpret_cast<typename Base::const_iterator
>(to)));
913 void push_back(const_reference value)
915 Base::push_back(*(
reinterpret_cast<typename Base::const_pointer
>(&value)));
918 void push_back(TCast&& value)
920 Base::push_back(std::move(*(
reinterpret_cast<TCast*
>(&value))));
924template <
bool TSignedIntegral>
925struct StaticVectorBaseSignedIntegral;
928struct StaticVectorBaseSignedIntegral<true>
930 template <
typename T, std::
size_t TSize>
931 using Type = StaticVectorCasted<T, typename std::make_unsigned<T>::type, TSize>;
935struct StaticVectorBaseSignedIntegral<false>
937 template <
typename T, std::
size_t TSize>
938 using Type = StaticVectorGeneric<T, TSize>;
941template <
typename T, std::
size_t TSize>
942using ChooseStaticVectorBase =
943 typename StaticVectorBaseSignedIntegral<std::is_integral<T>::value && std::is_signed<T>::value>::template Type<T, TSize>;
956template <
typename T, std::
size_t TSize>
959 using Base = details::ChooseStaticVectorBase<T, TSize>;
960 using ElementType =
typename Base::ElementType;
962 static_assert(
sizeof(T) ==
sizeof(ElementType),
963 "Sizes are not equal as expected.");
965 template <
typename U, std::
size_t TOtherSize>
1008 : Base(count, value)
1021 template <
typename TIter>
1029 template <std::
size_t TOtherSize>
1058 template <
std::
size_t TOtherSize>
1061 Base::operator=(other);
1069 Base::operator=(init);
1077 Base::assign(count, value);
1082 template <
typename TIter>
1085 Base::assign(from, to);
1090 void assign(std::initializer_list<value_type> init)
1092 assign(init.begin(), init.end());
1103 return Base::at(pos);
1114 return Base::at(pos);
1121 return Base::operator[](pos);
1128 return Base::operator[](pos);
1136 return Base::front();
1144 return Base::front();
1152 return Base::back();
1160 return Base::back();
1167 return Base::data();
1174 return Base::data();
1181 return Base::begin();
1195 return Base::cbegin();
1216 return Base::cend();
1265 return Base::empty();
1272 return Base::size();
1289 return Base::reserve(new_cap);
1298 return Base::capacity();
1319 return Base::insert(iter, value);
1326 return Base::insert(iter, std::move(value));
1333 return Base::insert(iter, count, value);
1338 template <
typename TIter>
1341 return Base::insert(iter, from, to);
1348 return Base::insert(iter, init.begin(), init.end());
1353 template <
typename... TArgs>
1356 return Base::emplace(iter, std::forward<TArgs>(args)...);
1363 return erase(iter, iter + 1);
1370 return Base::erase(from, to);
1378 Base::push_back(value);
1386 Base::push_back(std::move(value));
1392 template <
typename... TArgs>
1395 Base::emplace_back(std::forward<TArgs>(args)...);
1419 Base::resize(count, value);
1425 template <std::
size_t TOtherSize>
1433template <
typename T>
1434class StaticVector<T, 0U>
1436 using StorageType = std::array<T, 0U>;
1438 template <
typename U, std::
size_t TOtherSize>
1439 friend class StaticVector;
1442 using value_type =
typename StorageType::value_type;
1443 using size_type =
typename StorageType::size_type;
1444 using difference_type =
typename StorageType::difference_type;
1445 using reference =
typename StorageType::reference;
1446 using const_reference =
typename StorageType::const_reference;
1447 using pointer =
typename StorageType::pointer;
1448 using const_pointer =
typename StorageType::const_pointer;
1449 using iterator =
typename StorageType::iterator;
1450 using const_iterator =
typename StorageType::const_iterator;
1451 using reverse_iterator =
typename StorageType::reverse_iterator;
1452 using const_reverse_iterator =
typename StorageType::const_reverse_iterator;
1454 StaticVector() =
default;
1456 StaticVector(size_type count,
const T& value)
1458 static_cast<void>(value);
1463 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1464 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1465 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1468 explicit StaticVector(size_type count)
1474 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1475 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1476 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1479 template <
typename TIter>
1480 StaticVector(TIter from, TIter to)
1486 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1487 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1488 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1491 template <std::
size_t TOtherSize>
1492 StaticVector(
const StaticVector<T, TOtherSize>& other)
1494 static_cast<void>(other);
1495 if (TOtherSize == 0U) {
1499 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1500 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1501 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1504 StaticVector(
const StaticVector& other)
1506 static_cast<void>(other);
1509 StaticVector(std::initializer_list<value_type> init)
1511 if (std::begin(init) == std::end(init)) {
1515 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1516 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1517 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1520 ~StaticVector() noexcept = default;
1522 StaticVector& operator=(const StaticVector&) = default;
1524 template <
std::
size_t TOtherSize>
1525 StaticVector& operator=(const StaticVector<T, TOtherSize>& other)
1527 static_cast<void>(other);
1528 if (TOtherSize == 0U) {
1532 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1533 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1534 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1538 StaticVector& operator=(std::initializer_list<value_type> init)
1540 if (std::begin(init) == std::end(init)) {
1544 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1545 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1546 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1550 void assign(size_type count,
const T& value)
1552 static_cast<void>(value);
1557 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1558 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1559 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1562 template <
typename TIter>
1563 void assign(TIter from, TIter to)
1569 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1570 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1571 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1574 void assign(std::initializer_list<value_type> init)
1576 if (std::begin(init) == std::end(init)) {
1580 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1581 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1582 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1585 reference at(size_type pos)
1587 static_cast<void>(pos);
1588 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1589 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1590 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1594 const_reference at(size_type pos)
const
1596 static_cast<void>(pos);
1597 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1598 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1599 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1603 reference operator[](size_type pos)
1605 static_cast<void>(pos);
1606 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1607 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1608 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1612 const_reference operator[](size_type pos)
const
1614 static_cast<void>(pos);
1615 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1616 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1617 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1623 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1624 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1625 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1626 return m_data.front();
1629 const_reference front()
const
1631 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1632 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1633 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1634 return m_data.front();
1639 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1640 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1641 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1642 return m_data.back();
1645 const_reference back()
const
1647 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1648 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1649 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1650 return m_data.back();
1655 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1656 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1657 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1658 return m_data.data();
1661 const_pointer data()
const
1663 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1664 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1665 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1666 return m_data.data();
1671 return m_data.begin();
1674 const_iterator begin()
const
1676 return m_data.begin();
1679 const_iterator cbegin()
const
1681 return m_data.cbegin();
1686 return m_data.end();
1689 const_iterator end()
const
1691 return m_data.end();
1694 const_iterator cend()
const
1696 return m_data.cend();
1699 reverse_iterator rbegin()
1701 return m_data.rbegin();
1704 const_reverse_iterator rbegin()
const
1706 return m_data.rbegin();
1709 const_reverse_iterator crbegin()
const
1711 return m_data.crbegin();
1714 reverse_iterator rend()
1716 return m_data.rend();
1719 const_reverse_iterator rend()
const
1721 return m_data.rend();
1724 const_reverse_iterator crend()
const
1726 return m_data.crend();
1731 return m_data.empty();
1734 size_type size()
const
1736 return m_data.size();
1739 size_type max_size()
const
1741 return m_data.max_size();
1744 void reserve(size_type new_cap)
1746 static_cast<void>(new_cap);
1747 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1748 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1749 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1752 size_type capacity()
const
1757 void shrink_to_fit()
1765 iterator insert(const_iterator iter,
const T& value)
1767 static_cast<void>(iter);
1768 static_cast<void>(value);
1769 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1770 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1771 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1772 return m_data.end();
1775 iterator insert(const_iterator iter, T&& value)
1777 static_cast<void>(iter);
1778 static_cast<void>(value);
1779 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1780 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1781 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1782 return m_data.end();
1785 iterator insert(const_iterator iter, size_type count,
const T& value)
1787 static_cast<void>(iter);
1788 static_cast<void>(count);
1789 static_cast<void>(value);
1790 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1791 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1792 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1793 return m_data.end();
1796 template <
typename TIter>
1797 iterator insert(const_iterator iter, TIter from, TIter to)
1799 static_cast<void>(iter);
1800 static_cast<void>(from);
1801 static_cast<void>(to);
1802 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1803 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1804 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1805 return m_data.end();
1808 iterator insert(const_iterator iter, std::initializer_list<value_type> init)
1810 static_cast<void>(iter);
1811 static_cast<void>(init);
1812 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1813 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1814 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1815 return m_data.end();
1818 template <
typename... TArgs>
1819 iterator emplace(const_iterator iter, TArgs&&...)
1821 static_cast<void>(iter);
1822 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1823 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1824 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1825 return m_data.end();
1828 iterator erase(const_iterator iter)
1830 static_cast<void>(iter);
1831 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1832 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1833 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1834 return m_data.end();
1837 iterator erase(const_iterator from, const_iterator to)
1840 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1841 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1842 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1844 return m_data.end();
1847 void push_back(
const T& value)
1849 static_cast<void>(value);
1850 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1851 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1852 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1855 void push_back(T&& value)
1857 static_cast<void>(value);
1858 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1859 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1860 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1863 template <
typename... TArgs>
1864 void emplace_back(TArgs&&...)
1866 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1867 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1868 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1873 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1874 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1875 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1878 void resize(size_type count)
1884 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1885 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1886 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1889 void resize(size_type count,
const value_type& value)
1891 static_cast<void>(value);
1896 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1897 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1898 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1901 template <std::
size_t TOtherSize>
1902 void swap(StaticVector<T, TOtherSize>& other)
1904 static_cast<void>(other);
1905 if (TOtherSize != 0U) {
1906 static constexpr bool Must_not_be_called_for_zero_sized_vector =
false;
1907 static_cast<void>(Must_not_be_called_for_zero_sized_vector);
1908 COMMS_ASSERT(Must_not_be_called_for_zero_sized_vector);
1919template <
typename T, std::
size_t TSize1, std::
size_t TSize2>
1922 return std::lexicographical_compare(v1.begin(), v1.end(), v2.begin(), v2.end());
1928template <
typename T, std::
size_t TSize1, std::
size_t TSize2>
1937template <
typename T, std::
size_t TSize1, std::
size_t TSize2>
1946template <
typename T, std::
size_t TSize1, std::
size_t TSize2>
1955template <
typename T, std::
size_t TSize1, std::
size_t TSize2>
1958 return (v1.size() == v2.size()) &&
1966template <
typename T, std::
size_t TSize1, std::
size_t TSize2>
1975template <
typename T>
1976struct IsStaticVector
1978 static const bool Value =
false;
1981template <
typename T, std::
size_t TSize>
1984 static const bool Value =
true;
1992template <
typename T>
1995 return details::IsStaticVector<T>::Value;
2008template <
typename T, std::
size_t TSize1, std::
size_t TSize2>
2016COMMS_MSVC_WARNING_POP
2017COMMS_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:168
Contains various compiler related definitions.
Replacement to std::vector when no dynamic memory allocation is allowed.
Definition StaticVector.h:958
const_iterator cend() const
Returns an iterator to the end.
Definition StaticVector.h:1214
void assign(std::initializer_list< value_type > init)
Assigns values to the container.
Definition StaticVector.h:1090
reference at(size_type pos)
Access specified element with bounds checking.
Definition StaticVector.h:1101
size_type max_size() const
Returns the maximum possible number of elements.
Definition StaticVector.h:1279
typename Base::const_reference const_reference
Const reference to single element.
Definition StaticVector.h:982
void assign(size_type count, const T &value)
Assigns values to the container.
Definition StaticVector.h:1075
void resize(size_type count)
Changes the number of elements stored.
Definition StaticVector.h:1409
const_reverse_iterator rbegin() const
Returns a reverse iterator to the beginning.
Definition StaticVector.h:1228
iterator begin()
Returns an iterator to the beginning.
Definition StaticVector.h:1179
static constexpr bool isStaticVector()
Compile time check whether the provided type is a variant of comms::util::StaticVector.
Definition StaticVector.h:1993
void swap(StaticVector< T, TOtherSize > &other)
Swaps the contents.
Definition StaticVector.h:1426
const_iterator begin() const
Returns an iterator to the beginning.
Definition StaticVector.h:1186
const_reference at(size_type pos) const
Access specified element with bounds checking.
Definition StaticVector.h:1112
StaticVector(TIter from, TIter to)
Constructor.
Definition StaticVector.h:1022
typename Base::reference reference
Reference to single element.
Definition StaticVector.h:979
StaticVector(const StaticVector< T, TOtherSize > &other)
Copy constructor.
Definition StaticVector.h:1030
bool operator!=(const StaticVector< T, TSize1 > &v1, const StaticVector< T, TSize2 > &v2)
Lexicographically compares the values in the vector.
Definition StaticVector.h:1967
StaticVector(size_type count)
Constructor.
Definition StaticVector.h:1014
StaticVector(const StaticVector &other)
Copy constructor.
Definition StaticVector.h:1037
iterator insert(const_iterator iter, std::initializer_list< value_type > init)
Inserts elements.
Definition StaticVector.h:1346
const_reference operator[](size_type pos) const
Access specified element without bounds checking.
Definition StaticVector.h:1126
size_type capacity() const
Returns the number of elements that can be held in currently allocated storage.
Definition StaticVector.h:1296
void assign(TIter from, TIter to)
Assigns values to the container.
Definition StaticVector.h:1083
reference front()
Access the first element.
Definition StaticVector.h:1134
const_reference back() const
Access the last element.
Definition StaticVector.h:1158
void clear()
Clears the contents.
Definition StaticVector.h:1310
reference back()
Access the last element.
Definition StaticVector.h:1150
const_reference front() const
Access the first element.
Definition StaticVector.h:1142
bool operator<(const StaticVector< T, TSize1 > &v1, const StaticVector< T, TSize2 > &v2)
Lexicographically compares the values in the vector.
Definition StaticVector.h:1920
bool operator<=(const StaticVector< T, TSize1 > &v1, const StaticVector< T, TSize2 > &v2)
Lexicographically compares the values in the vector.
Definition StaticVector.h:1929
iterator insert(const_iterator iter, T &&value)
Inserts elements.
Definition StaticVector.h:1324
const_iterator end() const
Returns an iterator to the end.
Definition StaticVector.h:1207
typename Base::size_type size_type
Type used for size information.
Definition StaticVector.h:973
StaticVector(std::initializer_list< value_type > init)
Constructor.
Definition StaticVector.h:1044
StaticVector()=default
Default constructor.
StaticVector(size_type count, const T &value)
Constructor.
Definition StaticVector.h:1007
const_reverse_iterator rend() const
Returns a reverse iterator to the end.
Definition StaticVector.h:1249
void pop_back()
Removes the last element.
Definition StaticVector.h:1401
void resize(size_type count, const value_type &value)
Changes the number of elements stored.
Definition StaticVector.h:1417
void shrink_to_fit()
Reduces memory usage by freeing unused memory.
Definition StaticVector.h:1304
typename Base::iterator iterator
Type of the iterator.
Definition StaticVector.h:991
iterator insert(const_iterator iter, TIter from, TIter to)
Inserts elements.
Definition StaticVector.h:1339
const_reverse_iterator crbegin() const
Returns a reverse iterator to the beginning.
Definition StaticVector.h:1235
iterator insert(const_iterator iter, const T &value)
Inserts elements.
Definition StaticVector.h:1317
reverse_iterator rend()
Returns a reverse iterator to the end.
Definition StaticVector.h:1242
reverse_iterator rbegin()
Returns a reverse iterator to the beginning.
Definition StaticVector.h:1221
typename Base::StorageType::difference_type difference_type
Type used in pointer arithmetics.
Definition StaticVector.h:976
iterator end()
Returns an iterator to the end.
Definition StaticVector.h:1200
bool operator>(const StaticVector< T, TSize1 > &v1, const StaticVector< T, TSize2 > &v2)
Lexicographically compares the values in the vector.
Definition StaticVector.h:1938
void push_back(const T &value)
Adds an element to the end.
Definition StaticVector.h:1376
typename Base::value_type value_type
Type of single element.
Definition StaticVector.h:970
iterator erase(const_iterator from, const_iterator to)
Erases elements.
Definition StaticVector.h:1368
void swap(comms::util::StaticVector< T, TSize1 > &v1, comms::util::StaticVector< T, TSize2 > &v2)
Specializes the std::swap algorithm.
Definition StaticVector.h:2009
void reserve(size_type new_cap)
Reserves storage.
Definition StaticVector.h:1287
iterator insert(const_iterator iter, size_type count, const T &value)
Inserts elements.
Definition StaticVector.h:1331
size_type size() const
Returns the number of elements.
Definition StaticVector.h:1270
typename Base::const_reverse_iterator const_reverse_iterator
Type of the const reverse iterator.
Definition StaticVector.h:1000
bool operator==(const StaticVector< T, TSize1 > &v1, const StaticVector< T, TSize2 > &v2)
Lexicographically compares the values in the vector.
Definition StaticVector.h:1956
void push_back(T &&value)
Adds an element to the end.
Definition StaticVector.h:1384
typename Base::const_pointer const_pointer
Const pointer to single element.
Definition StaticVector.h:988
bool operator>=(const StaticVector< T, TSize1 > &v1, const StaticVector< T, TSize2 > &v2)
Lexicographically compares the values in the vector.
Definition StaticVector.h:1947
iterator emplace(const_iterator iter, TArgs &&... args)
Constructs elements in place.
Definition StaticVector.h:1354
void emplace_back(TArgs &&... args)
Constructs an element in place at the end.
Definition StaticVector.h:1393
typename Base::const_iterator const_iterator
Type of the const iterator.
Definition StaticVector.h:994
~StaticVector() noexcept=default
Destructor.
iterator erase(const_iterator iter)
Erases elements.
Definition StaticVector.h:1361
StaticVector & operator=(std::initializer_list< value_type > init)
Copy assignement.
Definition StaticVector.h:1067
bool empty() const
Checks whether the container is empty.
Definition StaticVector.h:1263
const_pointer data() const
Direct access to the underlying array.
Definition StaticVector.h:1172
pointer data()
Direct access to the underlying array.
Definition StaticVector.h:1165
typename Base::reverse_iterator reverse_iterator
Type of the reverse iterator.
Definition StaticVector.h:997
typename Base::pointer pointer
Pointer to single element.
Definition StaticVector.h:985
const_reverse_iterator crend() const
Returns a reverse iterator to the end.
Definition StaticVector.h:1256
reference operator[](size_type pos)
Access specified element without bounds checking.
Definition StaticVector.h:1119
const_iterator cbegin() const
Returns an iterator to the beginning.
Definition StaticVector.h:1193
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.