4#include "Stroika/Foundation/Containers/Common.h"
5#include "Stroika/Foundation/Containers/DataStructures/Array.h"
7#include "Stroika/Foundation/Containers/Private/IteratorImplHelper.h"
8#include "Stroika/Foundation/Containers/Support/ReserveTweaks.h"
17 class Sequence_Array<T>::Rep_ :
public Sequence<T>::_IRep,
public Memory::UseBlockAllocationIfAppropriate<Rep_> {
19 using inherited =
typename Sequence<T>::_IRep;
22 static constexpr size_t _kSentinelLastItemIndex = inherited::_kSentinelLastItemIndex;
26 Rep_ (
const Rep_&
from) =
default;
29 nonvirtual Rep_& operator= (
const Rep_&) =
delete;
36 return Memory::MakeSharedPtr<Rep_> (*
this);
43 virtual size_t size ()
const override
46 return fData_.size ();
48 virtual bool empty ()
const override
51 return fData_.empty ();
62 if (
auto i = fData_.Find (
that)) {
78 return Memory::MakeSharedPtr<Rep_> ();
84 auto result = Memory::MakeSharedPtr<Rep_> (*
this);
85 auto&
mir = Debug::UncheckedDynamicCast<const IteratorRep_&> (i->ConstGetRep ());
86 result->fData_.MoveIteratorHereAfterClone (&
mir.fIterator, &fData_);
89 virtual value_type
GetAt (
size_t i)
const override
91 Require (fData_.size () != 0);
92 Require (i == _kSentinelLastItemIndex
or i < fData_.size ());
94 if (i == _kSentinelLastItemIndex) {
95 i = fData_.size () - 1;
97 return fData_.GetAt (i);
111 Require (i < fData_.size ());
113 fData_.SetAt (i,
item);
114 fChangeCounts_.PerformedChange ();
119 const IteratorRep_&
iteratorRep = Debug::UncheckedDynamicCast<const IteratorRep_&> (i.ConstGetRep ());
125 const IteratorRep_&
iteratorRep = Debug::UncheckedDynamicCast<const IteratorRep_&> (i.ConstGetRep ());
126 if (
nextI ==
nullptr) {
128 fChangeCounts_.PerformedChange ();
132 fChangeCounts_.PerformedChange ();
139 const IteratorRep_&
iteratorRep = Debug::UncheckedDynamicCast<const IteratorRep_&> (i.ConstGetRep ());
142 if (
nextI !=
nullptr) {
146 fChangeCounts_.PerformedChange ();
147 if (
nextI !=
nullptr) {
153 Require (at == _kSentinelLastItemIndex
or at <= fData_.size ());
155 if (at == _kSentinelLastItemIndex) {
159 fChangeCounts_.PerformedChange ();
168 fChangeCounts_.PerformedChange ();
173 using DataStructureImplType_ = DataStructures::Array<value_type>;
174 using IteratorRep_ = Private::IteratorImplHelper_<value_type, DataStructureImplType_>;
175 using RandomAccessIteratorRep_ = Private::RandomAccessIteratorImplHelper_<value_type, DataStructureImplType_>;
178 DataStructureImplType_ fData_;
190 template <
typename T>
192 :
inherited{Memory::MakeSharedPtr<Rep_> ()}
194 AssertRepValidType_ ();
196 template <
typename T>
202 AssertRepValidType_ ();
204#if !qCompilerAndStdLib_RequiresNotMatchInlineOutOfLineForTemplateClassBeingDefined_Buggy
205 template <
typename T>
206 template <IIterableOfTo<T> ITERABLE_OF_ADDABLE>
207 requires (not derived_from<remove_cvref_t<ITERABLE_OF_ADDABLE>, Sequence_Array<T>>)
212 this->reserve (src.size ());
214 this->AppendAll (forward<ITERABLE_OF_ADDABLE> (src));
215 AssertRepValidType_ ();
218 template <
typename T>
219 template <IInputIterator<T> ITERATOR_OF_ADDABLE>
229 AssertRepValidType_ ();
231 template <
typename T>
232 inline void Sequence_Array<T>::AssertRepValidType_ ()
const
235 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_Array<T> is an Array-based concrete implementation of the Sequence<T> container pattern.
nonvirtual void reserve(size_t slotsAlloced)
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'.
Concept checks if the given type T has a const size() method which can be called to return a size_t.
SequencePolicy
equivalent which of 4 types being used std::execution::sequenced_policy, parallel_policy,...