19#include "comms/util/SizeToType.h"
32COMMS_MSVC_WARNING_PUSH
33COMMS_MSVC_WARNING_DISABLE(4324)
48 template <
typename TDerived,
typename TQueueType>
56 using StorageType = comms::util::AlignedStorage<
sizeof(ValueType), std::alignment_of<ValueType>::value>;
57 using StorageTypePtr = StorageType*;
58 using ConstStorageTypePtr =
const StorageType*;
59 using SizeType = std::size_t;
60 using Reference = ValueType&;
61 using ConstReference =
const ValueType&;
62 using Pointer = ValueType*;
63 using ConstPointer =
const ValueType*;
64 using LinearisedIterator = Pointer;
65 using ConstLinearisedIterator = ConstPointer;
66 using ReverseLinearisedIterator = std::reverse_iterator<LinearisedIterator>;
67 using ConstReverseLinearisedIterator = std::reverse_iterator<ConstLinearisedIterator>;
68 using LinearisedIteratorRange = std::pair<LinearisedIterator, LinearisedIterator>;
69 using ConstLinearisedIteratorRange = std::pair<ConstLinearisedIterator, ConstLinearisedIterator>;
71 StaticQueueBase(StorageTypePtr data, std::size_t capacity)
79 StaticQueueBase(
const StaticQueueBase&) =
delete;
80 StaticQueueBase(StaticQueueBase&&) =
delete;
82 ~StaticQueueBase() noexcept
87 StaticQueueBase& operator=(
const StaticQueueBase& other)
94 assignElements(other);
98 StaticQueueBase& operator=(StaticQueueBase&& other)
100 if (
this == &other) {
105 assignElements(std::move(other));
109 constexpr std::size_t capacity()
const
114 std::size_t size()
const
128 return (size() == 0);
133 return (size() == capacity());
142 ConstReference front()
const
150 auto constThis =
static_cast<const StaticQueueBase*
>(
this);
151 return const_cast<Reference
>(constThis->back());
154 ConstReference back()
const
161 return (*
this)[m_count - 1];
173 Reference element = front();
178 if ((capacity() <= m_startIdx) ||
184 void popFront(std::size_t count)
187 while ((!empty()) && (count > 0)) {
202 Reference element = back();
208 void popBack(std::size_t count)
211 while ((!empty()) && (count > 0)) {
217 Reference operator[](std::size_t index)
219 auto constThis =
static_cast<const StaticQueueBase*
>(
this);
220 return const_cast<Reference
>((*constThis)[index]);
223 ConstReference operator[](std::size_t index)
const
226 return elementAtIndex(index);
229 Reference at(std::size_t index)
231 auto constThis =
static_cast<const StaticQueueBase*
>(
this);
232 return const_cast<Reference
>(constThis->at(index));
235 ConstReference at(std::size_t index)
const
237 if (index >= size()) {
238 throw std::out_of_range(std::string(
"Index is out of range"));
240 return (*
this)[index];
243 int indexOf(ConstReference element)
const
245 ConstPointer elementPtr = &element;
246 auto cellPtr =
reinterpret_cast<ConstStorageTypePtr
>(elementPtr);
247 if ((cellPtr < &m_data[0]) ||
248 (&m_data[capacity()] <= cellPtr)) {
253 auto rawIdx = cellPtr - &m_data[0];
254 std::size_t actualIdx = capacity();
255 if (rawIdx < m_startIdx) {
256 actualIdx = (capacity() - m_startIdx) + rawIdx;
259 actualIdx = rawIdx - m_startIdx;
262 if (size() <= actualIdx)
271 LinearisedIterator invalidIter()
273 return reinterpret_cast<LinearisedIterator
>(&m_data[capacity()]);
276 ConstLinearisedIterator invalidIter()
const
278 return reinterpret_cast<LinearisedIterator
>(&m_data[capacity()]);
281 ReverseLinearisedIterator invalidReverseIter()
283 return ReverseLinearisedIterator(
284 reinterpret_cast<LinearisedIterator
>(&m_data[0]));
287 ConstReverseLinearisedIterator invalidReverseIter()
const
289 return ReverseLinearisedIterator(
290 reinterpret_cast<LinearisedIterator
>(&m_data[0]));
293 LinearisedIterator lbegin()
296 return invalidIter();
299 return reinterpret_cast<LinearisedIterator
>(&m_data[0] + m_startIdx);
302 ConstLinearisedIterator lbegin()
const
307 ConstLinearisedIterator clbegin()
const
310 return invalidIter();
313 return reinterpret_cast<LinearisedIterator
>(&m_data[0] + m_startIdx);
316 ReverseLinearisedIterator rlbegin()
319 return invalidReverseIter();
322 return ReverseLinearisedIterator(lend());
325 ConstReverseLinearisedIterator rlbegin()
const
330 ConstReverseLinearisedIterator crlbegin()
const
333 return invalidReverseIter();
335 return ConstReverseLinearisedIterator(lend());
338 LinearisedIterator lend()
341 return invalidIter();
344 return lbegin() + size();
347 ConstLinearisedIterator lend()
const
352 ConstLinearisedIterator clend()
const
355 return invalidIter();
358 return clbegin() + size();
361 ReverseLinearisedIterator rlend()
364 return invalidReverseIter();
367 return rlbegin() + size();
370 ConstReverseLinearisedIterator rlend()
const
375 ConstReverseLinearisedIterator crlend()
const
378 return invalidReverseIter();
381 return rlbegin() + size();
391 auto rangeOne = arrayOne();
392 auto rangeOneSize = std::distance(rangeOne.first, rangeOne.second);
394 auto rangeTwo = arrayTwo();
395 auto rangeTwoSize = std::distance(rangeTwo.first, rangeTwo.second);
398 auto remSpaceSize = capacity() - size();
400 if (rangeTwoSize <= remSpaceSize) {
401 lineariseByMoveOneTwo(rangeOne, rangeTwo);
405 if (rangeOneSize <= remSpaceSize) {
406 lineariseByMoveTwoOne(rangeOne, rangeTwo);
410 if (rangeOneSize < rangeTwoSize) {
417 bool linearised()
const
419 return (empty() || ((m_startIdx + size()) <= capacity()));
422 LinearisedIteratorRange arrayOne()
424 auto constThis =
static_cast<const StaticQueueBase*
>(
this);
425 auto constRange = constThis->arrayOne();
427 LinearisedIteratorRange(
428 const_cast<LinearisedIterator
>(constRange.first),
429 const_cast<LinearisedIterator
>(constRange.second));
432 ConstLinearisedIteratorRange arrayOne()
const
434 auto begCell = &m_data[m_startIdx];
435 auto endCell = std::min(&m_data[m_startIdx + size()], &m_data[capacity()]);
437 ConstLinearisedIteratorRange(
438 reinterpret_cast<ConstLinearisedIterator
>(begCell),
439 reinterpret_cast<ConstLinearisedIterator
>(endCell));
442 LinearisedIteratorRange arrayTwo()
444 auto constThis =
static_cast<const StaticQueueBase*
>(
this);
445 auto constRange = constThis->arrayTwo();
447 LinearisedIteratorRange(
448 const_cast<LinearisedIterator
>(constRange.first),
449 const_cast<LinearisedIterator
>(constRange.second));
452 ConstLinearisedIteratorRange arrayTwo()
const
455 auto iter = arrayOne().second;
456 return ConstLinearisedIteratorRange(iter, iter);
459 auto begCell = &m_data[0];
460 auto endCell = &m_data[(m_startIdx + size()) - capacity()];
463 ConstLinearisedIteratorRange(
464 reinterpret_cast<ConstLinearisedIterator
>(begCell),
465 reinterpret_cast<ConstLinearisedIterator
>(endCell));
468 void resize(std::size_t newSize)
471 if (capacity() < newSize) {
475 if (size() <= newSize) {
476 while (size() < newSize) {
477 pushBackNotFull(ValueType());
484 popBack(size() - newSize);
487 LinearisedIterator erase(LinearisedIterator pos)
491 auto rangeOne = arrayOne();
492 auto rangeTwo = arrayTwo();
495 [](LinearisedIterator pos,
const LinearisedIteratorRange range) ->
bool
497 return ((range.first <= pos) && (pos < range.second));
501 isInRangeFunc(pos, rangeTwo));
503 if (isInRangeFunc(pos, rangeOne)) {
504 std::move_backward(rangeOne.first, pos, pos + 1);
507 rangeOne = arrayOne();
508 if (isInRangeFunc(pos, rangeOne)) {
512 return rangeOne.first;
515 if (isInRangeFunc(pos, rangeTwo)) {
516 std::move(pos + 1, rangeTwo.second, pos);
521 return arrayOne().second;
524 static constexpr bool Invalid_iterator_is_used =
false;
525 static_cast<void>(Invalid_iterator_is_used);
527 return invalidIter();
530 Iterator erase(Iterator pos)
534 Pointer elem = &(*pos);
535 auto rangeOne = arrayOne();
536 auto rangeTwo = arrayTwo();
539 [](Pointer elemPtr,
const LinearisedIteratorRange range) ->
bool
541 return ((&(*range.first) <= elemPtr) && (elemPtr < &(*range.second)));
545 isInRangeFunc(elem, rangeTwo));
547 if (isInRangeFunc(elem, rangeOne)) {
548 std::move_backward(rangeOne.first, elem, elem + 1);
551 rangeOne = arrayOne();
552 if (isInRangeFunc(elem, rangeOne)) {
559 if (isInRangeFunc(elem, rangeTwo)) {
560 std::move(elem + 1, rangeTwo.second, elem);
568 static constexpr bool Invalid_iterator_is_used =
false;
569 static_cast<void>(Invalid_iterator_is_used);
576 return Iterator(*
this,
reinterpret_cast<LinearisedIterator
>(&m_data[0]));
579 ConstIterator begin()
const
584 ConstIterator cbegin()
const
586 return ConstIterator(*
this,
reinterpret_cast<ConstLinearisedIterator
>(&m_data[0]));
591 return Iterator(*
this,
reinterpret_cast<LinearisedIterator
>(&m_data[size()]));
594 ConstIterator end()
const
599 ConstIterator cend()
const
601 return ConstIterator(*
this,
reinterpret_cast<ConstLinearisedIterator
>(&m_data[size()]));
604 template <
typename TOther>
605 void assignElements(TOther&& other)
607 static_assert(std::is_base_of<StaticQueueBase, typename std::decay<TOther>::type>::value,
608 "Assignment works only on the same types");
610 using DecayedQueueType =
typename std::decay<
decltype(other)>::type;
611 using NonRefQueueType =
typename std::remove_reference<
decltype(other)>::type;
613 using QueueValueType =
615 std::is_const<NonRefQueueType>::value
617 const typename DecayedQueueType::ValueType,
618 typename DecayedQueueType::ValueType
623 std::is_rvalue_reference<
decltype(other)>::value
625 typename std::add_rvalue_reference<QueueValueType>::type,
626 typename std::add_lvalue_reference<QueueValueType>::type
632 auto rangeOne = other.arrayOne();
633 for (
auto iter = rangeOne.first; iter != rangeOne.second; ++iter) {
634 pushBackNotFull(std::forward<ElemRefType>(*iter));
637 auto rangeTwo = other.arrayTwo();
638 for (
auto iter = rangeTwo.first; iter != rangeTwo.second; ++iter) {
639 pushBackNotFull(std::forward<ElemRefType>(*iter));
643 template <
typename U>
644 void pushBack(U&& value)
650 pushBackNotFull(std::forward<U>(value));
653 template <
typename... TArgs>
654 void emplaceBack(TArgs&&... args)
660 emplaceBackNotFull(std::forward<TArgs>(args)...);
663 template <
typename U>
664 void pushFront(U&& value)
671 pushFrontNotFull(std::forward<U>(value));
674 template <
typename U>
675 LinearisedIterator insert(LinearisedIterator pos, U&& value)
679 return invalidIter();
682 return insertNotFull(pos, std::forward<U>(value));
685 bool operator==(
const StaticQueueBase& other)
const
687 if (size() != other.size()) {
691 auto rangeOne = arrayOne();
692 auto rangeOneSize = std::distance(rangeOne.first, rangeOne.second);
693 auto rangeTwo = arrayTwo();
694 auto otherRangeOne = other.arrayOne();
695 auto otherRangeOneSize = std::distance(otherRangeOne.first, otherRangeOne.second);
696 auto otherRangeTwo = other.arrayTwo();
698 auto firstCompSize = std::min(rangeOneSize, otherRangeOneSize);
699 auto firstCompEnd = rangeOne.first + firstCompSize;
701 auto currIter = rangeOne.first;
702 auto otherCurrIter = otherRangeOne.first;
703 if (!std::equal(currIter, firstCompEnd, otherCurrIter)) {
707 currIter = firstCompEnd;
708 otherCurrIter += firstCompSize;
710 if (currIter != rangeOne.first) {
711 otherCurrIter = otherRangeTwo.first;
712 if (!std::equal(currIter, rangeOne.second, otherCurrIter)) {
715 otherCurrIter += rangeOne.second - currIter;
716 currIter = rangeTwo.first;
719 currIter = rangeTwo.first;
720 if (!std::equal(otherCurrIter, otherRangeOne.second, currIter)) {
724 currIter += otherRangeOne.second - otherCurrIter;
725 otherCurrIter = otherRangeOne.first;
728 COMMS_ASSERT(std::distance(currIter, rangeTwo.second) == std::distance(otherCurrIter, otherRangeTwo.second));
729 return std::equal(currIter, rangeTwo.second, otherCurrIter);
732 bool operator!=(
const StaticQueueBase& other)
const
734 return !(*
this == other);
739 template <
typename U>
740 void createValueAtIndex(U&& value, std::size_t index)
743 Reference elementRef = elementAtIndex(index);
744 auto elementPtr =
new(&elementRef) ValueType(std::forward<U>(value));
745 static_cast<void>(elementPtr);
748 template <
typename U>
749 void pushBackNotFull(U&& value)
752 createValueAtIndex(std::forward<U>(value), size());
756 template <
typename... TArgs>
757 void emplaceBackNotFull(TArgs&&... args)
760 Reference elementRef = elementAtIndex(size());
761 auto elementPtr =
new(&elementRef) ValueType(std::forward<TArgs>(args)...);
762 static_cast<void>(elementPtr);
766 template <
typename U>
767 void pushFrontNotFull(U&& value)
770 createValueAtIndex(std::forward<U>(value), capacity() - 1);
771 if (m_startIdx == 0) {
772 m_startIdx = capacity() - 1;
781 template <
typename U>
782 LinearisedIterator insertNotFull(LinearisedIterator pos, U&& value)
786 auto rangeOne = arrayOne();
787 auto rangeTwo = arrayTwo();
789 if (pos == rangeOne.first) {
790 pushFrontNotFull(std::forward<U>(value));
791 return arrayOne().first;
794 if (pos == rangeTwo.second) {
795 pushBackNotFull(std::forward<U>(value));
796 return arrayTwo().second - 1;
799 auto isInRangeFunc = [](LinearisedIterator pos,
const LinearisedIteratorRange range) ->
bool
801 return ((range.first <= pos) && (pos < range.second));
805 isInRangeFunc(pos, rangeTwo));
807 if (isInRangeFunc(pos, rangeOne)) {
808 pushFrontNotFull(std::move(front()));
810 std::move(rangeOne.first + 1, pos, rangeOne.first);
811 *pos = std::forward<U>(value);
815 if (isInRangeFunc(pos, rangeTwo)) {
816 pushBackNotFull(std::move(back()));
817 std::move_backward(pos, rangeTwo.second - 1, rangeTwo.second);
818 *pos = std::forward<U>(value);
822 return invalidIter();
825 Reference elementAtIndex(std::size_t index) {
826 auto constThis =
static_cast<const StaticQueueBase*
>(
this);
827 return const_cast<Reference
>(constThis->elementAtIndex(index));
830 ConstReference elementAtIndex(std::size_t index)
const
832 std::size_t rawIdx = m_startIdx + index;
833 while (capacity() <= rawIdx) {
834 rawIdx = rawIdx - capacity();
837 auto cellAddr = &m_data[rawIdx];
838 return *(
reinterpret_cast<ConstPointer
>(cellAddr));
841 template <
typename TIter>
842 void lineariseByMove(
843 const std::pair<TIter, TIter> firstRange,
844 const std::pair<TIter, TIter> secondRange)
846 auto movConstructFirstSize =
848 std::size_t(std::distance(firstRange.first, firstRange.second)),
849 capacity() - size());
850 auto movConstructFirstEnd = firstRange.first + movConstructFirstSize;
851 COMMS_ASSERT(movConstructFirstEnd <= firstRange.second);
852 COMMS_ASSERT(movConstructFirstSize <= (firstRange.second - firstRange.first));
854 auto newPlacePtr = secondRange.second;
855 for (
auto iter = firstRange.first; iter != movConstructFirstEnd; ++iter) {
856 auto ptr =
new (&(*newPlacePtr)) ValueType(std::move(*iter));
857 static_cast<void>(ptr);
861 std::move(movConstructFirstEnd, firstRange.second, newPlacePtr);
862 newPlacePtr += (firstRange.second - movConstructFirstEnd);
864 auto movConstructTwoSize = 0;
865 if (newPlacePtr < firstRange.first) {
866 movConstructTwoSize =
867 std::min(std::distance(newPlacePtr, firstRange.first),
868 std::distance(secondRange.first, secondRange.second));
871 auto movConstructTwoEnd = secondRange.first + movConstructTwoSize;
872 for (
auto iter = secondRange.first; iter != movConstructTwoEnd; ++iter) {
873 auto ptr =
new (&(*newPlacePtr)) ValueType(std::move(*iter));
874 static_cast<void>(ptr);
878 std::move(movConstructTwoEnd, secondRange.second, newPlacePtr);
879 newPlacePtr += (secondRange.second - movConstructTwoEnd);
881 for (
auto iter = std::max(newPlacePtr, firstRange.first); iter != firstRange.second; ++iter) {
885 for (
auto iter = secondRange.first; iter != secondRange.second; ++iter) {
890 void lineariseByMoveOneTwo(
891 const LinearisedIteratorRange& rangeOne,
892 const LinearisedIteratorRange& rangeTwo)
894 lineariseByMove(rangeOne, rangeTwo);
895 m_startIdx = std::distance(rangeTwo.first, rangeTwo.second);
898 void lineariseByMoveTwoOne(
899 const LinearisedIteratorRange& rangeOne,
900 const LinearisedIteratorRange& rangeTwo)
902 using RevIter = std::reverse_iterator<Pointer>;
904 std::make_pair(RevIter(rangeTwo.second), RevIter(rangeTwo.first)),
905 std::make_pair(RevIter(rangeOne.second), RevIter(rangeOne.first)));
907 m_startIdx = (capacity() - std::distance(rangeOne.first, rangeOne.second)) - size();
910 void lineariseByPopOne()
916 ValueType tmp(std::move(front()));
919 if (m_startIdx == 0) {
920 using RevIter = std::reverse_iterator<LinearisedIterator>;
922 RevIter(
reinterpret_cast<LinearisedIterator
>(&m_data[capacity()]));
923 moveRange(rlbegin(), rlend(), target);
924 m_startIdx = capacity() - size();
926 pushFront(std::move(tmp));
930 void lineariseByPopTwo()
936 ValueType tmp(std::move(back()));
939 if (m_startIdx != 0) {
940 auto target =
reinterpret_cast<LinearisedIterator
>(&m_data[0]);
941 moveRange(lbegin(), lend(), target);
944 pushBack(std::move(tmp));
948 template <
typename TIter>
949 void moveRange(TIter rangeBeg, TIter rangeEnd, TIter target)
952 auto moveConstructSize =
954 std::distance(rangeBeg, rangeEnd),
955 std::distance(target, rangeBeg));
957 TIter moveConstructEnd = rangeBeg + moveConstructSize;
958 for (
auto iter = rangeBeg; iter != moveConstructEnd; ++iter) {
959 auto ptr =
new (&(*target)) ValueType(std::move(*iter));
960 static_cast<void>(ptr);
965 std::move(moveConstructEnd, rangeEnd, target);
966 target += std::distance(moveConstructEnd, rangeEnd);
968 for (
auto iter = std::max(target, rangeBeg); iter != rangeEnd; ++iter) {
973 StorageTypePtr
const m_data;
974 const std::size_t m_capacity;
975 std::size_t m_startIdx;
980template <
typename TDerived,
typename TQueueType>
981class StaticQueueBase<T>::IteratorBase
983 friend class StaticQueueBase<T>;
986 IteratorBase(
const IteratorBase&) =
default;
988 ~IteratorBase() noexcept = default;
991 using Derived = TDerived;
992 using QueueType = TQueueType;
993 using ArrayIterator = decltype(
std::declval<QueueType>().lbegin());
994 using IteratorCategory = typename
std::iterator_traits<ArrayIterator>::iterator_category;
995 using iterator_category = IteratorCategory;
996 using ValueType = typename
std::iterator_traits<ArrayIterator>::value_type;
997 using value_type = ValueType;
998 using DifferenceType = typename
std::iterator_traits<ArrayIterator>::difference_type;
999 using difference_type = DifferenceType;
1000 using Pointer = typename
std::iterator_traits<ArrayIterator>::pointer;
1001 using pointer = Pointer;
1002 using ConstPointer =
1003 typename
std::add_pointer<
1004 typename
std::add_const<
1005 typename
std::remove_pointer<Pointer>::type
1008 using Reference = typename
std::iterator_traits<ArrayIterator>::reference;
1009 using reference = Reference;
1010 using ConstReference = typename
std::add_const<Reference>::type;
1012 IteratorBase(QueueType& queue, ArrayIterator iterator)
1014 m_iterator(iterator)
1018 Derived& operator=(
const IteratorBase& other)
1021 m_iterator = other.m_iterator;
1022 return static_cast<Derived&
>(*this);
1025 Derived& operator++()
1028 return static_cast<Derived&
>(*this);
1031 Derived operator++(
int)
1033 IteratorBase copy(*
this);
1035 return std::move(*(
static_cast<Derived*
>(©)));
1038 Derived& operator--()
1041 return static_cast<Derived&
>(*this);
1044 Derived operator--(
int)
1046 IteratorBase copy(*
this);
1048 return std::move(*(
static_cast<Derived*
>(©)));
1051 Derived& operator+=(DifferenceType value)
1053 m_iterator += value;
1054 return static_cast<Derived&
>(*this);
1057 Derived& operator-=(DifferenceType value)
1059 m_iterator -= value;
1060 return static_cast<Derived&
>(*this);
1063 Derived operator+(DifferenceType value)
const
1065 IteratorBase copy(*
this);
1067 return std::move(*(
static_cast<Derived*
>(©)));
1070 Derived operator-(DifferenceType value)
const
1072 IteratorBase copy(*
this);
1074 return std::move(*(
static_cast<Derived*
>(©)));
1077 DifferenceType operator-(
const IteratorBase& other)
const
1079 return m_iterator - other.m_iterator;
1082 bool operator==(
const IteratorBase& other)
const
1084 return (m_iterator == other.m_iterator);
1087 bool operator!=(
const IteratorBase& other)
const
1089 return (m_iterator != other.m_iterator);
1092 bool operator<(
const IteratorBase& other)
const
1094 return m_iterator < other.m_iterator;
1097 bool operator<=(
const IteratorBase& other)
const
1099 return m_iterator <= other.m_iterator;
1102 bool operator>(
const IteratorBase& other)
const
1104 return m_iterator > other.m_iterator;
1107 bool operator>=(
const IteratorBase& other)
const
1109 return m_iterator >= other.m_iterator;
1112 Reference operator*()
1114 auto& constThisRef =
static_cast<const IteratorBase&
>(*this);
1115 auto& constRef = *constThisRef;
1116 return const_cast<Reference
>(constRef);
1119 ConstReference operator*()
const
1121 auto begCell =
reinterpret_cast<ArrayIterator
>(&m_queue.m_data[0]);
1122 auto idx = m_iterator - begCell;
1124 return m_queue[
static_cast<std::size_t
>(idx)];
1127 Pointer operator->()
1132 ConstPointer operator->()
const
1137 QueueType& getQueue() {
1141 typename std::add_const<QueueType&>::type getQueue()
const
1146 ArrayIterator& getIterator() {
1150 typename std::add_const<ArrayIterator>::type& getIterator()
const
1158 ArrayIterator m_iterator;
1161template <
typename T>
1162class StaticQueueBase<T>::ConstIterator :
1163 public StaticQueueBase<T>::template
1164 IteratorBase<typename StaticQueueBase<T>::ConstIterator, const StaticQueueBase<T> >
1166 using Base =
typename StaticQueueBase<T>::template
1167 IteratorBase<typename StaticQueueBase<T>::ConstIterator,
const StaticQueueBase<T> >;
1170 using QueueType =
typename Base::QueueType;
1171 using ArrayIterator =
typename Base::ArrayIterator;
1173 ConstIterator(
const ConstIterator&) =
default;
1174 ~ConstIterator() noexcept = default;
1176 ConstIterator(QueueType& queue, ArrayIterator iterator)
1177 : Base(queue, iterator)
1183template <
typename T>
1184class StaticQueueBase<T>::Iterator :
1185 public StaticQueueBase<T>::template
1186 IteratorBase<typename StaticQueueBase<T>::Iterator, StaticQueueBase<T> >
1188 using Base =
typename StaticQueueBase<T>::template
1189 IteratorBase<typename StaticQueueBase<T>::Iterator, StaticQueueBase<T> >;
1192 using QueueType =
typename Base::QueueType;
1193 using ArrayIterator =
typename Base::ArrayIterator;
1195 Iterator(
const Iterator&) =
default;
1196 ~Iterator() noexcept = default;
1198 Iterator(QueueType& queue, ArrayIterator iterator)
1199 : Base(queue, iterator)
1203 operator ConstIterator()
const
1205 return ConstIterator(Base::getQueue(), Base::getIterator());
1209template <
typename TWrapperElemType,
typename TQueueElemType>
1210class CastWrapperQueueBase :
public StaticQueueBase<TQueueElemType>
1212 using Base = StaticQueueBase<TQueueElemType>;
1213 using WrapperElemType = TWrapperElemType;
1215 using BaseValueType =
typename Base::ValueType;
1216 using BaseStorageTypePtr =
typename Base::StorageTypePtr;
1217 using BaseReference =
typename Base::Reference;
1218 using BaseConstReference =
typename Base::ConstReference;
1219 using BasePointer =
typename Base::Pointer;
1220 using BaseConstPointer =
typename Base::ConstPointer;
1221 using BaseLinearisedIterator =
typename Base::LinearisedIterator;
1222 using BaseConstLinearisedIterator =
typename Base::ConstLinearisedIterator;
1223 using BaseReverseLinearisedIterator =
typename Base::ReverseLinearisedIterator;
1224 using BaseConstReverseLinearisedIterator =
typename Base::ConstReverseLinearisedIterator;
1225 using BaseLinearisedIteratorRange =
typename Base::LinearisedIteratorRange;
1226 using BaseConstLinearisedIteratorRange =
typename Base::ConstLinearisedIteratorRange;
1230 class ConstIterator;
1234 using ValueType = WrapperElemType;
1235 using StorageType = comms::util::AlignedStorage<
sizeof(ValueType), std::alignment_of<ValueType>::value>;
1236 using StorageTypePtr = StorageType*;
1237 using Reference = ValueType&;
1238 using ConstReference =
const ValueType&;
1239 using Pointer = ValueType*;
1240 using ConstPointer =
const ValueType*;
1241 using LinearisedIterator = Pointer;
1242 using ConstLinearisedIterator = ConstPointer;
1243 using ReverseLinearisedIterator = std::reverse_iterator<LinearisedIterator>;
1244 using ConstReverseLinearisedIterator = std::reverse_iterator<ConstLinearisedIterator>;
1245 using LinearisedIteratorRange = std::pair<LinearisedIterator, LinearisedIterator>;
1246 using ConstLinearisedIteratorRange = std::pair<ConstLinearisedIterator, ConstLinearisedIterator>;
1248 CastWrapperQueueBase(StorageTypePtr data, std::size_t capacity)
1249 : Base(reinterpret_cast<BaseStorageTypePtr>(data), capacity)
1251 static_assert(
sizeof(ValueType) ==
sizeof(BaseValueType),
1252 "The times must have identical size.");
1255 ~CastWrapperQueueBase() noexcept = default;
1257 CastWrapperQueueBase& operator=(const CastWrapperQueueBase& other) = default;
1258 CastWrapperQueueBase& operator=(CastWrapperQueueBase&& other) = default;
1262 return reinterpret_cast<Reference
>(Base::front());
1265 ConstReference front()
const
1267 return reinterpret_cast<ConstReference
>(Base::front());
1272 return reinterpret_cast<Reference
>(Base::back());
1275 ConstReference back()
const
1277 return reinterpret_cast<Reference
>(Base::back());
1280 Reference operator[](std::size_t index)
1282 return reinterpret_cast<Reference
>(Base::operator[](index));
1285 ConstReference operator[](std::size_t index)
const
1287 return reinterpret_cast<ConstReference
>(Base::operator[](index));
1290 Reference at(std::size_t index)
1292 return reinterpret_cast<Reference
>(Base::at(index));
1295 ConstReference at(std::size_t index)
const
1297 return reinterpret_cast<ConstReference
>(Base::at(index));
1300 int indexOf(ConstReference element)
const
1302 return Base::indexOf(
reinterpret_cast<BaseConstReference
>(element));
1305 LinearisedIterator invalidIter()
1307 return reinterpret_cast<LinearisedIterator
>(Base::invalidIter());
1310 ConstLinearisedIterator invalidIter()
const
1312 return reinterpret_cast<ConstLinearisedIterator
>(Base::invalidIter());
1315 ReverseLinearisedIterator invalidReverseIter()
1317 return ReverseLinearisedIterator(
1318 reinterpret_cast<LinearisedIterator
>(
1319 Base::invalidReverseIter().base()));
1322 ConstReverseLinearisedIterator invalidReverseIter()
const
1324 return ConstReverseLinearisedIterator(
1325 reinterpret_cast<ConstLinearisedIterator
>(
1326 Base::invalidReverseIter().base()));
1329 LinearisedIterator lbegin()
1331 return reinterpret_cast<LinearisedIterator
>(Base::lbegin());
1334 ConstLinearisedIterator lbegin()
const
1336 return reinterpret_cast<ConstLinearisedIterator
>(Base::lbegin());
1339 ConstLinearisedIterator clbegin()
const
1341 return reinterpret_cast<ConstLinearisedIterator
>(Base::clbegin());
1344 ReverseLinearisedIterator rlbegin()
1346 return ReverseLinearisedIterator(
1347 reinterpret_cast<LinearisedIterator
>(
1348 Base::rlbegin().base()));
1351 ConstReverseLinearisedIterator rlbegin()
const
1353 return ConstReverseLinearisedIterator(
1354 reinterpret_cast<ConstLinearisedIterator
>(
1355 Base::rlbegin().base()));
1358 ConstReverseLinearisedIterator crlbegin()
const
1360 return ConstReverseLinearisedIterator(
1361 reinterpret_cast<ConstLinearisedIterator
>(
1362 Base::crlbegin().base()));
1365 LinearisedIterator lend()
1367 return reinterpret_cast<LinearisedIterator
>(Base::lend());
1370 ConstLinearisedIterator lend()
const
1372 return reinterpret_cast<ConstLinearisedIterator
>(Base::lend());
1375 ConstLinearisedIterator clend()
const
1377 return reinterpret_cast<ConstLinearisedIterator
>(Base::clend());
1380 ReverseLinearisedIterator rlend()
1382 return ReverseLinearisedIterator(
1383 reinterpret_cast<LinearisedIterator
>(
1384 Base::rlend().base()));
1387 ConstReverseLinearisedIterator rlend()
const
1389 return ConstReverseLinearisedIterator(
1390 reinterpret_cast<ConstLinearisedIterator
>(
1391 Base::rlend().base()));
1394 ConstReverseLinearisedIterator crlend()
const
1396 return ConstReverseLinearisedIterator(
1397 reinterpret_cast<ConstLinearisedIterator
>(
1398 Base::crlend().base()));
1401 LinearisedIteratorRange arrayOne()
1403 auto range = Base::arrayOne();
1404 return LinearisedIteratorRange(
1405 reinterpret_cast<LinearisedIterator
>(range.first),
1406 reinterpret_cast<LinearisedIterator
>(range.second));
1409 ConstLinearisedIteratorRange arrayOne()
const
1411 auto range = Base::arrayOne();
1412 return ConstLinearisedIteratorRange(
1413 reinterpret_cast<ConstLinearisedIterator
>(range.first),
1414 reinterpret_cast<ConstLinearisedIterator
>(range.second));
1418 LinearisedIteratorRange arrayTwo()
1420 auto range = Base::arrayTwo();
1421 return LinearisedIteratorRange(
1422 reinterpret_cast<LinearisedIterator
>(range.first),
1423 reinterpret_cast<LinearisedIterator
>(range.second));
1427 ConstLinearisedIteratorRange arrayTwo()
const
1429 auto range = Base::arrayTwo();
1430 return ConstLinearisedIteratorRange(
1431 reinterpret_cast<ConstLinearisedIterator
>(range.first),
1432 reinterpret_cast<ConstLinearisedIterator
>(range.second));
1436 LinearisedIterator erase(LinearisedIterator pos)
1438 return reinterpret_cast<LinearisedIterator
>(
1440 reinterpret_cast<BaseLinearisedIterator
>(pos)));
1443 Iterator erase(Iterator pos)
1445 auto tmp = Base::erase(pos);
1446 return *(
reinterpret_cast<Iterator*
>(&tmp));
1451 auto tmp = Base::begin();
1452 return *(
reinterpret_cast<Iterator*
>(&tmp));
1455 ConstIterator begin()
const
1457 auto tmp = Base::begin();
1458 return *(
reinterpret_cast<ConstIterator*
>(&tmp));
1461 ConstIterator cbegin()
const
1463 auto tmp = Base::cbegin();
1464 return *(
reinterpret_cast<ConstIterator*
>(&tmp));
1470 auto tmp = Base::end();
1471 return *(
reinterpret_cast<Iterator*
>(&tmp));
1474 ConstIterator end()
const
1476 auto tmp = Base::end();
1477 return *(
reinterpret_cast<ConstIterator*
>(&tmp));
1480 ConstIterator cend()
const
1482 auto tmp = Base::cend();
1483 return *(
reinterpret_cast<ConstIterator*
>(&tmp));
1486 void pushBack(ConstReference value)
1488 Base::pushBack(
reinterpret_cast<BaseConstReference
>(value));
1491 void pushFront(ConstReference value)
1493 Base::pushFront(
reinterpret_cast<BaseConstReference
>(value));
1496 LinearisedIterator insert(LinearisedIterator pos, ConstReference value)
1498 return reinterpret_cast<LinearisedIterator
>(
1500 reinterpret_cast<BaseLinearisedIterator
>(pos),
1501 reinterpret_cast<BaseConstReference
>(value)));
1504 void assignElements(
const CastWrapperQueueBase& other)
1506 Base::assignElements(
static_cast<const Base&
>(other));
1509 void assignElements(CastWrapperQueueBase&& other)
1511 Base::assignElements(
static_cast<Base&&
>(std::move(other)));
1515template <
typename TWrapperElemType,
typename TQueueElemType>
1516class CastWrapperQueueBase<TWrapperElemType, TQueueElemType>::ConstIterator :
1517 public StaticQueueBase<TQueueElemType>::ConstIterator
1519 using Base =
typename StaticQueueBase<TQueueElemType>::ConstIterator;
1521 ConstIterator(
const ConstIterator&) =
default;
1522 ConstIterator& operator=(
const ConstIterator&) =
default;
1523 ~ConstIterator() noexcept = default;
1526 using ExpectedQueueType = const StaticQueueBase<TWrapperElemType>;
1527 using ActualQueueType = const StaticQueueBase<TQueueElemType>;
1528 using ValueType = TWrapperElemType;
1529 using Reference = const ValueType&;
1530 using ConstReference = const ValueType&;
1531 using Pointer = const ValueType*;
1532 using ConstPointer = const ValueType*;
1533 using DifferenceType = typename Base::DifferenceType;
1535 ConstIterator(ExpectedQueueType& queue, Pointer iterator)
1536 : Base(reinterpret_cast<ActualQueueType&>(queue), iterator)
1540 ConstIterator& operator++()
1546 ConstIterator operator++(
int dummy)
1548 auto tmp = Base::operator++(dummy);
1549 return *(
static_cast<ConstIterator*
>(&tmp));
1552 ConstIterator& operator--()
1558 ConstIterator operator--(
int dummy)
1560 auto tmp = Base::operator--(dummy);
1561 return *(
static_cast<ConstIterator*
>(&tmp));
1564 ConstIterator& operator+=(DifferenceType value)
1566 Base::operator+=(value);
1570 ConstIterator& operator-=(DifferenceType value)
1572 Base::operator-=(value);
1576 ConstIterator operator+(DifferenceType value)
const
1578 auto tmp = Base::operator+(value);
1579 return *(
static_cast<ConstIterator*
>(&tmp));
1582 ConstIterator operator-(DifferenceType value)
const
1584 auto tmp = Base::operator-(value);
1585 return *(
static_cast<ConstIterator*
>(&tmp));
1588 DifferenceType operator-(
const ConstIterator& other)
const
1590 return Base::operator-(other);
1593 Reference operator*()
1595 auto& ref = Base::operator*();
1596 return reinterpret_cast<Reference
>(ref);
1599 ConstReference operator*()
const
1601 auto& ref = Base::operator*();
1602 return reinterpret_cast<ConstReference
>(ref);
1605 Pointer operator->()
1607 auto* ptr = Base::operator->();
1608 return reinterpret_cast<Pointer
>(ptr);
1611 ConstPointer operator->()
const
1613 auto* ptr = Base::operator->();
1614 return reinterpret_cast<ConstPointer
>(ptr);
1618template <
typename TWrapperElemType,
typename TQueueElemType>
1619class CastWrapperQueueBase<TWrapperElemType, TQueueElemType>::Iterator :
1620 public StaticQueueBase<TQueueElemType>::Iterator
1622 using Base =
typename StaticQueueBase<TQueueElemType>::Iterator;
1624 Iterator(
const Iterator&) =
default;
1625 Iterator& operator=(
const Iterator&) =
default;
1626 ~Iterator() noexcept = default;
1629 using ExpectedQueueType = const StaticQueueBase<TWrapperElemType>;
1630 using ActualQueueType = const StaticQueueBase<TQueueElemType>;
1631 using ValueType = TWrapperElemType;
1632 using Reference = ValueType&;
1633 using ConstReference = const ValueType&;
1634 using Pointer = ValueType*;
1635 using ConstPointer = const ValueType*;
1636 using DifferenceType = typename Base::DifferenceType;
1638 Iterator(ExpectedQueueType& queue, Pointer iterator)
1639 : Base(reinterpret_cast<ActualQueueType&>(queue), iterator)
1643 Iterator& operator++()
1649 Iterator operator++(
int dummy)
1651 auto tmp = Base::operator++(dummy);
1652 return *(
static_cast<Iterator*
>(&tmp));
1655 Iterator& operator--()
1661 Iterator operator--(
int dummy)
1663 auto tmp = Base::operator--(dummy);
1664 return *(
static_cast<Iterator*
>(&tmp));
1667 Iterator& operator+=(DifferenceType value)
1669 Base::operator+=(value);
1673 Iterator& operator-=(DifferenceType value)
1675 Base::operator-=(value);
1679 Iterator operator+(DifferenceType value)
const
1681 auto tmp = Base::operator+(value);
1682 return *(
static_cast<Iterator*
>(&tmp));
1685 Iterator operator-(DifferenceType value)
const
1687 auto tmp = Base::operator-(value);
1688 return *(
static_cast<Iterator*
>(&tmp));
1691 DifferenceType operator-(
const Iterator& other)
const
1693 return Base::operator-(other);
1696 Reference operator*()
1698 auto& ref = Base::operator*();
1699 return reinterpret_cast<Reference
>(ref);
1702 ConstReference operator*()
const
1704 auto& ref = Base::operator*();
1705 return reinterpret_cast<ConstReference
>(ref);
1708 Pointer operator->()
1710 auto* ptr = Base::operator->();
1711 return reinterpret_cast<Pointer
>(ptr);
1714 ConstPointer operator->()
const
1716 auto* ptr = Base::operator->();
1717 return reinterpret_cast<ConstPointer
>(ptr);
1721template <
typename T>
1722class StaticQueueBaseOptimised :
public StaticQueueBase<T>
1724 usign Base = StaticQueueBase<T>;
1727 using StorageTypePtr =
typename Base::StorageTypePtr;
1729 StaticQueueBaseOptimised(StorageTypePtr data, std::size_t capacity)
1730 : Base(data, capacity)
1734 ~StaticQueueBaseOptimised() noexcept = default;
1736 StaticQueueBaseOptimised& operator=(const StaticQueueBaseOptimised& other) = default;
1737 StaticQueueBaseOptimised& operator=(StaticQueueBaseOptimised&& other) = default;
1741class StaticQueueBaseOptimised<
std::int8_t> : public CastWrapperQueueBase<
std::int8_t,
std::uint8_t>
1743 using Base = CastWrapperQueueBase<std::int8_t, std::uint8_t>;
1746 using StorageTypePtr =
typename Base::StorageTypePtr;
1748 StaticQueueBaseOptimised(StorageTypePtr data, std::size_t capacity)
1749 : Base(data, capacity)
1753 ~StaticQueueBaseOptimised() noexcept = default;
1754 StaticQueueBaseOptimised& operator=(const StaticQueueBaseOptimised& other) = default;
1755 StaticQueueBaseOptimised& operator=(StaticQueueBaseOptimised&& other) = default;
1759class StaticQueueBaseOptimised<
std::int16_t> : public CastWrapperQueueBase<
std::int16_t,
std::uint16_t>
1761 using Base = CastWrapperQueueBase<std::int16_t, std::uint16_t>;
1764 using StorageTypePtr =
typename Base::StorageTypePtr;
1766 StaticQueueBaseOptimised(StorageTypePtr data, std::size_t capacity)
1767 : Base(data, capacity)
1771 ~StaticQueueBaseOptimised() noexcept = default;
1772 StaticQueueBaseOptimised& operator=(const StaticQueueBaseOptimised& other) = default;
1773 StaticQueueBaseOptimised& operator=(StaticQueueBaseOptimised&& other) = default;
1777class StaticQueueBaseOptimised<
std::int32_t> : public CastWrapperQueueBase<
std::int32_t,
std::uint32_t>
1779 using Base = CastWrapperQueueBase<std::int32_t, std::uint32_t>;
1782 using StorageTypePtr =
typename Base::StorageTypePtr;
1784 StaticQueueBaseOptimised(StorageTypePtr data, std::size_t capacity)
1785 : Base(data, capacity)
1789 ~StaticQueueBaseOptimised() noexcept = default;
1790 StaticQueueBaseOptimised& operator=(const StaticQueueBaseOptimised& other) = default;
1791 StaticQueueBaseOptimised& operator=(StaticQueueBaseOptimised&& other) = default;
1795class StaticQueueBaseOptimised<
std::int64_t> : public CastWrapperQueueBase<
std::int64_t,
std::uint64_t>
1797 using Base = CastWrapperQueueBase<std::int64_t, std::uint64_t>;
1800 using StorageTypePtr =
typename Base::StorageTypePtr;
1802 StaticQueueBaseOptimised(StorageTypePtr data, std::size_t capacity)
1803 : Base(data, capacity)
1807 ~StaticQueueBaseOptimised() noexcept = default;
1808 StaticQueueBaseOptimised& operator=(const StaticQueueBaseOptimised& other) = default;
1809 StaticQueueBaseOptimised& operator=(StaticQueueBaseOptimised&& other) = default;
1812template <typename T>
1813class StaticQueueBaseOptimised<T*> : public CastWrapperQueueBase<T*, typename
comms::util::SizeToType<sizeof(T*)>::Type>
1815 using Base = CastWrapperQueueBase<T*,
typename comms::util::SizeToType<
sizeof(T*)>::Type>;
1818 using Base =
typename Base::StorageTypePtr;
1820 StaticQueueBaseOptimised(StorageTypePtr data, std::size_t capacity)
1821 : Base(data, capacity)
1825 ~StaticQueueBaseOptimised() noexcept = default;
1826 StaticQueueBaseOptimised& operator=(const StaticQueueBaseOptimised& other) = default;
1827 StaticQueueBaseOptimised& operator=(StaticQueueBaseOptimised&& other) = default;
1844template <typename T,
std::
size_t TSize>
1845class StaticQueue : public details::StaticQueueBaseOptimised<T>
1847 using Base = details::StaticQueueBaseOptimised<T>;
1849 using StorageType =
typename Base::StorageType;
1852 using ValueType =
typename Base::ValueType;
1855 using value_type = ValueType;
1858 using SizeType =
typename Base::SizeType;
1861 using size_type = SizeType;
1864 using Reference =
typename Base::Reference;
1867 using reference = Reference;
1870 using ConstReference =
typename Base::ConstReference;
1873 using const_reference = ConstReference;
1876 using Pointer =
typename Base::Pointer;
1879 using pointer = Pointer;
1882 using ConstPointer =
typename Base::ConstPointer;
1885 using const_pointer = ConstPointer;
1888 using LinearisedIterator =
typename Base::LinearisedIterator;
1891 using ConstLinearisedIterator =
typename Base::ConstLinearisedIterator;
1894 using ReverseLinearisedIterator =
typename Base::ReverseLinearisedIterator;
1897 using ConstReverseLinearisedIterator =
typename Base::ConstReverseLinearisedIterator;
1900 using LinearisedIteratorRange =
typename Base::LinearisedIteratorRange;
1903 using ConstLinearisedIteratorRange =
typename Base::ConstLinearisedIteratorRange;
1906 class ConstIterator;
1909 using const_iterator = ConstIterator;
1915 using iterator = Iterator;
1923 : Base(&m_array[0], TSize)
1935 StaticQueue(
const StaticQueue& queue)
1936 : Base(&m_array[0], TSize)
1938 Base::assignElements(queue);
1949 StaticQueue(StaticQueue&& queue)
1950 : Base(&m_array[0], TSize)
1952 Base::assignElements(std::move(queue));
1963 template <std::
size_t TAnySize>
1964 StaticQueue(
const StaticQueue<T, TAnySize>& queue)
1965 : Base(&m_array[0], TSize)
1967 Base::assignElements(queue);
1978 template <std::
size_t TAnySize>
1979 StaticQueue(StaticQueue<T, TAnySize>&& queue)
1980 : Base(&m_array[0], TSize)
1982 Base::assignElements(std::move(queue));
1991 ~StaticQueue() noexcept
2006 StaticQueue& operator=(
const StaticQueue& queue)
2008 return static_cast<StaticQueue&
>(Base::operator=(queue));
2021 StaticQueue& operator=(StaticQueue&& queue)
2023 return static_cast<StaticQueue&
>(Base::operator=(std::move(queue)));
2037 template <std::
size_t TAnySize>
2038 StaticQueue& operator=(
const StaticQueue<T, TAnySize>& queue)
2040 return static_cast<StaticQueue&
>(Base::operator=(queue));
2054 template <std::
size_t TAnySize>
2055 StaticQueue& operator=(StaticQueue<T, TAnySize>&& queue)
2057 return static_cast<StaticQueue&
>(Base::operator=(std::move(queue)));
2066 static constexpr std::size_t capacity()
2078 std::size_t size()
const
2080 return Base::size();
2090 return Base::empty();
2094 bool isEmpty()
const
2106 return Base::full();
2137 inline void pop_back()
2151 void popBack(std::size_t count)
2153 Base::popBack(count);
2157 void pop_back(std::size_t count)
2174 inline void pop_front()
2186 void popFront(std::size_t count)
2188 Base::popFront(count);
2192 inline void pop_front(std::size_t count)
2204 template <
typename U>
2205 void pushBack(U&& value)
2207 Base::pushBack(std::forward<U>(value));
2218 template <
typename... TArgs>
2219 void emplaceBack(TArgs&&... args)
2221 Base::emplaceBack(std::forward<TArgs>(args)...);
2225 template <
typename U>
2226 inline void push_back(U&& value)
2228 pushBack(std::forward<U>(value));
2238 template <
typename U>
2239 void pushFront(U&& value)
2241 Base::pushFront(std::forward<U>(value));
2245 template <
typename U>
2246 inline void push_front(U&& value)
2248 pushFront(std::forward<U>(value));
2266 template <
typename U>
2267 LinearisedIterator insert(LinearisedIterator pos, U&& value)
2269 return Base::insert(pos, std::forward<U>(value));
2280 return Base::front();
2284 ConstReference front()
const
2286 return Base::front();
2297 return Base::back();
2301 ConstReference back()
const
2303 return Base::back();
2316 Reference operator[](std::size_t index)
2318 return Base::operator[](index);
2322 ConstReference operator[](std::size_t index)
const
2324 return Base::operator[](index);
2338 Reference at(std::size_t index)
2340 return Base::at(index);
2344 ConstReference at(std::size_t index)
const
2346 return Base::at(index);
2358 int indexOf(ConstReference element)
const
2360 return Base::indexOf(element);
2369 LinearisedIterator invalidIter()
2371 return Base::invalidIter();
2375 ConstLinearisedIterator invalidIter()
const
2377 return Base::invalidIter();
2385 ReverseLinearisedIterator invalidReverseIter()
2387 return Base::invalidReverseIter();
2391 ConstReverseLinearisedIterator invalidReverseIter()
const
2393 return Base::invalidReverseIter();
2410 LinearisedIterator lbegin()
2412 return Base::lbegin();
2416 ConstLinearisedIterator lbegin()
const
2418 return Base::lbegin();
2422 ConstLinearisedIterator clbegin()
const
2424 return Base::clbegin();
2441 ReverseLinearisedIterator rlbegin()
2443 return Base::rlbegin();
2447 ConstReverseLinearisedIterator rlbegin()
const
2449 return Base::rlbegin();
2453 ConstReverseLinearisedIterator crlbegin()
const
2455 return Base::crlbegin();
2470 LinearisedIterator lend()
2472 return Base::lend();
2476 ConstLinearisedIterator lend()
const
2478 return Base::lend();
2482 ConstLinearisedIterator clend()
const
2484 return Base::clend();
2499 ReverseLinearisedIterator rlend()
2501 return Base::rlend();
2505 ConstReverseLinearisedIterator rlend()
const
2507 return Base::rlend();
2511 ConstReverseLinearisedIterator crlend()
const
2513 return Base::crlend();
2556 bool linearised()
const
2558 return Base::linearised();
2562 bool isLinearised()
const
2564 return linearised();
2586 LinearisedIteratorRange arrayOne()
2588 return Base::arrayOne();
2592 ConstLinearisedIteratorRange arrayOne()
const
2594 return Base::arrayOne();
2620 LinearisedIteratorRange arrayTwo()
2622 return Base::arrayTwo();
2626 ConstLinearisedIteratorRange arrayTwo()
const
2628 return Base::arrayTwo();
2644 void resize(std::size_t newSize)
2646 Base::resize(newSize);
2660 LinearisedIterator erase(LinearisedIterator pos)
2662 return Base::erase(pos);
2675 Iterator erase(Iterator pos)
2677 auto iter = Base::erase(pos);
2678 return *(
static_cast<Iterator*
>(&iter));
2690 auto iter = Base::begin();
2691 return *(
static_cast<Iterator*
>(&iter));
2695 ConstIterator begin()
const
2697 auto iter = Base::begin();
2698 return *(
static_cast<ConstIterator*
>(&iter));
2702 ConstIterator cbegin()
const
2704 auto iter = Base::cbegin();
2705 return *(
static_cast<ConstIterator*
>(&iter));
2718 auto iter = Base::end();
2719 return *(
static_cast<Iterator*
>(&iter));
2723 ConstIterator end()
const
2725 auto iter = Base::end();
2726 return *(
static_cast<ConstIterator*
>(&iter));
2730 ConstIterator cend()
const
2732 auto iter = Base::end();
2733 return *(
static_cast<ConstIterator*
>(&iter));
2737 template <std::
size_t TAnySize>
2738 bool operator==(
const StaticQueue<T, TAnySize>& other)
const
2740 return Base::operator==(other);
2744 template <std::
size_t TAnySize>
2745 bool operator!=(
const StaticQueue<T, TAnySize>& other)
const
2747 return Base::operator!=(other);
2751 using ArrayType = std::array<StorageType, TSize>;
2752 alignas(
alignof(T)) ArrayType m_array;
2758template <
typename T, std::
size_t TSize>
2759class StaticQueue<T, TSize>::ConstIterator :
public StaticQueue<T, TSize>::Base::ConstIterator
2761 using Base =
typename StaticQueue<T, TSize>::Base::ConstIterator;
2765 using IteratorCategory =
typename Base::IteratorCategory;
2768 using iterator_category = IteratorCategory;
2771 using ValueType =
typename Base::ValueType;
2774 using value_type = ValueType;
2777 using DifferenceType =
typename Base::DifferenceType;
2780 using difference_type = DifferenceType;
2783 using Pointer =
typename Base::Pointer;
2786 using pointer = Pointer;
2789 using ConstPointer =
typename Base::ConstPointer;
2792 using Reference =
typename Base::Reference;
2795 using reference = Reference;
2798 using ConstReference =
typename Base::ConstReference;
2801 using QueueType = StaticQueue<T, TSize>;
2804 using ConstLinearisedIterator =
typename QueueType::ConstLinearisedIterator;
2809 ConstIterator(
const QueueType& queue, ConstLinearisedIterator iterator)
2810 : Base(queue, iterator)
2815 ConstIterator(
const ConstIterator&) =
default;
2820 ConstIterator& operator=(
const ConstIterator& other)
2822 return static_cast<ConstIterator&
>(Base::operator=(other));
2826 ConstIterator& operator++()
2828 return static_cast<ConstIterator&
>(Base::operator++());
2832 ConstIterator operator++(
int dummyParam)
2834 auto tmp = Base::operator++(dummyParam);
2835 return *(
static_cast<ConstIterator*
>(&tmp));
2839 ConstIterator& operator--()
2841 return static_cast<ConstIterator&
>(Base::operator--());
2845 ConstIterator operator--(
int dummyParam)
2847 auto tmp = Base::operator--(dummyParam);
2848 return *(
static_cast<ConstIterator*
>(&tmp));
2853 ConstIterator& operator+=(DifferenceType value)
2855 return static_cast<ConstIterator&
>(Base::operator+=(value));
2860 ConstIterator& operator-=(DifferenceType value)
2862 return static_cast<ConstIterator&
>(Base::operator-=(value));
2869 ConstIterator operator+(DifferenceType value)
const
2871 auto tmp = Base::operator+(value);
2872 return *(
static_cast<ConstIterator*
>(&tmp));
2879 ConstIterator operator-(DifferenceType value)
const
2881 auto tmp = Base::operator-(value);
2882 return *(
static_cast<ConstIterator*
>(&tmp));
2888 DifferenceType operator-(
const ConstIterator& other)
const
2890 return Base::operator-(other);
2895 bool operator==(
const ConstIterator& other)
const
2897 return Base::operator==(other);
2902 bool operator!=(
const ConstIterator& other)
const
2904 return Base::operator!=(other);
2909 bool operator<(
const ConstIterator& other)
const
2911 return Base::operator<(other);
2916 bool operator<=(
const ConstIterator& other)
const
2918 return Base::operator<=(other);
2923 bool operator>(
const ConstIterator& other)
const
2925 return Base::operator>(other);
2930 bool operator>=(
const ConstIterator& other)
const
2932 return Base::operator>=(other);
2936 Reference operator*()
2938 return Base::operator*();
2942 ConstReference operator*()
const
2944 return Base::operator*();
2948 Pointer operator->()
2950 return Base::operator->();
2954 ConstPointer operator->()
const
2956 return Base::operator->();
2963template <
typename T, std::
size_t TSize>
2964class StaticQueue<T, TSize>::Iterator :
public StaticQueue<T, TSize>::Base::Iterator
2966 using Base =
typename StaticQueue<T, TSize>::Base::Iterator;
2970 using IteratorCategory =
typename Base::IteratorCategory;
2973 using iterator_category = IteratorCategory;
2976 using ValueType =
typename Base::ValueType;
2979 using value_type = ValueType;
2982 using DifferenceType =
typename Base::DifferenceType;
2985 using difference_type = DifferenceType;
2988 using Pointer =
typename Base::Pointer;
2991 using pointer = Pointer;
2994 using ConstPointer =
typename Base::ConstPointer;
2997 using Reference =
typename Base::Reference;
3000 using reference = Reference;
3003 using ConstReference =
typename Base::ConstReference;
3006 using QueueType = StaticQueue<T, TSize>;
3009 using LinearisedIterator =
typename QueueType::LinearisedIterator;
3012 using ConstLinearisedIterator =
typename QueueType::ConstLinearisedIterator;
3017 Iterator(QueueType& queue, LinearisedIterator iterator)
3018 : Base(queue, iterator)
3023 Iterator(
const Iterator&) =
default;
3028 Iterator& operator=(
const Iterator& other)
3030 return static_cast<Iterator&
>(Base::operator=(other));
3034 Iterator& operator++()
3036 return static_cast<Iterator&
>(Base::operator++());
3040 Iterator operator++(
int dummyParam)
3042 auto tmp = Base::operator++(dummyParam);
3043 return *(
static_cast<Iterator*
>(&tmp));
3047 Iterator& operator--()
3049 return static_cast<Iterator&
>(Base::operator--());
3053 Iterator operator--(
int dummyParam)
3055 auto tmp = Base::operator--(dummyParam);
3056 return *(
static_cast<Iterator*
>(&tmp));
3061 Iterator& operator+=(DifferenceType value)
3063 return static_cast<Iterator&
>(Base::operator+=(value));
3068 Iterator& operator-=(DifferenceType value)
3070 return static_cast<Iterator&
>(Base::operator-=(value));
3077 Iterator operator+(DifferenceType value)
const
3079 auto tmp = Base::operator+(value);
3080 return *(
static_cast<Iterator*
>(&tmp));
3087 Iterator operator-(DifferenceType value)
const
3089 auto tmp = Base::operator-(value);
3090 return *(
static_cast<Iterator*
>(&tmp));
3096 DifferenceType operator-(
const Iterator& other)
const
3098 return Base::operator-(other);
3103 bool operator==(
const Iterator& other)
const
3105 return Base::operator==(other);
3110 bool operator!=(
const Iterator& other)
const
3112 return Base::operator!=(other);
3117 bool operator<(
const Iterator& other)
const
3119 return Base::operator<(other);
3124 bool operator<=(
const Iterator& other)
const
3126 return Base::operator<=(other);
3131 bool operator>(
const Iterator& other)
const
3133 return Base::operator>(other);
3138 bool operator>=(
const Iterator& other)
const
3140 return Base::operator>=(other);
3144 Reference operator*()
3146 return Base::operator*();
3150 ConstReference operator*()
const
3152 return Base::operator*();
3156 Pointer operator->()
3158 return Base::operator->();
3162 ConstPointer operator->()
const
3164 return Base::operator->();
3167 operator ConstIterator()
const
3169 auto iter =
static_cast<ConstLinearisedIterator
>(Base::getIterator());
3170 const auto& queue =
static_cast<QueueType&
>(Base::getQueue());
3171 return ConstIterator(queue, iter);
3181COMMS_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:170
Contains various compiler related definitions.
Main namespace for all classes / functions of COMMS library.
Replacement to std::conditional.
Definition type_traits.h:32
Replacement to some types from standard type_traits.