26#include "comms/util/SizeToType.h"
30COMMS_MSVC_WARNING_PUSH
31COMMS_MSVC_WARNING_DISABLE(4324)
47 template <
typename TDerived,
typename TQueueType>
55 using StorageType = comms::util::AlignedStorage<
sizeof(ValueType), std::alignment_of<ValueType>::value>;
56 using StorageTypePtr = StorageType*;
57 using ConstStorageTypePtr =
const StorageType*;
58 using SizeType = std::size_t;
59 using Reference = ValueType&;
60 using ConstReference =
const ValueType&;
61 using Pointer = ValueType*;
62 using ConstPointer =
const ValueType*;
63 using LinearisedIterator = Pointer;
64 using ConstLinearisedIterator = ConstPointer;
65 using ReverseLinearisedIterator = std::reverse_iterator<LinearisedIterator>;
66 using ConstReverseLinearisedIterator = std::reverse_iterator<ConstLinearisedIterator>;
67 using LinearisedIteratorRange = std::pair<LinearisedIterator, LinearisedIterator>;
68 using ConstLinearisedIteratorRange = std::pair<ConstLinearisedIterator, ConstLinearisedIterator>;
70 StaticQueueBase(StorageTypePtr data, std::size_t capacity)
78 StaticQueueBase(
const StaticQueueBase&) =
delete;
79 StaticQueueBase(StaticQueueBase&&) =
delete;
81 ~StaticQueueBase() noexcept
86 StaticQueueBase& operator=(
const StaticQueueBase& other)
93 assignElements(other);
97 StaticQueueBase& operator=(StaticQueueBase&& other)
104 assignElements(std::move(other));
108 constexpr std::size_t capacity()
const
113 std::size_t size()
const
127 return (size() == 0);
132 return (size() == capacity());
141 ConstReference front()
const
149 auto constThis =
static_cast<const StaticQueueBase*
>(
this);
150 return const_cast<Reference
>(constThis->back());
153 ConstReference back()
const
160 return (*
this)[count_ - 1];
173 Reference element = front();
178 if ((capacity() <= 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 < &data_[0]) ||
248 (&data_[capacity()] <= cellPtr)) {
253 auto rawIdx = cellPtr - &data_[0];
254 std::size_t actualIdx = capacity();
255 if (rawIdx < startIdx_) {
256 actualIdx = (capacity() - startIdx_) + rawIdx;
259 actualIdx = rawIdx - startIdx_;
262 if (size() <= actualIdx)
271 LinearisedIterator invalidIter()
273 return reinterpret_cast<LinearisedIterator
>(&data_[capacity()]);
276 ConstLinearisedIterator invalidIter()
const
278 return reinterpret_cast<LinearisedIterator
>(&data_[capacity()]);
281 ReverseLinearisedIterator invalidReverseIter()
283 return ReverseLinearisedIterator(
284 reinterpret_cast<LinearisedIterator
>(&data_[0]));
287 ConstReverseLinearisedIterator invalidReverseIter()
const
289 return ReverseLinearisedIterator(
290 reinterpret_cast<LinearisedIterator
>(&data_[0]));
293 LinearisedIterator lbegin()
296 return invalidIter();
299 return reinterpret_cast<LinearisedIterator
>(&data_[0] + startIdx_);
302 ConstLinearisedIterator lbegin()
const
307 ConstLinearisedIterator clbegin()
const
310 return invalidIter();
313 return reinterpret_cast<LinearisedIterator
>(&data_[0] + 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() || ((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 = &data_[startIdx_];
435 auto endCell = std::min(&data_[startIdx_ + size()], &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 = &data_[0];
460 auto endCell = &data_[(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
>(&data_[0]));
579 ConstIterator begin()
const
584 ConstIterator cbegin()
const
586 return ConstIterator(*
this,
reinterpret_cast<ConstLinearisedIterator
>(&data_[0]));
591 return Iterator(*
this,
reinterpret_cast<LinearisedIterator
>(&data_[size()]));
594 ConstIterator end()
const
599 ConstIterator cend()
const
601 return ConstIterator(*
this,
reinterpret_cast<ConstLinearisedIterator
>(&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");
611 using DecayedQueueType =
typename std::decay<
decltype(other)>::type;
612 using NonRefQueueType =
typename std::remove_reference<
decltype(other)>::type;
614 using QueueValueType =
616 std::is_const<NonRefQueueType>::value
618 const typename DecayedQueueType::ValueType,
619 typename DecayedQueueType::ValueType
624 std::is_rvalue_reference<
decltype(other)>::value
626 typename std::add_rvalue_reference<QueueValueType>::type,
627 typename std::add_lvalue_reference<QueueValueType>::type
633 auto rangeOne = other.arrayOne();
634 for (
auto iter = rangeOne.first; iter != rangeOne.second; ++iter) {
635 pushBackNotFull(std::forward<ElemRefType>(*iter));
638 auto rangeTwo = other.arrayTwo();
639 for (
auto iter = rangeTwo.first; iter != rangeTwo.second; ++iter) {
640 pushBackNotFull(std::forward<ElemRefType>(*iter));
644 template <
typename U>
645 void pushBack(U&& value)
651 pushBackNotFull(std::forward<U>(value));
654 template <
typename... TArgs>
655 void emplaceBack(TArgs&&... args)
661 emplaceBackNotFull(std::forward<TArgs>(args)...);
664 template <
typename U>
665 void pushFront(U&& value)
672 pushFrontNotFull(std::forward<U>(value));
675 template <
typename U>
676 LinearisedIterator insert(LinearisedIterator pos, U&& value)
680 return invalidIter();
683 return insertNotFull(pos, std::forward<U>(value));
686 bool operator==(
const StaticQueueBase& other)
const
688 if (size() != other.size()) {
692 auto rangeOne = arrayOne();
693 auto rangeOneSize = std::distance(rangeOne.first, rangeOne.second);
694 auto rangeTwo = arrayTwo();
695 auto otherRangeOne = other.arrayOne();
696 auto otherRangeOneSize = std::distance(otherRangeOne.first, otherRangeOne.second);
697 auto otherRangeTwo = other.arrayTwo();
699 auto firstCompSize = std::min(rangeOneSize, otherRangeOneSize);
700 auto firstCompEnd = rangeOne.first + firstCompSize;
702 auto currIter = rangeOne.first;
703 auto otherCurrIter = otherRangeOne.first;
704 if (!std::equal(currIter, firstCompEnd, otherCurrIter)) {
708 currIter = firstCompEnd;
709 otherCurrIter += firstCompSize;
711 if (currIter != rangeOne.first) {
712 otherCurrIter = otherRangeTwo.first;
713 if (!std::equal(currIter, rangeOne.second, otherCurrIter)) {
716 otherCurrIter += rangeOne.second - currIter;
717 currIter = rangeTwo.first;
720 currIter = rangeTwo.first;
721 if (!std::equal(otherCurrIter, otherRangeOne.second, currIter)) {
725 currIter += otherRangeOne.second - otherCurrIter;
726 otherCurrIter = otherRangeOne.first;
729 COMMS_ASSERT(std::distance(currIter, rangeTwo.second) == std::distance(otherCurrIter, otherRangeTwo.second));
730 return std::equal(currIter, rangeTwo.second, otherCurrIter);
733 bool operator!=(
const StaticQueueBase& other)
const
735 return !(*
this == other);
740 template <
typename U>
741 void createValueAtIndex(U&& value, std::size_t index)
744 Reference elementRef = elementAtIndex(index);
745 auto elementPtr =
new(&elementRef) ValueType(std::forward<U>(value));
746 static_cast<void>(elementPtr);
749 template <
typename U>
750 void pushBackNotFull(U&& value)
753 createValueAtIndex(std::forward<U>(value), size());
757 template <
typename... TArgs>
758 void emplaceBackNotFull(TArgs&&... args)
761 Reference elementRef = elementAtIndex(size());
762 auto elementPtr =
new(&elementRef) ValueType(std::forward<TArgs>(args)...);
763 static_cast<void>(elementPtr);
767 template <
typename U>
768 void pushFrontNotFull(U&& value)
771 createValueAtIndex(std::forward<U>(value), capacity() - 1);
772 if (startIdx_ == 0) {
773 startIdx_ = capacity() - 1;
782 template <
typename U>
783 LinearisedIterator insertNotFull(LinearisedIterator pos, U&& value)
787 auto rangeOne = arrayOne();
788 auto rangeTwo = arrayTwo();
790 if (pos == rangeOne.first) {
791 pushFrontNotFull(std::forward<U>(value));
792 return arrayOne().first;
795 if (pos == rangeTwo.second) {
796 pushBackNotFull(std::forward<U>(value));
797 return arrayTwo().second - 1;
800 auto isInRangeFunc = [](LinearisedIterator pos,
const LinearisedIteratorRange range) ->
bool
802 return ((range.first <= pos) && (pos < range.second));
806 isInRangeFunc(pos, rangeTwo));
808 if (isInRangeFunc(pos, rangeOne)) {
809 pushFrontNotFull(std::move(front()));
811 std::move(rangeOne.first + 1, pos, rangeOne.first);
812 *pos = std::forward<U>(value);
816 if (isInRangeFunc(pos, rangeTwo)) {
817 pushBackNotFull(std::move(back()));
818 std::move_backward(pos, rangeTwo.second - 1, rangeTwo.second);
819 *pos = std::forward<U>(value);
823 return invalidIter();
826 Reference elementAtIndex(std::size_t index) {
827 auto constThis =
static_cast<const StaticQueueBase*
>(
this);
828 return const_cast<Reference
>(constThis->elementAtIndex(index));
831 ConstReference elementAtIndex(std::size_t index)
const
833 std::size_t rawIdx = startIdx_ + index;
834 while (capacity() <= rawIdx) {
835 rawIdx = rawIdx - capacity();
838 auto cellAddr = &data_[rawIdx];
839 return *(
reinterpret_cast<ConstPointer
>(cellAddr));
842 template <
typename TIter>
843 void lineariseByMove(
844 const std::pair<TIter, TIter> firstRange,
845 const std::pair<TIter, TIter> secondRange)
847 auto movConstructFirstSize =
849 std::size_t(std::distance(firstRange.first, firstRange.second)),
850 capacity() - size());
851 auto movConstructFirstEnd = firstRange.first + movConstructFirstSize;
852 COMMS_ASSERT(movConstructFirstEnd <= firstRange.second);
853 COMMS_ASSERT(movConstructFirstSize <= (firstRange.second - firstRange.first));
855 auto newPlacePtr = secondRange.second;
856 for (
auto iter = firstRange.first; iter != movConstructFirstEnd; ++iter) {
857 auto ptr =
new (&(*newPlacePtr)) ValueType(std::move(*iter));
858 static_cast<void>(ptr);
862 std::move(movConstructFirstEnd, firstRange.second, newPlacePtr);
863 newPlacePtr += (firstRange.second - movConstructFirstEnd);
865 auto movConstructTwoSize = 0;
866 if (newPlacePtr < firstRange.first) {
867 movConstructTwoSize =
868 std::min(std::distance(newPlacePtr, firstRange.first),
869 std::distance(secondRange.first, secondRange.second));
872 auto movConstructTwoEnd = secondRange.first + movConstructTwoSize;
873 for (
auto iter = secondRange.first; iter != movConstructTwoEnd; ++iter) {
874 auto ptr =
new (&(*newPlacePtr)) ValueType(std::move(*iter));
875 static_cast<void>(ptr);
879 std::move(movConstructTwoEnd, secondRange.second, newPlacePtr);
880 newPlacePtr += (secondRange.second - movConstructTwoEnd);
882 for (
auto iter = std::max(newPlacePtr, firstRange.first); iter != firstRange.second; ++iter) {
886 for (
auto iter = secondRange.first; iter != secondRange.second; ++iter) {
891 void lineariseByMoveOneTwo(
892 const LinearisedIteratorRange& rangeOne,
893 const LinearisedIteratorRange& rangeTwo)
895 lineariseByMove(rangeOne, rangeTwo);
896 startIdx_ = std::distance(rangeTwo.first, rangeTwo.second);
899 void lineariseByMoveTwoOne(
900 const LinearisedIteratorRange& rangeOne,
901 const LinearisedIteratorRange& rangeTwo)
903 using RevIter = std::reverse_iterator<Pointer>;
905 std::make_pair(RevIter(rangeTwo.second), RevIter(rangeTwo.first)),
906 std::make_pair(RevIter(rangeOne.second), RevIter(rangeOne.first)));
908 startIdx_ = (capacity() - std::distance(rangeOne.first, rangeOne.second)) - size();
911 void lineariseByPopOne()
917 ValueType tmp(std::move(front()));
920 if (startIdx_ == 0) {
921 using RevIter = std::reverse_iterator<LinearisedIterator>;
923 RevIter(
reinterpret_cast<LinearisedIterator
>(&data_[capacity()]));
924 moveRange(rlbegin(), rlend(), target);
925 startIdx_ = capacity() - size();
927 pushFront(std::move(tmp));
931 void lineariseByPopTwo()
937 ValueType tmp(std::move(back()));
940 if (startIdx_ != 0) {
941 auto target =
reinterpret_cast<LinearisedIterator
>(&data_[0]);
942 moveRange(lbegin(), lend(), target);
945 pushBack(std::move(tmp));
949 template <
typename TIter>
950 void moveRange(TIter rangeBeg, TIter rangeEnd, TIter target)
953 auto moveConstructSize =
955 std::distance(rangeBeg, rangeEnd),
956 std::distance(target, rangeBeg));
958 TIter moveConstructEnd = rangeBeg + moveConstructSize;
959 for (
auto iter = rangeBeg; iter != moveConstructEnd; ++iter) {
960 auto ptr =
new (&(*target)) ValueType(std::move(*iter));
961 static_cast<void>(ptr);
966 std::move(moveConstructEnd, rangeEnd, target);
967 target += std::distance(moveConstructEnd, rangeEnd);
969 for (
auto iter = std::max(target, rangeBeg); iter != rangeEnd; ++iter) {
974 StorageTypePtr
const data_;
975 const std::size_t capacity_;
976 std::size_t startIdx_;
981template <
typename TDerived,
typename TQueueType>
982class StaticQueueBase<T>::IteratorBase
984 friend class StaticQueueBase<T>;
987 IteratorBase(
const IteratorBase&) =
default;
989 ~IteratorBase() noexcept = default;
992 using Derived = TDerived;
993 using QueueType = TQueueType;
994 using ArrayIterator = decltype(
std::declval<QueueType>().lbegin());
995 using IteratorCategory = typename
std::iterator_traits<ArrayIterator>::iterator_category;
996 using iterator_category = IteratorCategory;
997 using ValueType = typename
std::iterator_traits<ArrayIterator>::value_type;
998 using value_type = ValueType;
999 using DifferenceType = typename
std::iterator_traits<ArrayIterator>::difference_type;
1000 using difference_type = DifferenceType;
1001 using Pointer = typename
std::iterator_traits<ArrayIterator>::pointer;
1002 using pointer = Pointer;
1003 using ConstPointer =
1004 typename
std::add_pointer<
1005 typename
std::add_const<
1006 typename
std::remove_pointer<Pointer>::type
1009 using Reference = typename
std::iterator_traits<ArrayIterator>::reference;
1010 using reference = Reference;
1011 using ConstReference = typename
std::add_const<Reference>::type;
1013 IteratorBase(QueueType& queue, ArrayIterator iterator)
1019 Derived& operator=(
const IteratorBase& other)
1022 iterator_ = other.iterator_;
1023 return static_cast<Derived&
>(*this);
1026 Derived& operator++()
1029 return static_cast<Derived&
>(*this);
1032 Derived operator++(
int)
1034 IteratorBase copy(*
this);
1036 return std::move(*(
static_cast<Derived*
>(©)));
1039 Derived& operator--()
1042 return static_cast<Derived&
>(*this);
1045 Derived operator--(
int)
1047 IteratorBase copy(*
this);
1049 return std::move(*(
static_cast<Derived*
>(©)));
1052 Derived& operator+=(DifferenceType value)
1055 return static_cast<Derived&
>(*this);
1058 Derived& operator-=(DifferenceType value)
1061 return static_cast<Derived&
>(*this);
1064 Derived operator+(DifferenceType value)
const
1066 IteratorBase copy(*
this);
1068 return std::move(*(
static_cast<Derived*
>(©)));
1071 Derived operator-(DifferenceType value)
const
1073 IteratorBase copy(*
this);
1075 return std::move(*(
static_cast<Derived*
>(©)));
1078 DifferenceType operator-(
const IteratorBase& other)
const
1080 return iterator_ - other.iterator_;
1083 bool operator==(
const IteratorBase& other)
const
1085 return (iterator_ == other.iterator_);
1088 bool operator!=(
const IteratorBase& other)
const
1090 return (iterator_ != other.iterator_);
1093 bool operator<(
const IteratorBase& other)
const
1095 return iterator_ < other.iterator_;
1098 bool operator<=(
const IteratorBase& other)
const
1100 return iterator_ <= other.iterator_;
1103 bool operator>(
const IteratorBase& other)
const
1105 return iterator_ > other.iterator_;
1108 bool operator>=(
const IteratorBase& other)
const
1110 return iterator_ >= other.iterator_;
1113 Reference operator*()
1115 auto& constThisRef =
static_cast<const IteratorBase&
>(*this);
1116 auto& constRef = *constThisRef;
1117 return const_cast<Reference
>(constRef);
1120 ConstReference operator*()
const
1122 auto begCell =
reinterpret_cast<ArrayIterator
>(&queue_.data_[0]);
1123 auto idx = iterator_ - begCell;
1125 return queue_[
static_cast<std::size_t
>(idx)];
1128 Pointer operator->()
1133 ConstPointer operator->()
const
1138 QueueType& getQueue() {
1142 typename std::add_const<QueueType&>::type getQueue()
const
1147 ArrayIterator& getIterator() {
1151 typename std::add_const<ArrayIterator>::type& getIterator()
const
1159 ArrayIterator iterator_;
1162template <
typename T>
1163class StaticQueueBase<T>::ConstIterator :
1164 public StaticQueueBase<T>::template
1165 IteratorBase<typename StaticQueueBase<T>::ConstIterator, const StaticQueueBase<T> >
1167 using Base =
typename StaticQueueBase<T>::template
1168 IteratorBase<typename StaticQueueBase<T>::ConstIterator,
const StaticQueueBase<T> >;
1171 using QueueType =
typename Base::QueueType;
1172 using ArrayIterator =
typename Base::ArrayIterator;
1174 ConstIterator(
const ConstIterator&) =
default;
1175 ~ConstIterator() noexcept = default;
1177 ConstIterator(QueueType& queue, ArrayIterator iterator)
1178 : Base(queue, iterator)
1184template <
typename T>
1185class StaticQueueBase<T>::Iterator :
1186 public StaticQueueBase<T>::template
1187 IteratorBase<typename StaticQueueBase<T>::Iterator, StaticQueueBase<T> >
1189 using Base =
typename StaticQueueBase<T>::template
1190 IteratorBase<typename StaticQueueBase<T>::Iterator, StaticQueueBase<T> >;
1193 using QueueType =
typename Base::QueueType;
1194 using ArrayIterator =
typename Base::ArrayIterator;
1196 Iterator(
const Iterator&) =
default;
1197 ~Iterator() noexcept = default;
1199 Iterator(QueueType& queue, ArrayIterator iterator)
1200 : Base(queue, iterator)
1204 operator ConstIterator()
const
1206 return ConstIterator(Base::getQueue(), Base::getIterator());
1211template <
typename TWrapperElemType,
typename TQueueElemType>
1212class CastWrapperQueueBase :
public StaticQueueBase<TQueueElemType>
1214 using Base = StaticQueueBase<TQueueElemType>;
1215 using WrapperElemType = TWrapperElemType;
1217 using BaseValueType =
typename Base::ValueType;
1218 using BaseStorageTypePtr =
typename Base::StorageTypePtr;
1219 using BaseReference =
typename Base::Reference;
1220 using BaseConstReference =
typename Base::ConstReference;
1221 using BasePointer =
typename Base::Pointer;
1222 using BaseConstPointer =
typename Base::ConstPointer;
1223 using BaseLinearisedIterator =
typename Base::LinearisedIterator;
1224 using BaseConstLinearisedIterator =
typename Base::ConstLinearisedIterator;
1225 using BaseReverseLinearisedIterator =
typename Base::ReverseLinearisedIterator;
1226 using BaseConstReverseLinearisedIterator =
typename Base::ConstReverseLinearisedIterator;
1227 using BaseLinearisedIteratorRange =
typename Base::LinearisedIteratorRange;
1228 using BaseConstLinearisedIteratorRange =
typename Base::ConstLinearisedIteratorRange;
1232 class ConstIterator;
1236 using ValueType = WrapperElemType;
1237 using StorageType = comms::util::AlignedStorage<
sizeof(ValueType), std::alignment_of<ValueType>::value>;
1238 using StorageTypePtr = StorageType*;
1239 using Reference = ValueType&;
1240 using ConstReference =
const ValueType&;
1241 using Pointer = ValueType*;
1242 using ConstPointer =
const ValueType*;
1243 using LinearisedIterator = Pointer;
1244 using ConstLinearisedIterator = ConstPointer;
1245 using ReverseLinearisedIterator = std::reverse_iterator<LinearisedIterator>;
1246 using ConstReverseLinearisedIterator = std::reverse_iterator<ConstLinearisedIterator>;
1247 using LinearisedIteratorRange = std::pair<LinearisedIterator, LinearisedIterator>;
1248 using ConstLinearisedIteratorRange = std::pair<ConstLinearisedIterator, ConstLinearisedIterator>;
1250 CastWrapperQueueBase(StorageTypePtr data, std::size_t capacity)
1251 : Base(reinterpret_cast<BaseStorageTypePtr>(data), capacity)
1253 static_assert(
sizeof(ValueType) ==
sizeof(BaseValueType),
1254 "The times must have identical size.");
1257 ~CastWrapperQueueBase() noexcept = default;
1259 CastWrapperQueueBase& operator=(const CastWrapperQueueBase& other) = default;
1260 CastWrapperQueueBase& operator=(CastWrapperQueueBase&& other) = default;
1264 return reinterpret_cast<Reference
>(Base::front());
1267 ConstReference front()
const
1269 return reinterpret_cast<ConstReference
>(Base::front());
1274 return reinterpret_cast<Reference
>(Base::back());
1277 ConstReference back()
const
1279 return reinterpret_cast<Reference
>(Base::back());
1282 Reference operator[](std::size_t index)
1284 return reinterpret_cast<Reference
>(Base::operator[](index));
1287 ConstReference operator[](std::size_t index)
const
1289 return reinterpret_cast<ConstReference
>(Base::operator[](index));
1292 Reference at(std::size_t index)
1294 return reinterpret_cast<Reference
>(Base::at(index));
1297 ConstReference at(std::size_t index)
const
1299 return reinterpret_cast<ConstReference
>(Base::at(index));
1302 int indexOf(ConstReference element)
const
1304 return Base::indexOf(
reinterpret_cast<BaseConstReference
>(element));
1307 LinearisedIterator invalidIter()
1309 return reinterpret_cast<LinearisedIterator
>(Base::invalidIter());
1312 ConstLinearisedIterator invalidIter()
const
1314 return reinterpret_cast<ConstLinearisedIterator
>(Base::invalidIter());
1317 ReverseLinearisedIterator invalidReverseIter()
1319 return ReverseLinearisedIterator(
1320 reinterpret_cast<LinearisedIterator
>(
1321 Base::invalidReverseIter().base()));
1324 ConstReverseLinearisedIterator invalidReverseIter()
const
1326 return ConstReverseLinearisedIterator(
1327 reinterpret_cast<ConstLinearisedIterator
>(
1328 Base::invalidReverseIter().base()));
1331 LinearisedIterator lbegin()
1333 return reinterpret_cast<LinearisedIterator
>(Base::lbegin());
1336 ConstLinearisedIterator lbegin()
const
1338 return reinterpret_cast<ConstLinearisedIterator
>(Base::lbegin());
1341 ConstLinearisedIterator clbegin()
const
1343 return reinterpret_cast<ConstLinearisedIterator
>(Base::clbegin());
1346 ReverseLinearisedIterator rlbegin()
1348 return ReverseLinearisedIterator(
1349 reinterpret_cast<LinearisedIterator
>(
1350 Base::rlbegin().base()));
1353 ConstReverseLinearisedIterator rlbegin()
const
1355 return ConstReverseLinearisedIterator(
1356 reinterpret_cast<ConstLinearisedIterator
>(
1357 Base::rlbegin().base()));
1360 ConstReverseLinearisedIterator crlbegin()
const
1362 return ConstReverseLinearisedIterator(
1363 reinterpret_cast<ConstLinearisedIterator
>(
1364 Base::crlbegin().base()));
1367 LinearisedIterator lend()
1369 return reinterpret_cast<LinearisedIterator
>(Base::lend());
1372 ConstLinearisedIterator lend()
const
1374 return reinterpret_cast<ConstLinearisedIterator
>(Base::lend());
1377 ConstLinearisedIterator clend()
const
1379 return reinterpret_cast<ConstLinearisedIterator
>(Base::clend());
1382 ReverseLinearisedIterator rlend()
1384 return ReverseLinearisedIterator(
1385 reinterpret_cast<LinearisedIterator
>(
1386 Base::rlend().base()));
1389 ConstReverseLinearisedIterator rlend()
const
1391 return ConstReverseLinearisedIterator(
1392 reinterpret_cast<ConstLinearisedIterator
>(
1393 Base::rlend().base()));
1396 ConstReverseLinearisedIterator crlend()
const
1398 return ConstReverseLinearisedIterator(
1399 reinterpret_cast<ConstLinearisedIterator
>(
1400 Base::crlend().base()));
1403 LinearisedIteratorRange arrayOne()
1405 auto range = Base::arrayOne();
1406 return LinearisedIteratorRange(
1407 reinterpret_cast<LinearisedIterator
>(range.first),
1408 reinterpret_cast<LinearisedIterator
>(range.second));
1411 ConstLinearisedIteratorRange arrayOne()
const
1413 auto range = Base::arrayOne();
1414 return ConstLinearisedIteratorRange(
1415 reinterpret_cast<ConstLinearisedIterator
>(range.first),
1416 reinterpret_cast<ConstLinearisedIterator
>(range.second));
1420 LinearisedIteratorRange arrayTwo()
1422 auto range = Base::arrayTwo();
1423 return LinearisedIteratorRange(
1424 reinterpret_cast<LinearisedIterator
>(range.first),
1425 reinterpret_cast<LinearisedIterator
>(range.second));
1429 ConstLinearisedIteratorRange arrayTwo()
const
1431 auto range = Base::arrayTwo();
1432 return ConstLinearisedIteratorRange(
1433 reinterpret_cast<ConstLinearisedIterator
>(range.first),
1434 reinterpret_cast<ConstLinearisedIterator
>(range.second));
1438 LinearisedIterator erase(LinearisedIterator pos)
1440 return reinterpret_cast<LinearisedIterator
>(
1442 reinterpret_cast<BaseLinearisedIterator
>(pos)));
1445 Iterator erase(Iterator pos)
1447 auto tmp = Base::erase(pos);
1448 return *(
reinterpret_cast<Iterator*
>(&tmp));
1453 auto tmp = Base::begin();
1454 return *(
reinterpret_cast<Iterator*
>(&tmp));
1457 ConstIterator begin()
const
1459 auto tmp = Base::begin();
1460 return *(
reinterpret_cast<ConstIterator*
>(&tmp));
1463 ConstIterator cbegin()
const
1465 auto tmp = Base::cbegin();
1466 return *(
reinterpret_cast<ConstIterator*
>(&tmp));
1472 auto tmp = Base::end();
1473 return *(
reinterpret_cast<Iterator*
>(&tmp));
1476 ConstIterator end()
const
1478 auto tmp = Base::end();
1479 return *(
reinterpret_cast<ConstIterator*
>(&tmp));
1482 ConstIterator cend()
const
1484 auto tmp = Base::cend();
1485 return *(
reinterpret_cast<ConstIterator*
>(&tmp));
1488 void pushBack(ConstReference value)
1490 Base::pushBack(
reinterpret_cast<BaseConstReference
>(value));
1493 void pushFront(ConstReference value)
1495 Base::pushFront(
reinterpret_cast<BaseConstReference
>(value));
1498 LinearisedIterator insert(LinearisedIterator pos, ConstReference value)
1500 return reinterpret_cast<LinearisedIterator
>(
1502 reinterpret_cast<BaseLinearisedIterator
>(pos),
1503 reinterpret_cast<BaseConstReference
>(value)));
1506 void assignElements(
const CastWrapperQueueBase& other)
1508 Base::assignElements(
static_cast<const Base&
>(other));
1511 void assignElements(CastWrapperQueueBase&& other)
1513 Base::assignElements(
static_cast<Base&&
>(std::move(other)));
1517template <
typename TWrapperElemType,
typename TQueueElemType>
1518class CastWrapperQueueBase<TWrapperElemType, TQueueElemType>::ConstIterator :
1519 public StaticQueueBase<TQueueElemType>::ConstIterator
1521 using Base =
typename StaticQueueBase<TQueueElemType>::ConstIterator;
1523 ConstIterator(
const ConstIterator&) =
default;
1524 ConstIterator& operator=(
const ConstIterator&) =
default;
1525 ~ConstIterator() noexcept = default;
1528 using ExpectedQueueType = const StaticQueueBase<TWrapperElemType>;
1529 using ActualQueueType = const StaticQueueBase<TQueueElemType>;
1530 using ValueType = TWrapperElemType;
1531 using Reference = const ValueType&;
1532 using ConstReference = const ValueType&;
1533 using Pointer = const ValueType*;
1534 using ConstPointer = const ValueType*;
1535 using DifferenceType = typename Base::DifferenceType;
1537 ConstIterator(ExpectedQueueType& queue, Pointer iterator)
1538 : Base(reinterpret_cast<ActualQueueType&>(queue), iterator)
1542 ConstIterator& operator++()
1548 ConstIterator operator++(
int dummy)
1550 auto tmp = Base::operator++(dummy);
1551 return *(
static_cast<ConstIterator*
>(&tmp));
1554 ConstIterator& operator--()
1560 ConstIterator operator--(
int dummy)
1562 auto tmp = Base::operator--(dummy);
1563 return *(
static_cast<ConstIterator*
>(&tmp));
1566 ConstIterator& operator+=(DifferenceType value)
1568 Base::operator+=(value);
1572 ConstIterator& operator-=(DifferenceType value)
1574 Base::operator-=(value);
1578 ConstIterator operator+(DifferenceType value)
const
1580 auto tmp = Base::operator+(value);
1581 return *(
static_cast<ConstIterator*
>(&tmp));
1584 ConstIterator operator-(DifferenceType value)
const
1586 auto tmp = Base::operator-(value);
1587 return *(
static_cast<ConstIterator*
>(&tmp));
1590 DifferenceType operator-(
const ConstIterator& other)
const
1592 return Base::operator-(other);
1595 Reference operator*()
1597 auto& ref = Base::operator*();
1598 return reinterpret_cast<Reference
>(ref);
1601 ConstReference operator*()
const
1603 auto& ref = Base::operator*();
1604 return reinterpret_cast<ConstReference
>(ref);
1607 Pointer operator->()
1609 auto* ptr = Base::operator->();
1610 return reinterpret_cast<Pointer
>(ptr);
1613 ConstPointer operator->()
const
1615 auto* ptr = Base::operator->();
1616 return reinterpret_cast<ConstPointer
>(ptr);
1620template <
typename TWrapperElemType,
typename TQueueElemType>
1621class CastWrapperQueueBase<TWrapperElemType, TQueueElemType>::Iterator :
1622 public StaticQueueBase<TQueueElemType>::Iterator
1624 using Base =
typename StaticQueueBase<TQueueElemType>::Iterator;
1626 Iterator(
const Iterator&) =
default;
1627 Iterator& operator=(
const Iterator&) =
default;
1628 ~Iterator() noexcept = default;
1631 using ExpectedQueueType = const StaticQueueBase<TWrapperElemType>;
1632 using ActualQueueType = const StaticQueueBase<TQueueElemType>;
1633 using ValueType = TWrapperElemType;
1634 using Reference = ValueType&;
1635 using ConstReference = const ValueType&;
1636 using Pointer = ValueType*;
1637 using ConstPointer = const ValueType*;
1638 using DifferenceType = typename Base::DifferenceType;
1640 Iterator(ExpectedQueueType& queue, Pointer iterator)
1641 : Base(reinterpret_cast<ActualQueueType&>(queue), iterator)
1645 Iterator& operator++()
1651 Iterator operator++(
int dummy)
1653 auto tmp = Base::operator++(dummy);
1654 return *(
static_cast<Iterator*
>(&tmp));
1657 Iterator& operator--()
1663 Iterator operator--(
int dummy)
1665 auto tmp = Base::operator--(dummy);
1666 return *(
static_cast<Iterator*
>(&tmp));
1669 Iterator& operator+=(DifferenceType value)
1671 Base::operator+=(value);
1675 Iterator& operator-=(DifferenceType value)
1677 Base::operator-=(value);
1681 Iterator operator+(DifferenceType value)
const
1683 auto tmp = Base::operator+(value);
1684 return *(
static_cast<Iterator*
>(&tmp));
1687 Iterator operator-(DifferenceType value)
const
1689 auto tmp = Base::operator-(value);
1690 return *(
static_cast<Iterator*
>(&tmp));
1693 DifferenceType operator-(
const Iterator& other)
const
1695 return Base::operator-(other);
1698 Reference operator*()
1700 auto& ref = Base::operator*();
1701 return reinterpret_cast<Reference
>(ref);
1704 ConstReference operator*()
const
1706 auto& ref = Base::operator*();
1707 return reinterpret_cast<ConstReference
>(ref);
1710 Pointer operator->()
1712 auto* ptr = Base::operator->();
1713 return reinterpret_cast<Pointer
>(ptr);
1716 ConstPointer operator->()
const
1718 auto* ptr = Base::operator->();
1719 return reinterpret_cast<ConstPointer
>(ptr);
1723template <
typename T>
1724class StaticQueueBaseOptimised :
public StaticQueueBase<T>
1726 usign Base = StaticQueueBase<T>;
1729 using StorageTypePtr =
typename Base::StorageTypePtr;
1731 StaticQueueBaseOptimised(StorageTypePtr data, std::size_t capacity)
1732 : Base(data, capacity)
1736 ~StaticQueueBaseOptimised() noexcept = default;
1738 StaticQueueBaseOptimised& operator=(const StaticQueueBaseOptimised& other) = default;
1739 StaticQueueBaseOptimised& operator=(StaticQueueBaseOptimised&& other) = default;
1743class StaticQueueBaseOptimised<
std::int8_t> : public CastWrapperQueueBase<
std::int8_t,
std::uint8_t>
1745 using Base = CastWrapperQueueBase<std::int8_t, std::uint8_t>;
1748 using StorageTypePtr =
typename Base::StorageTypePtr;
1750 StaticQueueBaseOptimised(StorageTypePtr data, std::size_t capacity)
1751 : Base(data, capacity)
1755 ~StaticQueueBaseOptimised() noexcept = default;
1756 StaticQueueBaseOptimised& operator=(const StaticQueueBaseOptimised& other) = default;
1757 StaticQueueBaseOptimised& operator=(StaticQueueBaseOptimised&& other) = default;
1761class StaticQueueBaseOptimised<
std::int16_t> : public CastWrapperQueueBase<
std::int16_t,
std::uint16_t>
1763 using Base = CastWrapperQueueBase<std::int16_t, std::uint16_t>;
1766 using StorageTypePtr =
typename Base::StorageTypePtr;
1768 StaticQueueBaseOptimised(StorageTypePtr data, std::size_t capacity)
1769 : Base(data, capacity)
1773 ~StaticQueueBaseOptimised() noexcept = default;
1774 StaticQueueBaseOptimised& operator=(const StaticQueueBaseOptimised& other) = default;
1775 StaticQueueBaseOptimised& operator=(StaticQueueBaseOptimised&& other) = default;
1779class StaticQueueBaseOptimised<
std::int32_t> : public CastWrapperQueueBase<
std::int32_t,
std::uint32_t>
1781 using Base = CastWrapperQueueBase<std::int32_t, std::uint32_t>;
1784 using StorageTypePtr =
typename Base::StorageTypePtr;
1786 StaticQueueBaseOptimised(StorageTypePtr data, std::size_t capacity)
1787 : Base(data, capacity)
1791 ~StaticQueueBaseOptimised() noexcept = default;
1792 StaticQueueBaseOptimised& operator=(const StaticQueueBaseOptimised& other) = default;
1793 StaticQueueBaseOptimised& operator=(StaticQueueBaseOptimised&& other) = default;
1797class StaticQueueBaseOptimised<
std::int64_t> : public CastWrapperQueueBase<
std::int64_t,
std::uint64_t>
1799 using Base = CastWrapperQueueBase<std::int64_t, std::uint64_t>;
1802 using StorageTypePtr =
typename Base::StorageTypePtr;
1804 StaticQueueBaseOptimised(StorageTypePtr data, std::size_t capacity)
1805 : Base(data, capacity)
1809 ~StaticQueueBaseOptimised() noexcept = default;
1810 StaticQueueBaseOptimised& operator=(const StaticQueueBaseOptimised& other) = default;
1811 StaticQueueBaseOptimised& operator=(StaticQueueBaseOptimised&& other) = default;
1814template <typename T>
1815class StaticQueueBaseOptimised<T*> : public CastWrapperQueueBase<T*, typename
comms::util::SizeToType<sizeof(T*)>::Type>
1817 using Base = CastWrapperQueueBase<T*,
typename comms::util::SizeToType<
sizeof(T*)>::Type>;
1820 using Base =
typename Base::StorageTypePtr;
1822 StaticQueueBaseOptimised(StorageTypePtr data, std::size_t capacity)
1823 : Base(data, capacity)
1827 ~StaticQueueBaseOptimised() noexcept = default;
1828 StaticQueueBaseOptimised& operator=(const StaticQueueBaseOptimised& other) = default;
1829 StaticQueueBaseOptimised& operator=(StaticQueueBaseOptimised&& other) = default;
1847template <typename T,
std::
size_t TSize>
1848class StaticQueue : public details::StaticQueueBaseOptimised<T>
1850 using Base = details::StaticQueueBaseOptimised<T>;
1852 using StorageType =
typename Base::StorageType;
1855 using ValueType =
typename Base::ValueType;
1858 using value_type = ValueType;
1861 using SizeType =
typename Base::SizeType;
1864 using size_type = SizeType;
1867 using Reference =
typename Base::Reference;
1870 using reference = Reference;
1873 using ConstReference =
typename Base::ConstReference;
1876 using const_reference = ConstReference;
1879 using Pointer =
typename Base::Pointer;
1882 using pointer = Pointer;
1885 using ConstPointer =
typename Base::ConstPointer;
1888 using const_pointer = ConstPointer;
1891 using LinearisedIterator =
typename Base::LinearisedIterator;
1894 using ConstLinearisedIterator =
typename Base::ConstLinearisedIterator;
1897 using ReverseLinearisedIterator =
typename Base::ReverseLinearisedIterator;
1900 using ConstReverseLinearisedIterator =
typename Base::ConstReverseLinearisedIterator;
1903 using LinearisedIteratorRange =
typename Base::LinearisedIteratorRange;
1906 using ConstLinearisedIteratorRange =
typename Base::ConstLinearisedIteratorRange;
1909 class ConstIterator;
1912 using const_iterator = ConstIterator;
1918 using iterator = Iterator;
1926 : Base(&array_[0], TSize)
1938 StaticQueue(
const StaticQueue& queue)
1939 : Base(&array_[0], TSize)
1941 Base::assignElements(queue);
1952 StaticQueue(StaticQueue&& queue)
1953 : Base(&array_[0], TSize)
1955 Base::assignElements(std::move(queue));
1967 template <std::
size_t TAnySize>
1968 StaticQueue(
const StaticQueue<T, TAnySize>& queue)
1969 : Base(&array_[0], TSize)
1971 Base::assignElements(queue);
1982 template <std::
size_t TAnySize>
1983 StaticQueue(StaticQueue<T, TAnySize>&& queue)
1984 : Base(&array_[0], TSize)
1986 Base::assignElements(std::move(queue));
1995 ~StaticQueue() noexcept
2010 StaticQueue& operator=(
const StaticQueue& queue)
2012 return static_cast<StaticQueue&
>(Base::operator=(queue));
2025 StaticQueue& operator=(StaticQueue&& queue)
2027 return static_cast<StaticQueue&
>(Base::operator=(std::move(queue)));
2042 template <std::
size_t TAnySize>
2043 StaticQueue& operator=(
const StaticQueue<T, TAnySize>& queue)
2045 return static_cast<StaticQueue&
>(Base::operator=(queue));
2059 template <std::
size_t TAnySize>
2060 StaticQueue& operator=(StaticQueue<T, TAnySize>&& queue)
2062 return static_cast<StaticQueue&
>(Base::operator=(std::move(queue)));
2071 static constexpr std::size_t capacity()
2083 std::size_t size()
const
2085 return Base::size();
2095 return Base::empty();
2099 bool isEmpty()
const
2111 return Base::full();
2142 inline void pop_back()
2156 void popBack(std::size_t count)
2158 Base::popBack(count);
2162 void pop_back(std::size_t count)
2179 inline void pop_front()
2191 void popFront(std::size_t count)
2193 Base::popFront(count);
2197 inline void pop_front(std::size_t count)
2209 template <
typename U>
2210 void pushBack(U&& value)
2212 Base::pushBack(std::forward<U>(value));
2223 template <
typename... TArgs>
2224 void emplaceBack(TArgs&&... args)
2226 Base::emplaceBack(std::forward<TArgs>(args)...);
2230 template <
typename U>
2231 inline void push_back(U&& value)
2233 pushBack(std::forward<U>(value));
2243 template <
typename U>
2244 void pushFront(U&& value)
2246 Base::pushFront(std::forward<U>(value));
2250 template <
typename U>
2251 inline void push_front(U&& value)
2253 pushFront(std::forward<U>(value));
2271 template <
typename U>
2272 LinearisedIterator insert(LinearisedIterator pos, U&& value)
2274 return Base::insert(pos, std::forward<U>(value));
2286 return Base::front();
2290 ConstReference front()
const
2292 return Base::front();
2303 return Base::back();
2307 ConstReference back()
const
2309 return Base::back();
2322 Reference operator[](std::size_t index)
2324 return Base::operator[](index);
2328 ConstReference operator[](std::size_t index)
const
2330 return Base::operator[](index);
2344 Reference at(std::size_t index)
2346 return Base::at(index);
2350 ConstReference at(std::size_t index)
const
2352 return Base::at(index);
2364 int indexOf(ConstReference element)
const
2366 return Base::indexOf(element);
2375 LinearisedIterator invalidIter()
2377 return Base::invalidIter();
2381 ConstLinearisedIterator invalidIter()
const
2383 return Base::invalidIter();
2391 ReverseLinearisedIterator invalidReverseIter()
2393 return Base::invalidReverseIter();
2397 ConstReverseLinearisedIterator invalidReverseIter()
const
2399 return Base::invalidReverseIter();
2416 LinearisedIterator lbegin()
2418 return Base::lbegin();
2422 ConstLinearisedIterator lbegin()
const
2424 return Base::lbegin();
2428 ConstLinearisedIterator clbegin()
const
2430 return Base::clbegin();
2447 ReverseLinearisedIterator rlbegin()
2449 return Base::rlbegin();
2453 ConstReverseLinearisedIterator rlbegin()
const
2455 return Base::rlbegin();
2459 ConstReverseLinearisedIterator crlbegin()
const
2461 return Base::crlbegin();
2476 LinearisedIterator lend()
2478 return Base::lend();
2482 ConstLinearisedIterator lend()
const
2484 return Base::lend();
2488 ConstLinearisedIterator clend()
const
2490 return Base::clend();
2505 ReverseLinearisedIterator rlend()
2507 return Base::rlend();
2511 ConstReverseLinearisedIterator rlend()
const
2513 return Base::rlend();
2517 ConstReverseLinearisedIterator crlend()
const
2519 return Base::crlend();
2562 bool linearised()
const
2564 return Base::linearised();
2568 bool isLinearised()
const
2570 return linearised();
2592 LinearisedIteratorRange arrayOne()
2594 return Base::arrayOne();
2598 ConstLinearisedIteratorRange arrayOne()
const
2600 return Base::arrayOne();
2626 LinearisedIteratorRange arrayTwo()
2628 return Base::arrayTwo();
2632 ConstLinearisedIteratorRange arrayTwo()
const
2634 return Base::arrayTwo();
2650 void resize(std::size_t newSize)
2652 Base::resize(newSize);
2666 LinearisedIterator erase(LinearisedIterator pos)
2668 return Base::erase(pos);
2681 Iterator erase(Iterator pos)
2683 auto iter = Base::erase(pos);
2684 return *(
static_cast<Iterator*
>(&iter));
2697 auto iter = Base::begin();
2698 return *(
static_cast<Iterator*
>(&iter));
2702 ConstIterator begin()
const
2704 auto iter = Base::begin();
2705 return *(
static_cast<ConstIterator*
>(&iter));
2709 ConstIterator cbegin()
const
2711 auto iter = Base::cbegin();
2712 return *(
static_cast<ConstIterator*
>(&iter));
2725 auto iter = Base::end();
2726 return *(
static_cast<Iterator*
>(&iter));
2730 ConstIterator end()
const
2732 auto iter = Base::end();
2733 return *(
static_cast<ConstIterator*
>(&iter));
2737 ConstIterator cend()
const
2739 auto iter = Base::end();
2740 return *(
static_cast<ConstIterator*
>(&iter));
2744 template <std::
size_t TAnySize>
2745 bool operator==(
const StaticQueue<T, TAnySize>& other)
const
2747 return Base::operator==(other);
2751 template <std::
size_t TAnySize>
2752 bool operator!=(
const StaticQueue<T, TAnySize>& other)
const
2754 return Base::operator!=(other);
2759 using ArrayType = std::array<StorageType, TSize>;
2760 alignas(
alignof(T)) ArrayType array_;
2766template <
typename T, std::
size_t TSize>
2767class StaticQueue<T, TSize>::ConstIterator :
public StaticQueue<T, TSize>::Base::ConstIterator
2769 using Base =
typename StaticQueue<T, TSize>::Base::ConstIterator;
2773 using IteratorCategory =
typename Base::IteratorCategory;
2776 using iterator_category = IteratorCategory;
2779 using ValueType =
typename Base::ValueType;
2782 using value_type = ValueType;
2785 using DifferenceType =
typename Base::DifferenceType;
2788 using difference_type = DifferenceType;
2791 using Pointer =
typename Base::Pointer;
2794 using pointer = Pointer;
2797 using ConstPointer =
typename Base::ConstPointer;
2800 using Reference =
typename Base::Reference;
2803 using reference = Reference;
2806 using ConstReference =
typename Base::ConstReference;
2809 using QueueType = StaticQueue<T, TSize>;
2812 using ConstLinearisedIterator =
typename QueueType::ConstLinearisedIterator;
2817 ConstIterator(
const QueueType& queue, ConstLinearisedIterator iterator)
2818 : Base(queue, iterator)
2823 ConstIterator(
const ConstIterator&) =
default;
2828 ConstIterator& operator=(
const ConstIterator& other)
2830 return static_cast<ConstIterator&
>(Base::operator=(other));
2834 ConstIterator& operator++()
2836 return static_cast<ConstIterator&
>(Base::operator++());
2840 ConstIterator operator++(
int dummyParam)
2842 auto tmp = Base::operator++(dummyParam);
2843 return *(
static_cast<ConstIterator*
>(&tmp));
2847 ConstIterator& operator--()
2849 return static_cast<ConstIterator&
>(Base::operator--());
2853 ConstIterator operator--(
int dummyParam)
2855 auto tmp = Base::operator--(dummyParam);
2856 return *(
static_cast<ConstIterator*
>(&tmp));
2861 ConstIterator& operator+=(DifferenceType value)
2863 return static_cast<ConstIterator&
>(Base::operator+=(value));
2868 ConstIterator& operator-=(DifferenceType value)
2870 return static_cast<ConstIterator&
>(Base::operator-=(value));
2877 ConstIterator operator+(DifferenceType value)
const
2879 auto tmp = Base::operator+(value);
2880 return *(
static_cast<ConstIterator*
>(&tmp));
2887 ConstIterator operator-(DifferenceType value)
const
2889 auto tmp = Base::operator-(value);
2890 return *(
static_cast<ConstIterator*
>(&tmp));
2896 DifferenceType operator-(
const ConstIterator& other)
const
2898 return Base::operator-(other);
2903 bool operator==(
const ConstIterator& other)
const
2905 return Base::operator==(other);
2910 bool operator!=(
const ConstIterator& other)
const
2912 return Base::operator!=(other);
2917 bool operator<(
const ConstIterator& other)
const
2919 return Base::operator<(other);
2924 bool operator<=(
const ConstIterator& other)
const
2926 return Base::operator<=(other);
2931 bool operator>(
const ConstIterator& other)
const
2933 return Base::operator>(other);
2938 bool operator>=(
const ConstIterator& other)
const
2940 return Base::operator>=(other);
2944 Reference operator*()
2946 return Base::operator*();
2950 ConstReference operator*()
const
2952 return Base::operator*();
2956 Pointer operator->()
2958 return Base::operator->();
2962 ConstPointer operator->()
const
2964 return Base::operator->();
2971template <
typename T, std::
size_t TSize>
2972class StaticQueue<T, TSize>::Iterator :
public StaticQueue<T, TSize>::Base::Iterator
2974 using Base =
typename StaticQueue<T, TSize>::Base::Iterator;
2978 using IteratorCategory =
typename Base::IteratorCategory;
2981 using iterator_category = IteratorCategory;
2984 using ValueType =
typename Base::ValueType;
2987 using value_type = ValueType;
2990 using DifferenceType =
typename Base::DifferenceType;
2993 using difference_type = DifferenceType;
2996 using Pointer =
typename Base::Pointer;
2999 using pointer = Pointer;
3002 using ConstPointer =
typename Base::ConstPointer;
3005 using Reference =
typename Base::Reference;
3008 using reference = Reference;
3011 using ConstReference =
typename Base::ConstReference;
3014 using QueueType = StaticQueue<T, TSize>;
3017 using LinearisedIterator =
typename QueueType::LinearisedIterator;
3020 using ConstLinearisedIterator =
typename QueueType::ConstLinearisedIterator;
3025 Iterator(QueueType& queue, LinearisedIterator iterator)
3026 : Base(queue, iterator)
3031 Iterator(
const Iterator&) =
default;
3036 Iterator& operator=(
const Iterator& other)
3038 return static_cast<Iterator&
>(Base::operator=(other));
3042 Iterator& operator++()
3044 return static_cast<Iterator&
>(Base::operator++());
3048 Iterator operator++(
int dummyParam)
3050 auto tmp = Base::operator++(dummyParam);
3051 return *(
static_cast<Iterator*
>(&tmp));
3055 Iterator& operator--()
3057 return static_cast<Iterator&
>(Base::operator--());
3061 Iterator operator--(
int dummyParam)
3063 auto tmp = Base::operator--(dummyParam);
3064 return *(
static_cast<Iterator*
>(&tmp));
3069 Iterator& operator+=(DifferenceType value)
3071 return static_cast<Iterator&
>(Base::operator+=(value));
3076 Iterator& operator-=(DifferenceType value)
3078 return static_cast<Iterator&
>(Base::operator-=(value));
3085 Iterator operator+(DifferenceType value)
const
3087 auto tmp = Base::operator+(value);
3088 return *(
static_cast<Iterator*
>(&tmp));
3095 Iterator operator-(DifferenceType value)
const
3097 auto tmp = Base::operator-(value);
3098 return *(
static_cast<Iterator*
>(&tmp));
3104 DifferenceType operator-(
const Iterator& other)
const
3106 return Base::operator-(other);
3111 bool operator==(
const Iterator& other)
const
3113 return Base::operator==(other);
3118 bool operator!=(
const Iterator& other)
const
3120 return Base::operator!=(other);
3125 bool operator<(
const Iterator& other)
const
3127 return Base::operator<(other);
3132 bool operator<=(
const Iterator& other)
const
3134 return Base::operator<=(other);
3139 bool operator>(
const Iterator& other)
const
3141 return Base::operator>(other);
3146 bool operator>=(
const Iterator& other)
const
3148 return Base::operator>=(other);
3152 Reference operator*()
3154 return Base::operator*();
3158 ConstReference operator*()
const
3160 return Base::operator*();
3164 Pointer operator->()
3166 return Base::operator->();
3170 ConstPointer operator->()
const
3172 return Base::operator->();
3175 operator ConstIterator()
const
3177 auto iter =
static_cast<ConstLinearisedIterator
>(Base::getIterator());
3178 const auto& queue =
static_cast<QueueType&
>(Base::getQueue());
3179 return ConstIterator(queue, iter);
3189COMMS_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:28
Replacement to some types from standard type_traits.