4#include "Stroika/Foundation/Containers/DataStructures/LinkedList.h"
5#include "Stroika/Foundation/Containers/Private/IteratorImplHelper.h"
12 class Sequence_LinkedList<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);
93 return this->_MakeBidirectionalIterator_ViaGetAt ();
98 return this->_MakeRandomAccessIterator_ViaGetAt ();
102 Require (i <
size ());
104 fData_.SetAt (
item, i);
105 fChangeCounts_.PerformedChange ();
109 auto&
mir = Debug::UncheckedDynamicCast<const IteratorRep_&> (i.ConstGetRep ());
111 return mir.fIterator.CurrentIndex (&fData_);
116 auto&
mir = Debug::UncheckedDynamicCast<const IteratorRep_&> (i.ConstGetRep ());
117 if (
nextI ==
nullptr) {
118 fData_.Remove (
mir.fIterator);
119 fChangeCounts_.PerformedChange ();
122 auto ret = fData_.erase (
mir.fIterator);
123 fChangeCounts_.PerformedChange ();
131 if (
nextI !=
nullptr) {
132 savedUnderlyingIndex = Debug::UncheckedDynamicCast<const IteratorRep_&> (i.ConstGetRep ()).fIterator.GetUnderlyingIteratorRep ();
134 fData_.SetAt (Debug::UncheckedDynamicCast<const IteratorRep_&> (i.ConstGetRep ()).fIterator,
newValue);
135 fChangeCounts_.PerformedChange ();
136 if (
nextI !=
nullptr) {
142 Require (at == _kSentinelLastItemIndex
or at <=
size ());
144 if (at == _kSentinelLastItemIndex) {
152 else if (at == fData_.size ()) {
159 typename DataStructureImplType_::ForwardIterator
it{&fData_};
160 for (;
not it.AtEnd (); ++
it) {
164 fData_.AddBefore (
it, *
p);
170 Assert (
not it.AtEnd ());
172 fChangeCounts_.PerformedChange ();
182 for (
typename DataStructureImplType_::ForwardIterator
it{&fData_};
not it.AtEnd (); ++
it) {
185 it = fData_.erase (
it);
190 fChangeCounts_.PerformedChange ();
195 using DataStructureImplType_ = DataStructures::LinkedList<value_type>;
196 using IteratorRep_ = Private::IteratorImplHelper_<value_type, DataStructureImplType_>;
199 DataStructureImplType_ fData_;
208 template <
typename T>
210 :
inherited{Memory::MakeSharedPtr<Rep_> ()}
212 AssertRepValidType_ ();
214 template <
typename T>
219 AssertRepValidType_ ();
221#if !qCompilerAndStdLib_RequiresNotMatchInlineOutOfLineForTemplateClassBeingDefined_Buggy
222 template <
typename T>
223 template <IIterableOfTo<T> ITERABLE_OF_ADDABLE>
224 requires (not derived_from<remove_cvref_t<ITERABLE_OF_ADDABLE>, Sequence_LinkedList<T>>)
226 : Sequence_LinkedList{}
228 this->AppendAll (forward<ITERABLE_OF_ADDABLE> (src));
229 AssertRepValidType_ ();
232 template <
typename T>
233 template <IInputIterator<T> ITERATOR_OF_ADDABLE>
235 : Sequence_LinkedList{}
238 AssertRepValidType_ ();
240 template <
typename T>
241 inline void Sequence_LinkedList<T>::AssertRepValidType_ ()
const
244 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_LinkedList<T> is a LinkedList-based concrete implementation of the Sequence<T> container pat...
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,...