4#include "Stroika/Foundation/Containers/DataStructures/Array.h"
6#include "Stroika/Foundation/Containers/Private/IteratorImplHelper.h"
18 class Collection_Array<T>::Rep_ :
public Collection_Array<T>::IImplRep_,
public Memory::UseBlockAllocationIfAppropriate<Rep_> {
20 using inherited =
typename Collection<T>::_IRep;
24 Rep_ (
const Rep_&
from) =
default;
27 nonvirtual Rep_& operator= (
const Rep_&) =
delete;
34 return Memory::MakeSharedPtr<Rep_> (*
this);
47 virtual size_t size ()
const override
50 return fData_.size ();
52 virtual bool empty ()
const override
55 return fData_.empty ();
66 if (
auto i = fData_.Find (
that)) {
77 return Memory::MakeSharedPtr<Rep_> ();
83 auto result = Memory::MakeSharedPtr<Rep_> (*
this);
84 auto&
mir = Debug::UncheckedDynamicCast<const IteratorRep_&> (i->ConstGetRep ());
85 result->fData_.MoveIteratorHereAfterClone (&
mir.fIterator, &fData_);
89#if qCompilerAndStdLib_MemoryInsertAt_Buggy
92 [[gnu::noinline, gnu::optimize (
"O0")]]
100 fData_.Insert (fData_.size (),
items);
101 fChangeCounts_.PerformedChange ();
110 if (
nextI !=
nullptr) {
111 savedUnderlyingIndex = Debug::UncheckedDynamicCast<const IteratorRep_&> (i.ConstGetRep ()).fIterator.GetUnderlyingIteratorRep ();
113 fData_.SetAt (Debug::UncheckedDynamicCast<const IteratorRep_&> (i.ConstGetRep ()).fIterator,
newValue);
114 fChangeCounts_.PerformedChange ();
115 if (
nextI !=
nullptr) {
122 auto&
mir = Debug::UncheckedDynamicCast<const IteratorRep_&> (i.ConstGetRep ());
123 if (
nextI ==
nullptr) {
124 fData_.Remove (
mir.fIterator);
125 fChangeCounts_.PerformedChange ();
128 auto retI = fData_.erase (
mir.fIterator);
129 fChangeCounts_.PerformedChange ();
135 using DataStructureImplType_ = DataStructures::Array<value_type>;
136 using IteratorRep_ = Private::IteratorImplHelper_<value_type, DataStructureImplType_>;
139 DataStructureImplType_ fData_;
148 template <
typename T>
150 :
inherited{Memory::MakeSharedPtr<Rep_> ()}
152 AssertRepValidType_ ();
154 template <
typename T>
155 template <IInputIterator<T> ITERATOR_OF_ADDABLE>
165 AssertRepValidType_ ();
167 template <
typename T>
173 AssertRepValidType_ ();
175#if !qCompilerAndStdLib_RequiresNotMatchInlineOutOfLineForTemplateClassBeingDefined_Buggy
176 template <
typename T>
177 template <IIterableOfTo<T> ITERABLE_OF_ADDABLE>
178 requires (not derived_from<remove_cvref_t<ITERABLE_OF_ADDABLE>, Collection_Array<T>>)
182 reserve (src.size ());
183 this->AddAll (forward<ITERABLE_OF_ADDABLE> (src));
184 AssertRepValidType_ ();
187 template <
typename T>
188 inline void Collection_Array<T>::AssertRepValidType_ ()
const
191 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...
nonvirtual void AddAll(ITERATOR_OF_ADDABLE &&start, ITERATOR_OF_ADDABLE2 &&end)
nonvirtual void Update(const Iterator< value_type > &i, ArgByValueType< value_type > newValue, Iterator< value_type > *nextI=nullptr)
nonvirtual void Remove(ArgByValueType< value_type > item, EQUALS_COMPARER &&equalsComparer={})
Remove () the argument value (which must exist)
nonvirtual void Add(ArgByValueType< value_type > item)
Collection_Array<T> is an Array-based concrete implementation of the Collection<T> container pattern.
nonvirtual void reserve(size_t slotsAlloced)
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 CONTAINER_OF_T As(CONTAINER_OF_T_CONSTRUCTOR_ARGS... args) const
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,...