5#include "Stroika/Foundation/Containers/Private/IteratorImplHelper.h"
17 template <qCompilerAndStdLib_Constra
intDiffersInTemplateRedeclaration_BWA (IThreeWayComparer<T>) COMPARER>
18 class SortedSet_SkipList<T>::Rep_ :
public Private::SkipListBasedContainerRepImpl<Rep_<COMPARER>, IImplRepBase_>,
19 public Memory::UseBlockAllocationIfAppropriate<Rep_<COMPARER>> {
21 using inherited = Private::SkipListBasedContainerRepImpl<Rep_<COMPARER>, IImplRepBase_>;
31 Rep_ (
const Rep_&
from) =
default;
34 nonvirtual Rep_& operator= (
const Rep_&) =
delete;
41 return Memory::MakeSharedPtr<Rep_> (*
this);
48 virtual size_t size ()
const override
52 return fData_.size ();
54 virtual bool empty ()
const override
58 return fData_.empty ();
63 fData_.Apply ([&] (
const auto& k) {
doToElement (k.fKey); });
74 auto found = fData_.Find (v);
77 (
found == Debug::UncheckedDynamicCast<const IteratorRep_&> (this->inherited::Find_equal_to (v,
seq).ConstGetRep ())
78 .fIterator.GetUnderlyingIteratorRep ()));
88 return Common::EqualsComparerAdapter<T, COMPARER>{fData_.key_comp ()};
93 return Memory::MakeSharedPtr<Rep_> (fData_.key_comp ());
99 auto result = Memory::MakeSharedPtr<Rep_> (*
this);
100 auto&
mir = Debug::UncheckedDynamicCast<const IteratorRep_&> (i->ConstGetRep ());
101 result->fData_.MoveIteratorHereAfterClone (&
mir.fIterator, &fData_);
105 virtual bool Equals (
const typename Iterable<value_type>::_IRep&
rhs)
const override
108 return this->_Equals_Reference_Implementation (
rhs);
113 auto i = fData_.Find (
item);
114 bool notDone = i != fData_.end ();
127 fChangeCounts_.PerformedChange ();
133 auto i = fData_.Find (
item);
134 if (i != fData_.end ()) [[
likely]] {
136 fChangeCounts_.PerformedChange ();
143 Require (
not i.AtEnd ());
144 auto&
mir = Debug::UncheckedDynamicCast<const IteratorRep_&> (i.ConstGetRep ());
145 mir.fIterator.AssertDataMatches (&fData_);
146 if (
nextI ==
nullptr) {
147 fData_.Remove (
mir.fIterator);
148 fChangeCounts_.PerformedChange ();
151 auto ret = fData_.erase (
mir.fIterator);
152 fChangeCounts_.PerformedChange ();
162 return fData_.key_comp ();
167 struct IterTraits_ : Private::IteratorImplHelper_DefaultTraits<value_type, DataStructureImplType_> {
168 static constexpr value_type ConvertDataStructureIterationResult2ContainerIteratorResult (
const typename DataStructureImplType_::value_type& t)
173 using IteratorRep_ = Private::IteratorImplHelper_<value_type, DataStructureImplType_, IterTraits_>;
176 DataStructureImplType_ fData_;
188 template <
typename T>
192 AssertRepValidType_ ();
194 template <
typename T>
195 template <IThreeWayComparer<T> COMPARER>
197 : inherited{Memory::MakeSharedPtr<Rep_<remove_cvref_t<COMPARER>>> (forward<COMPARER> (comparer))}
199 AssertRepValidType_ ();
201 template <
typename T>
203 : SortedSet_SkipList{}
206 AssertRepValidType_ ();
208 template <
typename T>
209 template <IThreeWayComparer<T> COMPARER>
211 : SortedSet_SkipList{forward<COMPARER> (comparer)}
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>, SortedSet_SkipList<T>>)
221 : SortedSet_SkipList{}
223 this->AddAll (forward<ITERABLE_OF_ADDABLE> (src));
224 AssertRepValidType_ ();
227 template <
typename T>
228 template <IThreeWayComparer<T> COMPARER, IIterableOfTo<T> ITERABLE_OF_ADDABLE>
230 : SortedSet_SkipList (forward<COMPARER> (comparer))
233 AssertRepValidType_ ();
235 template <
typename T>
236 template <IInputIterator<T> ITERATOR_OF_ADDABLE>
238 : SortedSet_SkipList{}
241 AssertRepValidType_ ();
243 template <
typename T>
244 template <IThreeWayComparer<T> COMPARER, IInputIterator<T> ITERATOR_OF_ADDABLE>
246 : SortedSet_SkipList (forward<COMPARER> (comparer))
249 AssertRepValidType_ ();
251 template <
typename T>
252 inline void SortedSet_SkipList<T>::AssertRepValidType_ ()
const
255 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)
bool Equals(const T *lhs, const T *rhs)
strcmp or wsccmp() as appropriate == 0
#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...
SortedSet_SkipList<T> is an std::set-based concrete implementation of the SortedSet<T> container patt...
nonvirtual optional< value_type > Lookup(ArgByValueType< value_type > item) const
nonvirtual ElementEqualityComparerType GetElementEqualsComparer() const
nonvirtual Set CloneEmpty() const
for return Set<T> { s->GetEqualsComparer(); } - except more efficient - clones settings/dynamic subty...
nonvirtual void Remove(ArgByValueType< value_type > item)
Remove the item (given by value or iterator pointing to it) from the contain. The item MUST exist.
nonvirtual bool RemoveIf(ArgByValueType< value_type > item)
nonvirtual void Add(ArgByValueType< value_type > item)
nonvirtual void AddAll(ITERATOR_OF_ADDABLE &&start, ITERATOR_OF_ADDABLE2 &&end)
nonvirtual ElementThreeWayComparerType GetElementThreeWayComparer() const
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,...