4#include "Stroika/Foundation/Containers/DataStructures/LinkedList.h"
5#include "Stroika/Foundation/Containers/Private/IteratorImplHelper.h"
17 template <qCompilerAndStdLib_Constra
intDiffersInTemplateRedeclaration_BWA (Common::IInOrderComparer<T>) INORDER_COMPARER>
18 class SortedCollection_LinkedList<T>::Rep_ :
public IImplRepBase_,
public Memory::UseBlockAllocationIfAppropriate<Rep_<INORDER_COMPARER>> {
20 using inherited = IImplRepBase_;
30 Rep_ (
const Rep_&
from) =
default;
33 nonvirtual Rep_& operator= (
const Rep_&) =
delete;
43 return Memory::MakeSharedPtr<Rep_> (*
this);
50 virtual size_t size ()
const override
53 return fData_.size ();
55 virtual bool empty ()
const override
58 return fData_.empty ();
79 return Memory::MakeSharedPtr<Rep_> (fInorderComparer_);
85 auto result = Memory::MakeSharedPtr<Rep_> (*
this);
86 auto&
mir = Debug::UncheckedDynamicCast<const IteratorRep_&> (i->ConstGetRep ());
87 result->fData_.MoveIteratorHereAfterClone (&
mir.fIterator, &fData_);
91#if qCompilerAndStdLib_MemoryInsertAt_Buggy
94 [[gnu::noinline, gnu::optimize (
"O0")]]
102 for (
const value_type& i :
items) {
105 fChangeCounts_.PerformedChange ();
109 fChangeCounts_.PerformedChange ();
117 if (
nextI !=
nullptr) {
118 savedUnderlyingIndex = Debug::UncheckedDynamicCast<const IteratorRep_&> (i.ConstGetRep ()).fIterator.GetUnderlyingIteratorRep ();
120 auto&
mir = Debug::UncheckedDynamicCast<const IteratorRep_&> (i.ConstGetRep ());
123 if (Common::EqualsComparerAdapter<value_type, INORDER_COMPARER>{fInorderComparer_}(*
mir.fIterator,
newValue)) {
127 fData_.Remove (
mir.fIterator);
130 fChangeCounts_.PerformedChange ();
131 if (
nextI !=
nullptr) {
138 auto&
mir = Debug::UncheckedDynamicCast<const IteratorRep_&> (i.ConstGetRep ());
139 if (
nextI ==
nullptr) {
140 fData_.Remove (
mir.fIterator);
141 fChangeCounts_.PerformedChange ();
144 auto ret = fData_.erase (
mir.fIterator);
145 fChangeCounts_.PerformedChange ();
155 return Common::ThreeWayComparerAdapter<T, INORDER_COMPARER>{fInorderComparer_};
160 return fData_.Find (
item, Common::EqualsComparerAdapter<value_type, INORDER_COMPARER>{fInorderComparer_}) !=
nullptr;
165 fData_.Remove (
item, Common::EqualsComparerAdapter<value_type, INORDER_COMPARER>{fInorderComparer_});
166 fChangeCounts_.PerformedChange ();
170 using DataStructureImplType_ = DataStructures::LinkedList<value_type>;
171 using IteratorRep_ = Private::IteratorImplHelper_<value_type, DataStructureImplType_>;
176 using ForwardIterator =
typename DataStructureImplType_::ForwardIterator;
177 ForwardIterator
it{&fData_};
188 DataStructureImplType_ fData_;
197 template <
typename T>
201 AssertRepValidType_ ();
203 template <
typename T>
204 template <Common::IInOrderComparer<T> INORDER_COMPARER>
205 inline SortedCollection_LinkedList<T>::SortedCollection_LinkedList (INORDER_COMPARER&& inorderComparer)
206 : inherited{Memory::MakeSharedPtr<Rep_<remove_cvref_t<INORDER_COMPARER>>> (inorderComparer)}
208 AssertRepValidType_ ();
210 template <
typename T>
212 : SortedCollection_LinkedList{}
215 AssertRepValidType_ ();
217 template <
typename T>
218 template <Common::IInOrderComparer<T> INORDER_COMPARER>
220 : SortedCollection_LinkedList{forward<INORDER_COMPARER> (inOrderComparer)}
223 AssertRepValidType_ ();
225#if !qCompilerAndStdLib_RequiresNotMatchInlineOutOfLineForTemplateClassBeingDefined_Buggy
226 template <
typename T>
227 template <IIterableOfTo<T> ITERABLE_OF_ADDABLE>
228 requires (not derived_from<remove_cvref_t<ITERABLE_OF_ADDABLE>, SortedCollection_LinkedList<T>>)
230 : SortedCollection_LinkedList{}
232 this->AddAll (forward<ITERABLE_OF_ADDABLE> (src));
233 AssertRepValidType_ ();
236 template <
typename T>
237 template <Common::IInOrderComparer<T> INORDER_COMPARER, IIterableOfTo<T> ITERABLE_OF_ADDABLE>
239 : SortedCollection_LinkedList{forward<INORDER_COMPARER> (inOrderComparer)}
242 AssertRepValidType_ ();
244 template <
typename T>
245 template <IInputIterator<T> ITERATOR_OF_ADDABLE>
247 : SortedCollection_LinkedList{}
250 AssertRepValidType_ ();
252 template <
typename T>
253 template <Common::IInOrderComparer<T> INORDER_COMPARER, IInputIterator<T> ITERATOR_OF_ADDABLE>
255 ITERATOR_OF_ADDABLE&& end)
256 : SortedCollection_LinkedList{forward<INORDER_COMPARER> (inOrderComparer)}
259 AssertRepValidType_ ();
261 template <
typename T>
262 inline void SortedCollection_LinkedList<T>::AssertRepValidType_ ()
const
265 typename inherited::template _SafeReadRepAccessor<IImplRepBase_> 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
qStroika_ATTRIBUTE_NO_UNIQUE_ADDRESS - used for the attribute [[no_unique_address]]
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 Add(ArgByValueType< value_type > item)
SortedCollection_LinkedList<T> is an LinkedList-based concrete implementation of the SortedCollection...
SortedCollection_LinkedList()
nonvirtual ElementThreeWayComparerType GetElementThreeWayComparer() const
nonvirtual bool Contains(ArgByValueType< T > item) const
Compares items with the already associated GetInOrderComparer(), and returns true if the item is foun...
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,...