4#include "Stroika/Foundation/Containers/DataStructures/DoublyLinkedList.h"
5#include "Stroika/Foundation/Containers/Private/IteratorImplHelper.h"
12 class Sequence_DoublyLinkedList<T>::Rep_ :
public Sequence<T>::_IRep,
public Memory::UseBlockAllocationIfAppropriate<Rep_> {
14 using inherited =
typename Sequence<T>::_IRep;
17 static constexpr size_t _kSentinelLastItemIndex = inherited::_kSentinelLastItemIndex;
21 Rep_ (
const Rep_&
from) =
default;
24 nonvirtual Rep_& operator= (
const Rep_&) =
delete;
31 return Memory::MakeSharedPtr<Rep_> (*
this);
38 virtual size_t size ()
const override
41 return fData_.size ();
43 virtual bool empty ()
const override
46 return fData_.empty ();
68 return Memory::MakeSharedPtr<Rep_> ();
74 auto result = Memory::MakeSharedPtr<Rep_> (*
this);
75 auto&
mir = Debug::UncheckedDynamicCast<const IteratorRep_&> (i->ConstGetRep ());
76 result->fData_.MoveIteratorHereAfterClone (&
mir.fIterator, &fData_);
80 virtual value_type
GetAt (
size_t i)
const override
83 Require (i == _kSentinelLastItemIndex
or i <
size ());
85 if (i == _kSentinelLastItemIndex) {
88 return fData_.GetAt (i);
99 return this->_MakeRandomAccessIterator_ViaGetAt ();
103 Require (i <
size ());
105 fData_.SetAt (i,
item);
106 fChangeCounts_.PerformedChange ();
110 auto&
mir = Debug::UncheckedDynamicCast<const IteratorRep_&> (i.ConstGetRep ());
112 return mir.fIterator.CurrentIndex (&fData_);
117 auto&
mir = Debug::UncheckedDynamicCast<const IteratorRep_&> (i.ConstGetRep ());
118 if (
nextI ==
nullptr) {
119 fData_.Remove (
mir.fIterator);
120 fChangeCounts_.PerformedChange ();
123 auto ret = fData_.erase (
mir.fIterator);
124 fChangeCounts_.PerformedChange ();
132 const IteratorRep_&
iteratorRep = Debug::UncheckedDynamicCast<const IteratorRep_&> (i.ConstGetRep ());
133 if (
nextI !=
nullptr) {
137 fChangeCounts_.PerformedChange ();
138 if (
nextI !=
nullptr) {
144 Require (at == _kSentinelLastItemIndex
or at <=
size ());
146 if (at == _kSentinelLastItemIndex) {
154 else if (at == fData_.size ()) {
169 for (
typename DataStructureImplType_::ForwardIterator
it{&fData_};
not it.AtEnd (); ++
it) {
175 fData_.AddBefore (
it, *
p);
183 fChangeCounts_.PerformedChange ();
193 for (
typename DataStructureImplType_::ForwardIterator
it{&fData_};
not it.AtEnd (); ++
it) {
196 it = fData_.erase (
it);
201 fChangeCounts_.PerformedChange ();
206 using DataStructureImplType_ = DataStructures::DoublyLinkedList<value_type>;
207 using IteratorRep_ = Private::IteratorImplHelper_<value_type, DataStructureImplType_>;
212 struct BidirectionalIteratorTraits_ : Private::IteratorImplHelper_DefaultTraits<value_type, DataStructureImplType_> {
213 using DataStructureIteratorT =
typename DataStructureImplType_::BidirectionalIterator;
215 using BidirectionalIteratorRep_ = Private::BidirectionalIteratorImplHelper_<value_type, DataStructureImplType_, BidirectionalIteratorTraits_>;
218 DataStructureImplType_ fData_;
227 template <
typename T>
229 :
inherited{Memory::MakeSharedPtr<Rep_> ()}
231 AssertRepValidType_ ();
233 template <
typename T>
238 AssertRepValidType_ ();
240#if !qCompilerAndStdLib_RequiresNotMatchInlineOutOfLineForTemplateClassBeingDefined_Buggy
241 template <
typename T>
242 template <IIterableOfTo<T> ITERABLE_OF_ADDABLE>
243 requires (not derived_from<remove_cvref_t<ITERABLE_OF_ADDABLE>, Sequence_DoublyLinkedList<T>>)
245 : Sequence_DoublyLinkedList{}
247 this->AppendAll (forward<ITERABLE_OF_ADDABLE> (src));
248 AssertRepValidType_ ();
251 template <
typename T>
252 template <IInputIterator<T> ITERATOR_OF_ADDABLE>
254 : Sequence_DoublyLinkedList{}
257 AssertRepValidType_ ();
259 template <
typename T>
260 inline void Sequence_DoublyLinkedList<T>::AssertRepValidType_ ()
const
263 typename inherited::template _SafeReadRepAccessor<Rep_> tmp{
this};
#define qStroika_Foundation_Debug_AssertionsChecked
The qStroika_Foundation_Debug_AssertionsChecked flag determines if assertions are checked and validat...
#define RequireNotNull(p)
#define qStroika_ATTRIBUTE_NO_UNIQUE_ADDRESS_VCFORCE
[[msvc::no_unique_address]] isn't always broken in MSVC. Annotate with this on things where its not b...
Sequence_DoublyLinkedList<T> is an Array-based concrete implementation of the Sequence<T> container p...
Sequence_DoublyLinkedList()
A generalization of a vector: a container whose elements are keyed by the natural numbers.
nonvirtual void As(CONTAINER_OF_ADDABLE *into) const
write this Sequence into an existing container
nonvirtual void Remove(size_t i)
nonvirtual void Insert(size_t i, ArgByValueType< value_type > item)
nonvirtual optional< size_t > IndexOf(ArgByValueType< value_type > i, EQUALS_COMPARER &&equalsComparer={}) const
nonvirtual void SetAt(size_t i, ArgByValueType< value_type > item)
nonvirtual value_type GetAt(size_t i) const
nonvirtual void Update(const Iterator< value_type > &i, ArgByValueType< value_type > newValue, Iterator< value_type > *nextI=nullptr)
nonvirtual void AppendAll(ITERABLE_OF_ADDABLE &&s)
unique_lock< AssertExternallySynchronizedChecker > WriteContext
Instantiate AssertExternallySynchronizedChecker::WriteContext to designate an area of code where prot...
shared_lock< const AssertExternallySynchronizedChecker > ReadContext
Instantiate AssertExternallySynchronizedChecker::ReadContext to designate an area of code where prote...
nonvirtual Iterator< T > Find(THAT_FUNCTION &&that) const
Run the argument bool-returning function (or lambda) on the elements of the container,...
nonvirtual size_t size() const
Returns the number of items contained.
nonvirtual void Apply(const function< void(ArgByValueType< T > item)> &doToElement) const
Run the argument function (or lambda) on each element of the container.
nonvirtual bool empty() const
Returns true iff size() == 0.
static constexpr default_sentinel_t end() noexcept
Support for ranged for, and STL syntax in general.
nonvirtual Iterator< T > MakeIterator() const
Create an iterator object which can be used to traverse the 'Iterable'.
SequencePolicy
equivalent which of 4 types being used std::execution::sequenced_policy, parallel_policy,...