16 class Collection_stdforward_list<T>::Rep_ :
public Collection<T>::_IRep,
public Memory::UseBlockAllocationIfAppropriate<Rep_> {
18 using inherited =
typename Collection<T>::_IRep;
22 Rep_ (
const Rep_& from) =
default;
25 nonvirtual Rep_& operator= (
const Rep_&) =
delete;
29 virtual shared_ptr<typename Iterable<T>::_IRep> Clone ()
const override
32 return Memory::MakeSharedPtr<Rep_> (*
this);
34 virtual Iterator<value_type>
MakeIterator ()
const override
37 return Iterator<value_type>{make_unique<IteratorRep_> (&fData_, &fChangeCounts_)};
39 virtual size_t size ()
const override
43 for (
auto i = fData_.begin (); i != fData_.end (); ++i, ++cnt)
47 virtual bool empty ()
const override
50 return fData_.empty ();
52 virtual void Apply (
const function<
void (ArgByValueType<value_type> item)>& doToElement, [[maybe_unused]]
Execution::SequencePolicy seq)
const override
55 fData_.Apply (doToElement);
57 virtual Iterator<value_type>
Find (
const function<
bool (ArgByValueType<value_type> item)>& that,
66 virtual shared_ptr<typename Collection<T>::_IRep> CloneEmpty ()
const override
68 return Memory::MakeSharedPtr<Rep_> ();
70 virtual shared_ptr<typename Collection<T>::_IRep> CloneAndPatchIterator (Iterator<value_type>* i)
const override
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 void Add (ArgByValueType<value_type> item, Iterator<value_type>* oAddedI)
override
83 fData_.push_front (item);
84 fChangeCounts_.PerformedChange ();
85 if (oAddedI !=
nullptr) [[unlikely]] {
86 *oAddedI = Iterator<value_type>{make_unique<IteratorRep_> (&fData_, &fChangeCounts_)};
89 virtual void Update (
const Iterator<value_type>& i, ArgByValueType<value_type> newValue, Iterator<value_type>* nextI)
override
92 Require (not i.Done ());
93 optional<typename DataStructureImplType_::UnderlyingIteratorRep> savedUnderlyingIndex;
94 if (nextI !=
nullptr) {
95 savedUnderlyingIndex = Debug::UncheckedDynamicCast<const IteratorRep_&> (i.ConstGetRep ()).fIterator.GetUnderlyingIteratorRep ();
97 *fData_.remove_constness (Debug::UncheckedDynamicCast<const IteratorRep_&> (i.ConstGetRep ()).fIterator.GetUnderlyingIteratorRep ()) = newValue;
98 fChangeCounts_.PerformedChange ();
99 if (nextI !=
nullptr) {
100 *nextI = Iterator<value_type>{make_unique<IteratorRep_> (&fData_, &fChangeCounts_, *savedUnderlyingIndex)};
103 virtual void Remove (
const Iterator<value_type>& i, Iterator<value_type>* nextI)
override
108 typename STDFORWARDLIST::const_iterator victim =
109 Debug::UncheckedDynamicCast<const IteratorRep_&> (i.ConstGetRep ()).fIterator.GetUnderlyingIteratorRep ();
110 typename STDFORWARDLIST::const_iterator prevI;
111 for (prevI = fData_.before_begin (); std::next (prevI) != victim; ++prevI)
113 Assert (prevI != fData_.end ());
114 auto nextStdI = fData_.erase_after (prevI);
115 fChangeCounts_.PerformedChange ();
116 if (nextI !=
nullptr) {
117 *nextI = Iterator<value_type>{make_unique<IteratorRep_> (&fData_, &fChangeCounts_, nextStdI)};
122 using DataStructureImplType_ = DataStructures::STLContainerWrapper<STDFORWARDLIST>;
123 using IteratorRep_ = Private::IteratorImplHelper_<value_type, DataStructureImplType_>;
126 DataStructureImplType_ fData_;
127 [[no_unique_address]] Private::ContainerDebugChangeCounts_ fChangeCounts_;
135 template <
typename T>
137 :
inherited{Memory::MakeSharedPtr<Rep_> ()}
139 AssertRepValidType_ ();
141 template <
typename T>
142 template <IInputIterator<T> ITERATOR_OF_ADDABLE>
146 this->
AddAll (forward<ITERATOR_OF_ADDABLE> (start), forward<ITERATOR_OF_ADDABLE> (
end));
147 AssertRepValidType_ ();
149 template <
typename T>
151 : Collection_stdforward_list{}
154 AssertRepValidType_ ();
156#if !qCompilerAndStdLib_RequiresNotMatchInlineOutOfLineForTemplateClassBeingDefined_Buggy
157 template <
typename T>
158 template <IIterableOfTo<T> ITERABLE_OF_ADDABLE>
159 requires (not derived_from<remove_cvref_t<ITERABLE_OF_ADDABLE>, Collection_stdforward_list<T>>)
161 : Collection_stdforward_list{}
163 this->AddAll (forward<ITERABLE_OF_ADDABLE> (src));
164 AssertRepValidType_ ();
167 template <
typename T>
168 inline void Collection_stdforward_list<T>::AssertRepValidType_ ()
const
171 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)
A Collection<T> is a container to manage an un-ordered collection of items, without equality defined ...
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_stdforward_list<T> is an std::forward_list (singly linked list)-based concrete implementat...
Collection_stdforward_list()
shared_lock< const AssertExternallySynchronizedMutex > ReadContext
Instantiate AssertExternallySynchronizedMutex::ReadContext to designate an area of code where protect...
unique_lock< AssertExternallySynchronizedMutex > WriteContext
Instantiate AssertExternallySynchronizedMutex::WriteContext to designate an area of code where protec...
nonvirtual void Apply(const function< void(ArgByValueType< T > item)> &doToElement, Execution::SequencePolicy seq=Execution::SequencePolicy::eDEFAULT) const
Run the argument function (or lambda) on each element of the container.
nonvirtual Iterator< T > Find(THAT_FUNCTION &&that, Execution::SequencePolicy seq=Execution::SequencePolicy::eDEFAULT) const
Run the argument bool-returning function (or lambda) on each element of the container,...
nonvirtual size_t size() const
Returns the number of items contained.
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,...