7#include "Stroika/Foundation/Containers/Private/IteratorImplHelper.h"
8#include "Stroika/Foundation/Containers/Support/ReserveTweaks.h"
15 class Sequence_stdvector<T>::Rep_ :
public Sequence<T>::_IRep,
public Memory::UseBlockAllocationIfAppropriate<Rep_> {
17 using inherited =
typename Sequence<T>::_IRep;
20 static constexpr size_t _kSentinelLastItemIndex = inherited::_kSentinelLastItemIndex;
24 Rep_ (
const Rep_&
src) =
default;
31 nonvirtual Rep_& operator= (
const Rep_&) =
delete;
38 return Memory::MakeSharedPtr<Rep_> (*
this);
45 virtual size_t size ()
const override
48 return fData_.size ();
50 virtual bool empty ()
const override
53 return fData_.empty ();
64 auto iLink =
const_cast<DataStructureImplType_&
> (fData_).
Find (
that);
65 if (
iLink == fData_.end ()) {
82 return Memory::MakeSharedPtr<Rep_> ();
88 auto result = Memory::MakeSharedPtr<Rep_> (*
this);
89 auto&
mir = Debug::UncheckedDynamicCast<const IteratorRep_&> (i->ConstGetRep ());
90 result->fData_.MoveIteratorHereAfterClone (
91 &
mir.fIterator, &fData_,
96 virtual value_type
GetAt (
size_t i)
const override
99 Require (i == _kSentinelLastItemIndex
or i <
size ());
101 if (i == _kSentinelLastItemIndex) {
102 i = fData_.size () - 1;
118 Require (i <
size ());
121 fChangeCounts_.PerformedChange ();
126 return Debug::UncheckedDynamicCast<const IteratorRep_&> (i.ConstGetRep ()).fIterator.CurrentIndex ();
130 Require (
not i.AtEnd ());
132 const IteratorRep_&
iRep = Debug::UncheckedDynamicCast<const IteratorRep_&> (i.ConstGetRep ());
133 iRep.fIterator.AssertDataMatches (&fData_);
134 auto newI = fData_.erase (
iRep.fIterator.GetUnderlyingIteratorRep ());
135 fChangeCounts_.PerformedChange ();
136 if (
nextI !=
nullptr) {
143 const IteratorRep_&
iRep = Debug::UncheckedDynamicCast<const IteratorRep_&> (i.ConstGetRep ());
145 if (
nextI !=
nullptr) {
149 *fData_.remove_constness (
iRep.fIterator.GetUnderlyingIteratorRep ()) =
newValue;
150 fChangeCounts_.PerformedChange ();
151 if (
nextI !=
nullptr) {
158 Require (at == _kSentinelLastItemIndex
or at <=
size ());
160 if (at == _kSentinelLastItemIndex) {
163 Support::ReserveTweaks::Reserve4AddN (fData_,
copyFrom.size ());
165 fChangeCounts_.PerformedChange ();
172 fData_.erase (fData_.begin () +
from, fData_.begin () +
to);
173 fChangeCounts_.PerformedChange ();
178 using DataStructureImplType_ = DataStructures::STLContainerWrapper<vector<value_type>>;
179 using IteratorRep_ = Private::IteratorImplHelper_<value_type, DataStructureImplType_>;
184 struct RandomAccessIteratorTraits_ : Private::IteratorImplHelper_DefaultTraits<value_type, DataStructureImplType_> {
185 using DataStructureIteratorT =
typename DataStructureImplType_::RandomAccessIterator;
187 using RandomAccessIteratorRep_ = Private::RandomAccessIteratorImplHelper_<value_type, DataStructureImplType_, RandomAccessIteratorTraits_>;
190 DataStructureImplType_ fData_;
202 template <
typename T>
204 :
inherited{Memory::MakeSharedPtr<Rep_> ()}
206 AssertRepValidType_ ();
208 template <
typename T>
214 AssertRepValidType_ ();
216#if !qCompilerAndStdLib_RequiresNotMatchInlineOutOfLineForTemplateClassBeingDefined_Buggy
217 template <
typename T>
218 template <IIterableOfTo<T> ITERABLE_OF_ADDABLE>
219 requires (not derived_from<remove_cvref_t<ITERABLE_OF_ADDABLE>, Sequence_stdvector<T>>)
221 : Sequence_stdvector{}
224 this->reserve (src.size ());
226 this->AppendAll (forward<ITERABLE_OF_ADDABLE> (src));
227 AssertRepValidType_ ();
230 template <
typename T>
232 : inherited{Memory::MakeSharedPtr<Rep_> (move (src))}
234 AssertRepValidType_ ();
236 template <
typename T>
237 template <IInputIterator<T> ITERATOR_OF_ADDABLE>
239 : Sequence_stdvector{}
247 AssertRepValidType_ ();
249 template <
typename T>
250 inline void Sequence_stdvector<T>::AssertRepValidType_ ()
const
253 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_stdvector<T> is an std::vector-based concrete implementation of the Sequence<T> container pa...
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,...