17#include "comms/util/SizeToType.h"
30COMMS_MSVC_WARNING_PUSH
31COMMS_MSVC_WARNING_DISABLE(4324)
46 template <
typename TDerived,
typename TQueueType>
54 using StorageType = comms::util::AlignedStorage<
sizeof(ValueType), std::alignment_of<ValueType>::value>;
55 using StorageTypePtr = StorageType*;
56 using ConstStorageTypePtr =
const StorageType*;
57 using SizeType = std::size_t;
58 using Reference = ValueType&;
59 using ConstReference =
const ValueType&;
60 using Pointer = ValueType*;
61 using ConstPointer =
const ValueType*;
62 using LinearisedIterator = Pointer;
63 using ConstLinearisedIterator = ConstPointer;
64 using ReverseLinearisedIterator = std::reverse_iterator<LinearisedIterator>;
65 using ConstReverseLinearisedIterator = std::reverse_iterator<ConstLinearisedIterator>;
66 using LinearisedIteratorRange = std::pair<LinearisedIterator, LinearisedIterator>;
67 using ConstLinearisedIteratorRange = std::pair<ConstLinearisedIterator, ConstLinearisedIterator>;
69 StaticQueueBase(StorageTypePtr data, std::size_t capacity)
77 StaticQueueBase(
const StaticQueueBase&) =
delete;
78 StaticQueueBase(StaticQueueBase&&) =
delete;
80 ~StaticQueueBase() noexcept
85 StaticQueueBase& operator=(
const StaticQueueBase& other)
92 assignElements(other);
96 StaticQueueBase& operator=(StaticQueueBase&& other)
103 assignElements(std::move(other));
107 constexpr std::size_t capacity()
const
112 std::size_t size()
const
126 return (size() == 0);
131 return (size() == capacity());
140 ConstReference front()
const
148 auto constThis =
static_cast<const StaticQueueBase*
>(
this);
149 return const_cast<Reference
>(constThis->back());
152 ConstReference back()
const
159 return (*
this)[m_count - 1];
171 Reference element = front();
176 if ((capacity() <= m_startIdx) ||
182 void popFront(std::size_t count)
185 while ((!empty()) && (count > 0)) {
200 Reference element = back();
206 void popBack(std::size_t count)
209 while ((!empty()) && (count > 0)) {
215 Reference operator[](std::size_t index)
217 auto constThis =
static_cast<const StaticQueueBase*
>(
this);
218 return const_cast<Reference
>((*constThis)[index]);
221 ConstReference operator[](std::size_t index)
const
224 return elementAtIndex(index);
227 Reference at(std::size_t index)
229 auto constThis =
static_cast<const StaticQueueBase*
>(
this);
230 return const_cast<Reference
>(constThis->at(index));
233 ConstReference at(std::size_t index)
const
235 if (index >= size()) {
236 throw std::out_of_range(std::string(
"Index is out of range"));
238 return (*
this)[index];
241 int indexOf(ConstReference element)
const
243 ConstPointer elementPtr = &element;
244 auto cellPtr =
reinterpret_cast<ConstStorageTypePtr
>(elementPtr);
245 if ((cellPtr < &m_data[0]) ||
246 (&m_data[capacity()] <= cellPtr)) {
251 auto rawIdx = cellPtr - &m_data[0];
252 std::size_t actualIdx = capacity();
253 if (rawIdx < m_startIdx) {
254 actualIdx = (capacity() - m_startIdx) + rawIdx;
257 actualIdx = rawIdx - m_startIdx;
260 if (size() <= actualIdx)
269 LinearisedIterator invalidIter()
271 return reinterpret_cast<LinearisedIterator
>(&m_data[capacity()]);
274 ConstLinearisedIterator invalidIter()
const
276 return reinterpret_cast<LinearisedIterator
>(&m_data[capacity()]);
279 ReverseLinearisedIterator invalidReverseIter()
281 return ReverseLinearisedIterator(
282 reinterpret_cast<LinearisedIterator
>(&m_data[0]));
285 ConstReverseLinearisedIterator invalidReverseIter()
const
287 return ReverseLinearisedIterator(
288 reinterpret_cast<LinearisedIterator
>(&m_data[0]));
291 LinearisedIterator lbegin()
294 return invalidIter();
297 return reinterpret_cast<LinearisedIterator
>(&m_data[0] + m_startIdx);
300 ConstLinearisedIterator lbegin()
const
305 ConstLinearisedIterator clbegin()
const
308 return invalidIter();
311 return reinterpret_cast<LinearisedIterator
>(&m_data[0] + m_startIdx);
314 ReverseLinearisedIterator rlbegin()
317 return invalidReverseIter();
320 return ReverseLinearisedIterator(lend());
323 ConstReverseLinearisedIterator rlbegin()
const
328 ConstReverseLinearisedIterator crlbegin()
const
331 return invalidReverseIter();
333 return ConstReverseLinearisedIterator(lend());
336 LinearisedIterator lend()
339 return invalidIter();
342 return lbegin() + size();
345 ConstLinearisedIterator lend()
const
350 ConstLinearisedIterator clend()
const
353 return invalidIter();
356 return clbegin() + size();
359 ReverseLinearisedIterator rlend()
362 return invalidReverseIter();
365 return rlbegin() + size();
368 ConstReverseLinearisedIterator rlend()
const
373 ConstReverseLinearisedIterator crlend()
const
376 return invalidReverseIter();
379 return rlbegin() + size();
389 auto rangeOne = arrayOne();
390 auto rangeOneSize = std::distance(rangeOne.first, rangeOne.second);
392 auto rangeTwo = arrayTwo();
393 auto rangeTwoSize = std::distance(rangeTwo.first, rangeTwo.second);
396 auto remSpaceSize = capacity() - size();
398 if (rangeTwoSize <= remSpaceSize) {
399 lineariseByMoveOneTwo(rangeOne, rangeTwo);
403 if (rangeOneSize <= remSpaceSize) {
404 lineariseByMoveTwoOne(rangeOne, rangeTwo);
408 if (rangeOneSize < rangeTwoSize) {
415 bool linearised()
const
417 return (empty() || ((m_startIdx + size()) <= capacity()));
420 LinearisedIteratorRange arrayOne()
422 auto constThis =
static_cast<const StaticQueueBase*
>(
this);
423 auto constRange = constThis->arrayOne();
425 LinearisedIteratorRange(
426 const_cast<LinearisedIterator
>(constRange.first),
427 const_cast<LinearisedIterator
>(constRange.second));
430 ConstLinearisedIteratorRange arrayOne()
const
432 auto begCell = &m_data[m_startIdx];
433 auto endCell = std::min(&m_data[m_startIdx + size()], &m_data[capacity()]);
435 ConstLinearisedIteratorRange(
436 reinterpret_cast<ConstLinearisedIterator
>(begCell),
437 reinterpret_cast<ConstLinearisedIterator
>(endCell));
440 LinearisedIteratorRange arrayTwo()
442 auto constThis =
static_cast<const StaticQueueBase*
>(
this);
443 auto constRange = constThis->arrayTwo();
445 LinearisedIteratorRange(
446 const_cast<LinearisedIterator
>(constRange.first),
447 const_cast<LinearisedIterator
>(constRange.second));
450 ConstLinearisedIteratorRange arrayTwo()
const
453 auto iter = arrayOne().second;
454 return ConstLinearisedIteratorRange(iter, iter);
457 auto begCell = &m_data[0];
458 auto endCell = &m_data[(m_startIdx + size()) - capacity()];
461 ConstLinearisedIteratorRange(
462 reinterpret_cast<ConstLinearisedIterator
>(begCell),
463 reinterpret_cast<ConstLinearisedIterator
>(endCell));
466 void resize(std::size_t newSize)
469 if (capacity() < newSize) {
473 if (size() <= newSize) {
474 while (size() < newSize) {
475 pushBackNotFull(ValueType());
482 popBack(size() - newSize);
485 LinearisedIterator erase(LinearisedIterator pos)
489 auto rangeOne = arrayOne();
490 auto rangeTwo = arrayTwo();
493 [](LinearisedIterator pos,
const LinearisedIteratorRange range) ->
bool
495 return ((range.first <= pos) && (pos < range.second));
499 isInRangeFunc(pos, rangeTwo));
501 if (isInRangeFunc(pos, rangeOne)) {
502 std::move_backward(rangeOne.first, pos, pos + 1);
505 rangeOne = arrayOne();
506 if (isInRangeFunc(pos, rangeOne)) {
510 return rangeOne.first;
513 if (isInRangeFunc(pos, rangeTwo)) {
514 std::move(pos + 1, rangeTwo.second, pos);
519 return arrayOne().second;
522 static constexpr bool Invalid_iterator_is_used =
false;
523 static_cast<void>(Invalid_iterator_is_used);
525 return invalidIter();
528 Iterator erase(Iterator pos)
532 Pointer elem = &(*pos);
533 auto rangeOne = arrayOne();
534 auto rangeTwo = arrayTwo();
537 [](Pointer elemPtr,
const LinearisedIteratorRange range) ->
bool
539 return ((&(*range.first) <= elemPtr) && (elemPtr < &(*range.second)));
543 isInRangeFunc(elem, rangeTwo));
545 if (isInRangeFunc(elem, rangeOne)) {
546 std::move_backward(rangeOne.first, elem, elem + 1);
549 rangeOne = arrayOne();
550 if (isInRangeFunc(elem, rangeOne)) {
557 if (isInRangeFunc(elem, rangeTwo)) {
558 std::move(elem + 1, rangeTwo.second, elem);
566 static constexpr bool Invalid_iterator_is_used =
false;
567 static_cast<void>(Invalid_iterator_is_used);
574 return Iterator(*
this,
reinterpret_cast<LinearisedIterator
>(&m_data[0]));
577 ConstIterator begin()
const
582 ConstIterator cbegin()
const
584 return ConstIterator(*
this,
reinterpret_cast<ConstLinearisedIterator
>(&m_data[0]));
589 return Iterator(*
this,
reinterpret_cast<LinearisedIterator
>(&m_data[size()]));
592 ConstIterator end()
const
597 ConstIterator cend()
const
599 return ConstIterator(*
this,
reinterpret_cast<ConstLinearisedIterator
>(&m_data[size()]));
602 template <
typename TOther>
603 void assignElements(TOther&& other)
605 static_assert(std::is_base_of<StaticQueueBase, typename std::decay<TOther>::type>::value,
606 "Assignment works only on the same types");
608 using DecayedQueueType =
typename std::decay<
decltype(other)>::type;
609 using NonRefQueueType =
typename std::remove_reference<
decltype(other)>::type;
611 using QueueValueType =
613 std::is_const<NonRefQueueType>::value
615 const typename DecayedQueueType::ValueType,
616 typename DecayedQueueType::ValueType
621 std::is_rvalue_reference<
decltype(other)>::value
623 typename std::add_rvalue_reference<QueueValueType>::type,
624 typename std::add_lvalue_reference<QueueValueType>::type
630 auto rangeOne = other.arrayOne();
631 for (
auto iter = rangeOne.first; iter != rangeOne.second; ++iter) {
632 pushBackNotFull(std::forward<ElemRefType>(*iter));
635 auto rangeTwo = other.arrayTwo();
636 for (
auto iter = rangeTwo.first; iter != rangeTwo.second; ++iter) {
637 pushBackNotFull(std::forward<ElemRefType>(*iter));
641 template <
typename U>
642 void pushBack(U&& value)
648 pushBackNotFull(std::forward<U>(value));
651 template <
typename... TArgs>
652 void emplaceBack(TArgs&&... args)
658 emplaceBackNotFull(std::forward<TArgs>(args)...);
661 template <
typename U>
662 void pushFront(U&& value)
669 pushFrontNotFull(std::forward<U>(value));
672 template <
typename U>
673 LinearisedIterator insert(LinearisedIterator pos, U&& value)
677 return invalidIter();
680 return insertNotFull(pos, std::forward<U>(value));
683 bool operator==(
const StaticQueueBase& other)
const
685 if (size() != other.size()) {
689 auto rangeOne = arrayOne();
690 auto rangeOneSize = std::distance(rangeOne.first, rangeOne.second);
691 auto rangeTwo = arrayTwo();
692 auto otherRangeOne = other.arrayOne();
693 auto otherRangeOneSize = std::distance(otherRangeOne.first, otherRangeOne.second);
694 auto otherRangeTwo = other.arrayTwo();
696 auto firstCompSize = std::min(rangeOneSize, otherRangeOneSize);
697 auto firstCompEnd = rangeOne.first + firstCompSize;
699 auto currIter = rangeOne.first;
700 auto otherCurrIter = otherRangeOne.first;
701 if (!std::equal(currIter, firstCompEnd, otherCurrIter)) {
705 currIter = firstCompEnd;
706 otherCurrIter += firstCompSize;
708 if (currIter != rangeOne.first) {
709 otherCurrIter = otherRangeTwo.first;
710 if (!std::equal(currIter, rangeOne.second, otherCurrIter)) {
713 otherCurrIter += rangeOne.second - currIter;
714 currIter = rangeTwo.first;
717 currIter = rangeTwo.first;
718 if (!std::equal(otherCurrIter, otherRangeOne.second, currIter)) {
722 currIter += otherRangeOne.second - otherCurrIter;
723 otherCurrIter = otherRangeOne.first;
726 COMMS_ASSERT(std::distance(currIter, rangeTwo.second) == std::distance(otherCurrIter, otherRangeTwo.second));
727 return std::equal(currIter, rangeTwo.second, otherCurrIter);
730 bool operator!=(
const StaticQueueBase& other)
const
732 return !(*
this == other);
737 template <
typename U>
738 void createValueAtIndex(U&& value, std::size_t index)
741 Reference elementRef = elementAtIndex(index);
742 auto elementPtr =
new(&elementRef) ValueType(std::forward<U>(value));
743 static_cast<void>(elementPtr);
746 template <
typename U>
747 void pushBackNotFull(U&& value)
750 createValueAtIndex(std::forward<U>(value), size());
754 template <
typename... TArgs>
755 void emplaceBackNotFull(TArgs&&... args)
758 Reference elementRef = elementAtIndex(size());
759 auto elementPtr =
new(&elementRef) ValueType(std::forward<TArgs>(args)...);
760 static_cast<void>(elementPtr);
764 template <
typename U>
765 void pushFrontNotFull(U&& value)
768 createValueAtIndex(std::forward<U>(value), capacity() - 1);
769 if (m_startIdx == 0) {
770 m_startIdx = capacity() - 1;
779 template <
typename U>
780 LinearisedIterator insertNotFull(LinearisedIterator pos, U&& value)
784 auto rangeOne = arrayOne();
785 auto rangeTwo = arrayTwo();
787 if (pos == rangeOne.first) {
788 pushFrontNotFull(std::forward<U>(value));
789 return arrayOne().first;
792 if (pos == rangeTwo.second) {
793 pushBackNotFull(std::forward<U>(value));
794 return arrayTwo().second - 1;
797 auto isInRangeFunc = [](LinearisedIterator pos,
const LinearisedIteratorRange range) ->
bool
799 return ((range.first <= pos) && (pos < range.second));
803 isInRangeFunc(pos, rangeTwo));
805 if (isInRangeFunc(pos, rangeOne)) {
806 pushFrontNotFull(std::move(front()));
808 std::move(rangeOne.first + 1, pos, rangeOne.first);
809 *pos = std::forward<U>(value);
813 if (isInRangeFunc(pos, rangeTwo)) {
814 pushBackNotFull(std::move(back()));
815 std::move_backward(pos, rangeTwo.second - 1, rangeTwo.second);
816 *pos = std::forward<U>(value);
820 return invalidIter();
823 Reference elementAtIndex(std::size_t index) {
824 auto constThis =
static_cast<const StaticQueueBase*
>(
this);
825 return const_cast<Reference
>(constThis->elementAtIndex(index));
828 ConstReference elementAtIndex(std::size_t index)
const
830 std::size_t rawIdx = m_startIdx + index;
831 while (capacity() <= rawIdx) {
832 rawIdx = rawIdx - capacity();
835 auto cellAddr = &m_data[rawIdx];
836 return *(
reinterpret_cast<ConstPointer
>(cellAddr));
839 template <
typename TIter>
840 void lineariseByMove(
841 const std::pair<TIter, TIter> firstRange,
842 const std::pair<TIter, TIter> secondRange)
844 auto movConstructFirstSize =
846 std::size_t(std::distance(firstRange.first, firstRange.second)),
847 capacity() - size());
848 auto movConstructFirstEnd = firstRange.first + movConstructFirstSize;
849 COMMS_ASSERT(movConstructFirstEnd <= firstRange.second);
850 COMMS_ASSERT(movConstructFirstSize <= (firstRange.second - firstRange.first));
852 auto newPlacePtr = secondRange.second;
853 for (
auto iter = firstRange.first; iter != movConstructFirstEnd; ++iter) {
854 auto ptr =
new (&(*newPlacePtr)) ValueType(std::move(*iter));
855 static_cast<void>(ptr);
859 std::move(movConstructFirstEnd, firstRange.second, newPlacePtr);
860 newPlacePtr += (firstRange.second - movConstructFirstEnd);
862 auto movConstructTwoSize = 0;
863 if (newPlacePtr < firstRange.first) {
864 movConstructTwoSize =
865 std::min(std::distance(newPlacePtr, firstRange.first),
866 std::distance(secondRange.first, secondRange.second));
869 auto movConstructTwoEnd = secondRange.first + movConstructTwoSize;
870 for (
auto iter = secondRange.first; iter != movConstructTwoEnd; ++iter) {
871 auto ptr =
new (&(*newPlacePtr)) ValueType(std::move(*iter));
872 static_cast<void>(ptr);
876 std::move(movConstructTwoEnd, secondRange.second, newPlacePtr);
877 newPlacePtr += (secondRange.second - movConstructTwoEnd);
879 for (
auto iter = std::max(newPlacePtr, firstRange.first); iter != firstRange.second; ++iter) {
883 for (
auto iter = secondRange.first; iter != secondRange.second; ++iter) {
888 void lineariseByMoveOneTwo(
889 const LinearisedIteratorRange& rangeOne,
890 const LinearisedIteratorRange& rangeTwo)
892 lineariseByMove(rangeOne, rangeTwo);
893 m_startIdx = std::distance(rangeTwo.first, rangeTwo.second);
896 void lineariseByMoveTwoOne(
897 const LinearisedIteratorRange& rangeOne,
898 const LinearisedIteratorRange& rangeTwo)
900 using RevIter = std::reverse_iterator<Pointer>;
902 std::make_pair(RevIter(rangeTwo.second), RevIter(rangeTwo.first)),
903 std::make_pair(RevIter(rangeOne.second), RevIter(rangeOne.first)));
905 m_startIdx = (capacity() - std::distance(rangeOne.first, rangeOne.second)) - size();
908 void lineariseByPopOne()
914 ValueType tmp(std::move(front()));
917 if (m_startIdx == 0) {
918 using RevIter = std::reverse_iterator<LinearisedIterator>;
920 RevIter(
reinterpret_cast<LinearisedIterator
>(&m_data[capacity()]));
921 moveRange(rlbegin(), rlend(), target);
922 m_startIdx = capacity() - size();
924 pushFront(std::move(tmp));
928 void lineariseByPopTwo()
934 ValueType tmp(std::move(back()));
937 if (m_startIdx != 0) {
938 auto target =
reinterpret_cast<LinearisedIterator
>(&m_data[0]);
939 moveRange(lbegin(), lend(), target);
942 pushBack(std::move(tmp));
946 template <
typename TIter>
947 void moveRange(TIter rangeBeg, TIter rangeEnd, TIter target)
950 auto moveConstructSize =
952 std::distance(rangeBeg, rangeEnd),
953 std::distance(target, rangeBeg));
955 TIter moveConstructEnd = rangeBeg + moveConstructSize;
956 for (
auto iter = rangeBeg; iter != moveConstructEnd; ++iter) {
957 auto ptr =
new (&(*target)) ValueType(std::move(*iter));
958 static_cast<void>(ptr);
963 std::move(moveConstructEnd, rangeEnd, target);
964 target += std::distance(moveConstructEnd, rangeEnd);
966 for (
auto iter = std::max(target, rangeBeg); iter != rangeEnd; ++iter) {
971 StorageTypePtr
const m_data;
972 const std::size_t m_capacity;
973 std::size_t m_startIdx;
978template <
typename TDerived,
typename TQueueType>
979class StaticQueueBase<T>::IteratorBase
981 friend class StaticQueueBase<T>;
984 IteratorBase(
const IteratorBase&) =
default;
986 ~IteratorBase() noexcept = default;
989 using Derived = TDerived;
990 using QueueType = TQueueType;
991 using ArrayIterator = decltype(
std::declval<QueueType>().lbegin());
992 using IteratorCategory = typename
std::iterator_traits<ArrayIterator>::iterator_category;
993 using iterator_category = IteratorCategory;
994 using ValueType = typename
std::iterator_traits<ArrayIterator>::value_type;
995 using value_type = ValueType;
996 using DifferenceType = typename
std::iterator_traits<ArrayIterator>::difference_type;
997 using difference_type = DifferenceType;
998 using Pointer = typename
std::iterator_traits<ArrayIterator>::pointer;
999 using pointer = Pointer;
1000 using ConstPointer =
1001 typename
std::add_pointer<
1002 typename
std::add_const<
1003 typename
std::remove_pointer<Pointer>::type
1006 using Reference = typename
std::iterator_traits<ArrayIterator>::reference;
1007 using reference = Reference;
1008 using ConstReference = typename
std::add_const<Reference>::type;
1010 IteratorBase(QueueType& queue, ArrayIterator iterator)
1012 m_iterator(iterator)
1016 Derived& operator=(
const IteratorBase& other)
1019 m_iterator = other.m_iterator;
1020 return static_cast<Derived&
>(*this);
1023 Derived& operator++()
1026 return static_cast<Derived&
>(*this);
1029 Derived operator++(
int)
1031 IteratorBase copy(*
this);
1033 return std::move(*(
static_cast<Derived*
>(©)));
1036 Derived& operator--()
1039 return static_cast<Derived&
>(*this);
1042 Derived operator--(
int)
1044 IteratorBase copy(*
this);
1046 return std::move(*(
static_cast<Derived*
>(©)));
1049 Derived& operator+=(DifferenceType value)
1051 m_iterator += value;
1052 return static_cast<Derived&
>(*this);
1055 Derived& operator-=(DifferenceType value)
1057 m_iterator -= value;
1058 return static_cast<Derived&
>(*this);
1061 Derived operator+(DifferenceType value)
const
1063 IteratorBase copy(*
this);
1065 return std::move(*(
static_cast<Derived*
>(©)));
1068 Derived operator-(DifferenceType value)
const
1070 IteratorBase copy(*
this);
1072 return std::move(*(
static_cast<Derived*
>(©)));
1075 DifferenceType operator-(
const IteratorBase& other)
const
1077 return m_iterator - other.m_iterator;
1080 bool operator==(
const IteratorBase& other)
const
1082 return (m_iterator == other.m_iterator);
1085 bool operator!=(
const IteratorBase& other)
const
1087 return (m_iterator != other.m_iterator);
1090 bool operator<(
const IteratorBase& other)
const
1092 return m_iterator < other.m_iterator;
1095 bool operator<=(
const IteratorBase& other)
const
1097 return m_iterator <= other.m_iterator;
1100 bool operator>(
const IteratorBase& other)
const
1102 return m_iterator > other.m_iterator;
1105 bool operator>=(
const IteratorBase& other)
const
1107 return m_iterator >= other.m_iterator;
1110 Reference operator*()
1112 auto& constThisRef =
static_cast<const IteratorBase&
>(*this);
1113 auto& constRef = *constThisRef;
1114 return const_cast<Reference
>(constRef);
1117 ConstReference operator*()
const
1119 auto begCell =
reinterpret_cast<ArrayIterator
>(&m_queue.m_data[0]);
1120 auto idx = m_iterator - begCell;
1122 return m_queue[
static_cast<std::size_t
>(idx)];
1125 Pointer operator->()
1130 ConstPointer operator->()
const
1135 QueueType& getQueue() {
1139 typename std::add_const<QueueType&>::type getQueue()
const
1144 ArrayIterator& getIterator() {
1148 typename std::add_const<ArrayIterator>::type& getIterator()
const
1156 ArrayIterator m_iterator;
1159template <
typename T>
1160class StaticQueueBase<T>::ConstIterator :
1161 public StaticQueueBase<T>::template
1162 IteratorBase<typename StaticQueueBase<T>::ConstIterator, const StaticQueueBase<T> >
1164 using Base =
typename StaticQueueBase<T>::template
1165 IteratorBase<typename StaticQueueBase<T>::ConstIterator,
const StaticQueueBase<T> >;
1168 using QueueType =
typename Base::QueueType;
1169 using ArrayIterator =
typename Base::ArrayIterator;
1171 ConstIterator(
const ConstIterator&) =
default;
1172 ~ConstIterator() noexcept = default;
1174 ConstIterator(QueueType& queue, ArrayIterator iterator)
1175 : Base(queue, iterator)
1181template <
typename T>
1182class StaticQueueBase<T>::Iterator :
1183 public StaticQueueBase<T>::template
1184 IteratorBase<typename StaticQueueBase<T>::Iterator, StaticQueueBase<T> >
1186 using Base =
typename StaticQueueBase<T>::template
1187 IteratorBase<typename StaticQueueBase<T>::Iterator, StaticQueueBase<T> >;
1190 using QueueType =
typename Base::QueueType;
1191 using ArrayIterator =
typename Base::ArrayIterator;
1193 Iterator(
const Iterator&) =
default;
1194 ~Iterator() noexcept = default;
1196 Iterator(QueueType& queue, ArrayIterator iterator)
1197 : Base(queue, iterator)
1201 operator ConstIterator()
const
1203 return ConstIterator(Base::getQueue(), Base::getIterator());
1207template <
typename TWrapperElemType,
typename TQueueElemType>
1208class CastWrapperQueueBase :
public StaticQueueBase<TQueueElemType>
1210 using Base = StaticQueueBase<TQueueElemType>;
1211 using WrapperElemType = TWrapperElemType;
1213 using BaseValueType =
typename Base::ValueType;
1214 using BaseStorageTypePtr =
typename Base::StorageTypePtr;
1215 using BaseReference =
typename Base::Reference;
1216 using BaseConstReference =
typename Base::ConstReference;
1217 using BasePointer =
typename Base::Pointer;
1218 using BaseConstPointer =
typename Base::ConstPointer;
1219 using BaseLinearisedIterator =
typename Base::LinearisedIterator;
1220 using BaseConstLinearisedIterator =
typename Base::ConstLinearisedIterator;
1221 using BaseReverseLinearisedIterator =
typename Base::ReverseLinearisedIterator;
1222 using BaseConstReverseLinearisedIterator =
typename Base::ConstReverseLinearisedIterator;
1223 using BaseLinearisedIteratorRange =
typename Base::LinearisedIteratorRange;
1224 using BaseConstLinearisedIteratorRange =
typename Base::ConstLinearisedIteratorRange;
1228 class ConstIterator;
1232 using ValueType = WrapperElemType;
1233 using StorageType = comms::util::AlignedStorage<
sizeof(ValueType), std::alignment_of<ValueType>::value>;
1234 using StorageTypePtr = StorageType*;
1235 using Reference = ValueType&;
1236 using ConstReference =
const ValueType&;
1237 using Pointer = ValueType*;
1238 using ConstPointer =
const ValueType*;
1239 using LinearisedIterator = Pointer;
1240 using ConstLinearisedIterator = ConstPointer;
1241 using ReverseLinearisedIterator = std::reverse_iterator<LinearisedIterator>;
1242 using ConstReverseLinearisedIterator = std::reverse_iterator<ConstLinearisedIterator>;
1243 using LinearisedIteratorRange = std::pair<LinearisedIterator, LinearisedIterator>;
1244 using ConstLinearisedIteratorRange = std::pair<ConstLinearisedIterator, ConstLinearisedIterator>;
1246 CastWrapperQueueBase(StorageTypePtr data, std::size_t capacity)
1247 : Base(reinterpret_cast<BaseStorageTypePtr>(data), capacity)
1249 static_assert(
sizeof(ValueType) ==
sizeof(BaseValueType),
1250 "The times must have identical size.");
1253 ~CastWrapperQueueBase() noexcept = default;
1255 CastWrapperQueueBase& operator=(const CastWrapperQueueBase& other) = default;
1256 CastWrapperQueueBase& operator=(CastWrapperQueueBase&& other) = default;
1260 return reinterpret_cast<Reference
>(Base::front());
1263 ConstReference front()
const
1265 return reinterpret_cast<ConstReference
>(Base::front());
1270 return reinterpret_cast<Reference
>(Base::back());
1273 ConstReference back()
const
1275 return reinterpret_cast<Reference
>(Base::back());
1278 Reference operator[](std::size_t index)
1280 return reinterpret_cast<Reference
>(Base::operator[](index));
1283 ConstReference operator[](std::size_t index)
const
1285 return reinterpret_cast<ConstReference
>(Base::operator[](index));
1288 Reference at(std::size_t index)
1290 return reinterpret_cast<Reference
>(Base::at(index));
1293 ConstReference at(std::size_t index)
const
1295 return reinterpret_cast<ConstReference
>(Base::at(index));
1298 int indexOf(ConstReference element)
const
1300 return Base::indexOf(
reinterpret_cast<BaseConstReference
>(element));
1303 LinearisedIterator invalidIter()
1305 return reinterpret_cast<LinearisedIterator
>(Base::invalidIter());
1308 ConstLinearisedIterator invalidIter()
const
1310 return reinterpret_cast<ConstLinearisedIterator
>(Base::invalidIter());
1313 ReverseLinearisedIterator invalidReverseIter()
1315 return ReverseLinearisedIterator(
1316 reinterpret_cast<LinearisedIterator
>(
1317 Base::invalidReverseIter().base()));
1320 ConstReverseLinearisedIterator invalidReverseIter()
const
1322 return ConstReverseLinearisedIterator(
1323 reinterpret_cast<ConstLinearisedIterator
>(
1324 Base::invalidReverseIter().base()));
1327 LinearisedIterator lbegin()
1329 return reinterpret_cast<LinearisedIterator
>(Base::lbegin());
1332 ConstLinearisedIterator lbegin()
const
1334 return reinterpret_cast<ConstLinearisedIterator
>(Base::lbegin());
1337 ConstLinearisedIterator clbegin()
const
1339 return reinterpret_cast<ConstLinearisedIterator
>(Base::clbegin());
1342 ReverseLinearisedIterator rlbegin()
1344 return ReverseLinearisedIterator(
1345 reinterpret_cast<LinearisedIterator
>(
1346 Base::rlbegin().base()));
1349 ConstReverseLinearisedIterator rlbegin()
const
1351 return ConstReverseLinearisedIterator(
1352 reinterpret_cast<ConstLinearisedIterator
>(
1353 Base::rlbegin().base()));
1356 ConstReverseLinearisedIterator crlbegin()
const
1358 return ConstReverseLinearisedIterator(
1359 reinterpret_cast<ConstLinearisedIterator
>(
1360 Base::crlbegin().base()));
1363 LinearisedIterator lend()
1365 return reinterpret_cast<LinearisedIterator
>(Base::lend());
1368 ConstLinearisedIterator lend()
const
1370 return reinterpret_cast<ConstLinearisedIterator
>(Base::lend());
1373 ConstLinearisedIterator clend()
const
1375 return reinterpret_cast<ConstLinearisedIterator
>(Base::clend());
1378 ReverseLinearisedIterator rlend()
1380 return ReverseLinearisedIterator(
1381 reinterpret_cast<LinearisedIterator
>(
1382 Base::rlend().base()));
1385 ConstReverseLinearisedIterator rlend()
const
1387 return ConstReverseLinearisedIterator(
1388 reinterpret_cast<ConstLinearisedIterator
>(
1389 Base::rlend().base()));
1392 ConstReverseLinearisedIterator crlend()
const
1394 return ConstReverseLinearisedIterator(
1395 reinterpret_cast<ConstLinearisedIterator
>(
1396 Base::crlend().base()));
1399 LinearisedIteratorRange arrayOne()
1401 auto range = Base::arrayOne();
1402 return LinearisedIteratorRange(
1403 reinterpret_cast<LinearisedIterator
>(range.first),
1404 reinterpret_cast<LinearisedIterator
>(range.second));
1407 ConstLinearisedIteratorRange arrayOne()
const
1409 auto range = Base::arrayOne();
1410 return ConstLinearisedIteratorRange(
1411 reinterpret_cast<ConstLinearisedIterator
>(range.first),
1412 reinterpret_cast<ConstLinearisedIterator
>(range.second));
1416 LinearisedIteratorRange arrayTwo()
1418 auto range = Base::arrayTwo();
1419 return LinearisedIteratorRange(
1420 reinterpret_cast<LinearisedIterator
>(range.first),
1421 reinterpret_cast<LinearisedIterator
>(range.second));
1425 ConstLinearisedIteratorRange arrayTwo()
const
1427 auto range = Base::arrayTwo();
1428 return ConstLinearisedIteratorRange(
1429 reinterpret_cast<ConstLinearisedIterator
>(range.first),
1430 reinterpret_cast<ConstLinearisedIterator
>(range.second));
1434 LinearisedIterator erase(LinearisedIterator pos)
1436 return reinterpret_cast<LinearisedIterator
>(
1438 reinterpret_cast<BaseLinearisedIterator
>(pos)));
1441 Iterator erase(Iterator pos)
1443 auto tmp = Base::erase(pos);
1444 return *(
reinterpret_cast<Iterator*
>(&tmp));
1449 auto tmp = Base::begin();
1450 return *(
reinterpret_cast<Iterator*
>(&tmp));
1453 ConstIterator begin()
const
1455 auto tmp = Base::begin();
1456 return *(
reinterpret_cast<ConstIterator*
>(&tmp));
1459 ConstIterator cbegin()
const
1461 auto tmp = Base::cbegin();
1462 return *(
reinterpret_cast<ConstIterator*
>(&tmp));
1468 auto tmp = Base::end();
1469 return *(
reinterpret_cast<Iterator*
>(&tmp));
1472 ConstIterator end()
const
1474 auto tmp = Base::end();
1475 return *(
reinterpret_cast<ConstIterator*
>(&tmp));
1478 ConstIterator cend()
const
1480 auto tmp = Base::cend();
1481 return *(
reinterpret_cast<ConstIterator*
>(&tmp));
1484 void pushBack(ConstReference value)
1486 Base::pushBack(
reinterpret_cast<BaseConstReference
>(value));
1489 void pushFront(ConstReference value)
1491 Base::pushFront(
reinterpret_cast<BaseConstReference
>(value));
1494 LinearisedIterator insert(LinearisedIterator pos, ConstReference value)
1496 return reinterpret_cast<LinearisedIterator
>(
1498 reinterpret_cast<BaseLinearisedIterator
>(pos),
1499 reinterpret_cast<BaseConstReference
>(value)));
1502 void assignElements(
const CastWrapperQueueBase& other)
1504 Base::assignElements(
static_cast<const Base&
>(other));
1507 void assignElements(CastWrapperQueueBase&& other)
1509 Base::assignElements(
static_cast<Base&&
>(std::move(other)));
1513template <
typename TWrapperElemType,
typename TQueueElemType>
1514class CastWrapperQueueBase<TWrapperElemType, TQueueElemType>::ConstIterator :
1515 public StaticQueueBase<TQueueElemType>::ConstIterator
1517 using Base =
typename StaticQueueBase<TQueueElemType>::ConstIterator;
1519 ConstIterator(
const ConstIterator&) =
default;
1520 ConstIterator& operator=(
const ConstIterator&) =
default;
1521 ~ConstIterator() noexcept = default;
1524 using ExpectedQueueType = const StaticQueueBase<TWrapperElemType>;
1525 using ActualQueueType = const StaticQueueBase<TQueueElemType>;
1526 using ValueType = TWrapperElemType;
1527 using Reference = const ValueType&;
1528 using ConstReference = const ValueType&;
1529 using Pointer = const ValueType*;
1530 using ConstPointer = const ValueType*;
1531 using DifferenceType = typename Base::DifferenceType;
1533 ConstIterator(ExpectedQueueType& queue, Pointer iterator)
1534 : Base(reinterpret_cast<ActualQueueType&>(queue), iterator)
1538 ConstIterator& operator++()
1544 ConstIterator operator++(
int dummy)
1546 auto tmp = Base::operator++(dummy);
1547 return *(
static_cast<ConstIterator*
>(&tmp));
1550 ConstIterator& operator--()
1556 ConstIterator operator--(
int dummy)
1558 auto tmp = Base::operator--(dummy);
1559 return *(
static_cast<ConstIterator*
>(&tmp));
1562 ConstIterator& operator+=(DifferenceType value)
1564 Base::operator+=(value);
1568 ConstIterator& operator-=(DifferenceType value)
1570 Base::operator-=(value);
1574 ConstIterator operator+(DifferenceType value)
const
1576 auto tmp = Base::operator+(value);
1577 return *(
static_cast<ConstIterator*
>(&tmp));
1580 ConstIterator operator-(DifferenceType value)
const
1582 auto tmp = Base::operator-(value);
1583 return *(
static_cast<ConstIterator*
>(&tmp));
1586 DifferenceType operator-(
const ConstIterator& other)
const
1588 return Base::operator-(other);
1591 Reference operator*()
1593 auto& ref = Base::operator*();
1594 return reinterpret_cast<Reference
>(ref);
1597 ConstReference operator*()
const
1599 auto& ref = Base::operator*();
1600 return reinterpret_cast<ConstReference
>(ref);
1603 Pointer operator->()
1605 auto* ptr = Base::operator->();
1606 return reinterpret_cast<Pointer
>(ptr);
1609 ConstPointer operator->()
const
1611 auto* ptr = Base::operator->();
1612 return reinterpret_cast<ConstPointer
>(ptr);
1616template <
typename TWrapperElemType,
typename TQueueElemType>
1617class CastWrapperQueueBase<TWrapperElemType, TQueueElemType>::Iterator :
1618 public StaticQueueBase<TQueueElemType>::Iterator
1620 using Base =
typename StaticQueueBase<TQueueElemType>::Iterator;
1622 Iterator(
const Iterator&) =
default;
1623 Iterator& operator=(
const Iterator&) =
default;
1624 ~Iterator() noexcept = default;
1627 using ExpectedQueueType = const StaticQueueBase<TWrapperElemType>;
1628 using ActualQueueType = const StaticQueueBase<TQueueElemType>;
1629 using ValueType = TWrapperElemType;
1630 using Reference = ValueType&;
1631 using ConstReference = const ValueType&;
1632 using Pointer = ValueType*;
1633 using ConstPointer = const ValueType*;
1634 using DifferenceType = typename Base::DifferenceType;
1636 Iterator(ExpectedQueueType& queue, Pointer iterator)
1637 : Base(reinterpret_cast<ActualQueueType&>(queue), iterator)
1641 Iterator& operator++()
1647 Iterator operator++(
int dummy)
1649 auto tmp = Base::operator++(dummy);
1650 return *(
static_cast<Iterator*
>(&tmp));
1653 Iterator& operator--()
1659 Iterator operator--(
int dummy)
1661 auto tmp = Base::operator--(dummy);
1662 return *(
static_cast<Iterator*
>(&tmp));
1665 Iterator& operator+=(DifferenceType value)
1667 Base::operator+=(value);
1671 Iterator& operator-=(DifferenceType value)
1673 Base::operator-=(value);
1677 Iterator operator+(DifferenceType value)
const
1679 auto tmp = Base::operator+(value);
1680 return *(
static_cast<Iterator*
>(&tmp));
1683 Iterator operator-(DifferenceType value)
const
1685 auto tmp = Base::operator-(value);
1686 return *(
static_cast<Iterator*
>(&tmp));
1689 DifferenceType operator-(
const Iterator& other)
const
1691 return Base::operator-(other);
1694 Reference operator*()
1696 auto& ref = Base::operator*();
1697 return reinterpret_cast<Reference
>(ref);
1700 ConstReference operator*()
const
1702 auto& ref = Base::operator*();
1703 return reinterpret_cast<ConstReference
>(ref);
1706 Pointer operator->()
1708 auto* ptr = Base::operator->();
1709 return reinterpret_cast<Pointer
>(ptr);
1712 ConstPointer operator->()
const
1714 auto* ptr = Base::operator->();
1715 return reinterpret_cast<ConstPointer
>(ptr);
1719template <
typename T>
1720class StaticQueueBaseOptimised :
public StaticQueueBase<T>
1722 usign Base = StaticQueueBase<T>;
1725 using StorageTypePtr =
typename Base::StorageTypePtr;
1727 StaticQueueBaseOptimised(StorageTypePtr data, std::size_t capacity)
1728 : Base(data, capacity)
1732 ~StaticQueueBaseOptimised() noexcept = default;
1734 StaticQueueBaseOptimised& operator=(const StaticQueueBaseOptimised& other) = default;
1735 StaticQueueBaseOptimised& operator=(StaticQueueBaseOptimised&& other) = default;
1739class StaticQueueBaseOptimised<
std::int8_t> : public CastWrapperQueueBase<
std::int8_t,
std::uint8_t>
1741 using Base = CastWrapperQueueBase<std::int8_t, std::uint8_t>;
1744 using StorageTypePtr =
typename Base::StorageTypePtr;
1746 StaticQueueBaseOptimised(StorageTypePtr data, std::size_t capacity)
1747 : Base(data, capacity)
1751 ~StaticQueueBaseOptimised() noexcept = default;
1752 StaticQueueBaseOptimised& operator=(const StaticQueueBaseOptimised& other) = default;
1753 StaticQueueBaseOptimised& operator=(StaticQueueBaseOptimised&& other) = default;
1757class StaticQueueBaseOptimised<
std::int16_t> : public CastWrapperQueueBase<
std::int16_t,
std::uint16_t>
1759 using Base = CastWrapperQueueBase<std::int16_t, std::uint16_t>;
1762 using StorageTypePtr =
typename Base::StorageTypePtr;
1764 StaticQueueBaseOptimised(StorageTypePtr data, std::size_t capacity)
1765 : Base(data, capacity)
1769 ~StaticQueueBaseOptimised() noexcept = default;
1770 StaticQueueBaseOptimised& operator=(const StaticQueueBaseOptimised& other) = default;
1771 StaticQueueBaseOptimised& operator=(StaticQueueBaseOptimised&& other) = default;
1775class StaticQueueBaseOptimised<
std::int32_t> : public CastWrapperQueueBase<
std::int32_t,
std::uint32_t>
1777 using Base = CastWrapperQueueBase<std::int32_t, std::uint32_t>;
1780 using StorageTypePtr =
typename Base::StorageTypePtr;
1782 StaticQueueBaseOptimised(StorageTypePtr data, std::size_t capacity)
1783 : Base(data, capacity)
1787 ~StaticQueueBaseOptimised() noexcept = default;
1788 StaticQueueBaseOptimised& operator=(const StaticQueueBaseOptimised& other) = default;
1789 StaticQueueBaseOptimised& operator=(StaticQueueBaseOptimised&& other) = default;
1793class StaticQueueBaseOptimised<
std::int64_t> : public CastWrapperQueueBase<
std::int64_t,
std::uint64_t>
1795 using Base = CastWrapperQueueBase<std::int64_t, std::uint64_t>;
1798 using StorageTypePtr =
typename Base::StorageTypePtr;
1800 StaticQueueBaseOptimised(StorageTypePtr data, std::size_t capacity)
1801 : Base(data, capacity)
1805 ~StaticQueueBaseOptimised() noexcept = default;
1806 StaticQueueBaseOptimised& operator=(const StaticQueueBaseOptimised& other) = default;
1807 StaticQueueBaseOptimised& operator=(StaticQueueBaseOptimised&& other) = default;
1810template <typename T>
1811class StaticQueueBaseOptimised<T*> : public CastWrapperQueueBase<T*, typename
comms::util::SizeToType<sizeof(T*)>::Type>
1813 using Base = CastWrapperQueueBase<T*,
typename comms::util::SizeToType<
sizeof(T*)>::Type>;
1816 using Base =
typename Base::StorageTypePtr;
1818 StaticQueueBaseOptimised(StorageTypePtr data, std::size_t capacity)
1819 : Base(data, capacity)
1823 ~StaticQueueBaseOptimised() noexcept = default;
1824 StaticQueueBaseOptimised& operator=(const StaticQueueBaseOptimised& other) = default;
1825 StaticQueueBaseOptimised& operator=(StaticQueueBaseOptimised&& other) = default;
1842template <typename T,
std::
size_t TSize>
1843class StaticQueue : public details::StaticQueueBaseOptimised<T>
1845 using Base = details::StaticQueueBaseOptimised<T>;
1847 using StorageType =
typename Base::StorageType;
1850 using ValueType =
typename Base::ValueType;
1853 using value_type = ValueType;
1856 using SizeType =
typename Base::SizeType;
1859 using size_type = SizeType;
1862 using Reference =
typename Base::Reference;
1865 using reference = Reference;
1868 using ConstReference =
typename Base::ConstReference;
1871 using const_reference = ConstReference;
1874 using Pointer =
typename Base::Pointer;
1877 using pointer = Pointer;
1880 using ConstPointer =
typename Base::ConstPointer;
1883 using const_pointer = ConstPointer;
1886 using LinearisedIterator =
typename Base::LinearisedIterator;
1889 using ConstLinearisedIterator =
typename Base::ConstLinearisedIterator;
1892 using ReverseLinearisedIterator =
typename Base::ReverseLinearisedIterator;
1895 using ConstReverseLinearisedIterator =
typename Base::ConstReverseLinearisedIterator;
1898 using LinearisedIteratorRange =
typename Base::LinearisedIteratorRange;
1901 using ConstLinearisedIteratorRange =
typename Base::ConstLinearisedIteratorRange;
1904 class ConstIterator;
1907 using const_iterator = ConstIterator;
1913 using iterator = Iterator;
1921 : Base(&m_array[0], TSize)
1933 StaticQueue(
const StaticQueue& queue)
1934 : Base(&m_array[0], TSize)
1936 Base::assignElements(queue);
1947 StaticQueue(StaticQueue&& queue)
1948 : Base(&m_array[0], TSize)
1950 Base::assignElements(std::move(queue));
1961 template <std::
size_t TAnySize>
1962 StaticQueue(
const StaticQueue<T, TAnySize>& queue)
1963 : Base(&m_array[0], TSize)
1965 Base::assignElements(queue);
1976 template <std::
size_t TAnySize>
1977 StaticQueue(StaticQueue<T, TAnySize>&& queue)
1978 : Base(&m_array[0], TSize)
1980 Base::assignElements(std::move(queue));
1989 ~StaticQueue() noexcept
2004 StaticQueue& operator=(
const StaticQueue& queue)
2006 return static_cast<StaticQueue&
>(Base::operator=(queue));
2019 StaticQueue& operator=(StaticQueue&& queue)
2021 return static_cast<StaticQueue&
>(Base::operator=(std::move(queue)));
2035 template <std::
size_t TAnySize>
2036 StaticQueue& operator=(
const StaticQueue<T, TAnySize>& queue)
2038 return static_cast<StaticQueue&
>(Base::operator=(queue));
2052 template <std::
size_t TAnySize>
2053 StaticQueue& operator=(StaticQueue<T, TAnySize>&& queue)
2055 return static_cast<StaticQueue&
>(Base::operator=(std::move(queue)));
2064 static constexpr std::size_t capacity()
2076 std::size_t size()
const
2078 return Base::size();
2088 return Base::empty();
2092 bool isEmpty()
const
2104 return Base::full();
2135 inline void pop_back()
2149 void popBack(std::size_t count)
2151 Base::popBack(count);
2155 void pop_back(std::size_t count)
2172 inline void pop_front()
2184 void popFront(std::size_t count)
2186 Base::popFront(count);
2190 inline void pop_front(std::size_t count)
2202 template <
typename U>
2203 void pushBack(U&& value)
2205 Base::pushBack(std::forward<U>(value));
2216 template <
typename... TArgs>
2217 void emplaceBack(TArgs&&... args)
2219 Base::emplaceBack(std::forward<TArgs>(args)...);
2223 template <
typename U>
2224 inline void push_back(U&& value)
2226 pushBack(std::forward<U>(value));
2236 template <
typename U>
2237 void pushFront(U&& value)
2239 Base::pushFront(std::forward<U>(value));
2243 template <
typename U>
2244 inline void push_front(U&& value)
2246 pushFront(std::forward<U>(value));
2264 template <
typename U>
2265 LinearisedIterator insert(LinearisedIterator pos, U&& value)
2267 return Base::insert(pos, std::forward<U>(value));
2278 return Base::front();
2282 ConstReference front()
const
2284 return Base::front();
2295 return Base::back();
2299 ConstReference back()
const
2301 return Base::back();
2314 Reference operator[](std::size_t index)
2316 return Base::operator[](index);
2320 ConstReference operator[](std::size_t index)
const
2322 return Base::operator[](index);
2336 Reference at(std::size_t index)
2338 return Base::at(index);
2342 ConstReference at(std::size_t index)
const
2344 return Base::at(index);
2356 int indexOf(ConstReference element)
const
2358 return Base::indexOf(element);
2367 LinearisedIterator invalidIter()
2369 return Base::invalidIter();
2373 ConstLinearisedIterator invalidIter()
const
2375 return Base::invalidIter();
2383 ReverseLinearisedIterator invalidReverseIter()
2385 return Base::invalidReverseIter();
2389 ConstReverseLinearisedIterator invalidReverseIter()
const
2391 return Base::invalidReverseIter();
2408 LinearisedIterator lbegin()
2410 return Base::lbegin();
2414 ConstLinearisedIterator lbegin()
const
2416 return Base::lbegin();
2420 ConstLinearisedIterator clbegin()
const
2422 return Base::clbegin();
2439 ReverseLinearisedIterator rlbegin()
2441 return Base::rlbegin();
2445 ConstReverseLinearisedIterator rlbegin()
const
2447 return Base::rlbegin();
2451 ConstReverseLinearisedIterator crlbegin()
const
2453 return Base::crlbegin();
2468 LinearisedIterator lend()
2470 return Base::lend();
2474 ConstLinearisedIterator lend()
const
2476 return Base::lend();
2480 ConstLinearisedIterator clend()
const
2482 return Base::clend();
2497 ReverseLinearisedIterator rlend()
2499 return Base::rlend();
2503 ConstReverseLinearisedIterator rlend()
const
2505 return Base::rlend();
2509 ConstReverseLinearisedIterator crlend()
const
2511 return Base::crlend();
2554 bool linearised()
const
2556 return Base::linearised();
2560 bool isLinearised()
const
2562 return linearised();
2584 LinearisedIteratorRange arrayOne()
2586 return Base::arrayOne();
2590 ConstLinearisedIteratorRange arrayOne()
const
2592 return Base::arrayOne();
2618 LinearisedIteratorRange arrayTwo()
2620 return Base::arrayTwo();
2624 ConstLinearisedIteratorRange arrayTwo()
const
2626 return Base::arrayTwo();
2642 void resize(std::size_t newSize)
2644 Base::resize(newSize);
2658 LinearisedIterator erase(LinearisedIterator pos)
2660 return Base::erase(pos);
2673 Iterator erase(Iterator pos)
2675 auto iter = Base::erase(pos);
2676 return *(
static_cast<Iterator*
>(&iter));
2688 auto iter = Base::begin();
2689 return *(
static_cast<Iterator*
>(&iter));
2693 ConstIterator begin()
const
2695 auto iter = Base::begin();
2696 return *(
static_cast<ConstIterator*
>(&iter));
2700 ConstIterator cbegin()
const
2702 auto iter = Base::cbegin();
2703 return *(
static_cast<ConstIterator*
>(&iter));
2716 auto iter = Base::end();
2717 return *(
static_cast<Iterator*
>(&iter));
2721 ConstIterator end()
const
2723 auto iter = Base::end();
2724 return *(
static_cast<ConstIterator*
>(&iter));
2728 ConstIterator cend()
const
2730 auto iter = Base::end();
2731 return *(
static_cast<ConstIterator*
>(&iter));
2735 template <std::
size_t TAnySize>
2736 bool operator==(
const StaticQueue<T, TAnySize>& other)
const
2738 return Base::operator==(other);
2742 template <std::
size_t TAnySize>
2743 bool operator!=(
const StaticQueue<T, TAnySize>& other)
const
2745 return Base::operator!=(other);
2749 using ArrayType = std::array<StorageType, TSize>;
2750 alignas(
alignof(T)) ArrayType m_array;
2756template <
typename T, std::
size_t TSize>
2757class StaticQueue<T, TSize>::ConstIterator :
public StaticQueue<T, TSize>::Base::ConstIterator
2759 using Base =
typename StaticQueue<T, TSize>::Base::ConstIterator;
2763 using IteratorCategory =
typename Base::IteratorCategory;
2766 using iterator_category = IteratorCategory;
2769 using ValueType =
typename Base::ValueType;
2772 using value_type = ValueType;
2775 using DifferenceType =
typename Base::DifferenceType;
2778 using difference_type = DifferenceType;
2781 using Pointer =
typename Base::Pointer;
2784 using pointer = Pointer;
2787 using ConstPointer =
typename Base::ConstPointer;
2790 using Reference =
typename Base::Reference;
2793 using reference = Reference;
2796 using ConstReference =
typename Base::ConstReference;
2799 using QueueType = StaticQueue<T, TSize>;
2802 using ConstLinearisedIterator =
typename QueueType::ConstLinearisedIterator;
2807 ConstIterator(
const QueueType& queue, ConstLinearisedIterator iterator)
2808 : Base(queue, iterator)
2813 ConstIterator(
const ConstIterator&) =
default;
2818 ConstIterator& operator=(
const ConstIterator& other)
2820 return static_cast<ConstIterator&
>(Base::operator=(other));
2824 ConstIterator& operator++()
2826 return static_cast<ConstIterator&
>(Base::operator++());
2830 ConstIterator operator++(
int dummyParam)
2832 auto tmp = Base::operator++(dummyParam);
2833 return *(
static_cast<ConstIterator*
>(&tmp));
2837 ConstIterator& operator--()
2839 return static_cast<ConstIterator&
>(Base::operator--());
2843 ConstIterator operator--(
int dummyParam)
2845 auto tmp = Base::operator--(dummyParam);
2846 return *(
static_cast<ConstIterator*
>(&tmp));
2851 ConstIterator& operator+=(DifferenceType value)
2853 return static_cast<ConstIterator&
>(Base::operator+=(value));
2858 ConstIterator& operator-=(DifferenceType value)
2860 return static_cast<ConstIterator&
>(Base::operator-=(value));
2867 ConstIterator operator+(DifferenceType value)
const
2869 auto tmp = Base::operator+(value);
2870 return *(
static_cast<ConstIterator*
>(&tmp));
2877 ConstIterator operator-(DifferenceType value)
const
2879 auto tmp = Base::operator-(value);
2880 return *(
static_cast<ConstIterator*
>(&tmp));
2886 DifferenceType operator-(
const ConstIterator& other)
const
2888 return Base::operator-(other);
2893 bool operator==(
const ConstIterator& other)
const
2895 return Base::operator==(other);
2900 bool operator!=(
const ConstIterator& other)
const
2902 return Base::operator!=(other);
2907 bool operator<(
const ConstIterator& other)
const
2909 return Base::operator<(other);
2914 bool operator<=(
const ConstIterator& other)
const
2916 return Base::operator<=(other);
2921 bool operator>(
const ConstIterator& other)
const
2923 return Base::operator>(other);
2928 bool operator>=(
const ConstIterator& other)
const
2930 return Base::operator>=(other);
2934 Reference operator*()
2936 return Base::operator*();
2940 ConstReference operator*()
const
2942 return Base::operator*();
2946 Pointer operator->()
2948 return Base::operator->();
2952 ConstPointer operator->()
const
2954 return Base::operator->();
2961template <
typename T, std::
size_t TSize>
2962class StaticQueue<T, TSize>::Iterator :
public StaticQueue<T, TSize>::Base::Iterator
2964 using Base =
typename StaticQueue<T, TSize>::Base::Iterator;
2968 using IteratorCategory =
typename Base::IteratorCategory;
2971 using iterator_category = IteratorCategory;
2974 using ValueType =
typename Base::ValueType;
2977 using value_type = ValueType;
2980 using DifferenceType =
typename Base::DifferenceType;
2983 using difference_type = DifferenceType;
2986 using Pointer =
typename Base::Pointer;
2989 using pointer = Pointer;
2992 using ConstPointer =
typename Base::ConstPointer;
2995 using Reference =
typename Base::Reference;
2998 using reference = Reference;
3001 using ConstReference =
typename Base::ConstReference;
3004 using QueueType = StaticQueue<T, TSize>;
3007 using LinearisedIterator =
typename QueueType::LinearisedIterator;
3010 using ConstLinearisedIterator =
typename QueueType::ConstLinearisedIterator;
3015 Iterator(QueueType& queue, LinearisedIterator iterator)
3016 : Base(queue, iterator)
3021 Iterator(
const Iterator&) =
default;
3026 Iterator& operator=(
const Iterator& other)
3028 return static_cast<Iterator&
>(Base::operator=(other));
3032 Iterator& operator++()
3034 return static_cast<Iterator&
>(Base::operator++());
3038 Iterator operator++(
int dummyParam)
3040 auto tmp = Base::operator++(dummyParam);
3041 return *(
static_cast<Iterator*
>(&tmp));
3045 Iterator& operator--()
3047 return static_cast<Iterator&
>(Base::operator--());
3051 Iterator operator--(
int dummyParam)
3053 auto tmp = Base::operator--(dummyParam);
3054 return *(
static_cast<Iterator*
>(&tmp));
3059 Iterator& operator+=(DifferenceType value)
3061 return static_cast<Iterator&
>(Base::operator+=(value));
3066 Iterator& operator-=(DifferenceType value)
3068 return static_cast<Iterator&
>(Base::operator-=(value));
3075 Iterator operator+(DifferenceType value)
const
3077 auto tmp = Base::operator+(value);
3078 return *(
static_cast<Iterator*
>(&tmp));
3085 Iterator operator-(DifferenceType value)
const
3087 auto tmp = Base::operator-(value);
3088 return *(
static_cast<Iterator*
>(&tmp));
3094 DifferenceType operator-(
const Iterator& other)
const
3096 return Base::operator-(other);
3101 bool operator==(
const Iterator& other)
const
3103 return Base::operator==(other);
3108 bool operator!=(
const Iterator& other)
const
3110 return Base::operator!=(other);
3115 bool operator<(
const Iterator& other)
const
3117 return Base::operator<(other);
3122 bool operator<=(
const Iterator& other)
const
3124 return Base::operator<=(other);
3129 bool operator>(
const Iterator& other)
const
3131 return Base::operator>(other);
3136 bool operator>=(
const Iterator& other)
const
3138 return Base::operator>=(other);
3142 Reference operator*()
3144 return Base::operator*();
3148 ConstReference operator*()
const
3150 return Base::operator*();
3154 Pointer operator->()
3156 return Base::operator->();
3160 ConstPointer operator->()
const
3162 return Base::operator->();
3165 operator ConstIterator()
const
3167 auto iter =
static_cast<ConstLinearisedIterator
>(Base::getIterator());
3168 const auto& queue =
static_cast<QueueType&
>(Base::getQueue());
3169 return ConstIterator(queue, iter);
3179COMMS_MSVC_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.
Main namespace for all classes / functions of COMMS library.
Replacement to std::conditional.
Definition type_traits.h:29
Replacement to some types from standard type_traits.