4#include "Stroika/Foundation/Containers/DataStructures/LinkedList.h"
5#include "Stroika/Foundation/Containers/Private/IteratorImplHelper.h"
14 template <qCompilerAndStdLib_Constra
intDiffersInTemplateRedeclaration_BWA (IEqualsComparer<T>) EQUALS_COMPARER>
15 class Set_LinkedList<T>::Rep_ :
public IImplRepBase_,
public Memory::UseBlockAllocationIfAppropriate<Rep_<EQUALS_COMPARER>> {
17 using inherited = IImplRepBase_;
24 Rep_ (
const Rep_&
from) =
default;
30 nonvirtual Rep_& operator= (
const Rep_&) =
delete;
37 return Memory::MakeSharedPtr<Rep_> (*
this);
44 virtual size_t size ()
const override
47 return fData_.size ();
49 virtual bool empty ()
const override
52 return fData_.empty ();
74 return fEqualsComparer_;
79 return Memory::MakeSharedPtr<Rep_> (fEqualsComparer_);
85 auto result = Memory::MakeSharedPtr<Rep_> (*
this);
86 auto&
mir = Debug::UncheckedDynamicCast<const IteratorRep_&> (i->ConstGetRep ());
87 result->fData_.MoveIteratorHereAfterClone (&
mir.fIterator, &fData_);
91 virtual bool Equals (
const typename Iterable<value_type>::_IRep&
rhs)
const override
94 return this->_Equals_Reference_Implementation (
rhs);
99 typename DataStructureImplType_::UnderlyingIteratorRep
l =
113 for (
typename DataStructureImplType_::ForwardIterator
it{&fData_};
not it.Done (); ++
it) {
114 if (fEqualsComparer_ (*
it,
item)) {
115 fChangeCounts_.PerformedChange ();
119 fData_.push_front (
item);
120 fChangeCounts_.PerformedChange ();
125 for (
typename DataStructureImplType_::ForwardIterator
it{&fData_};
not it.Done (); ++
it) {
126 if (fEqualsComparer_ (*
it,
item)) {
128 fChangeCounts_.PerformedChange ();
137 auto&
mir = Debug::UncheckedDynamicCast<const IteratorRep_&> (i.ConstGetRep ());
138 if (
nextI ==
nullptr) {
139 fData_.Remove (
mir.fIterator);
140 fChangeCounts_.PerformedChange ();
143 auto ret = fData_.erase (
mir.fIterator);
144 fChangeCounts_.PerformedChange ();
150 using DataStructureImplType_ = DataStructures::LinkedList<value_type>;
151 using IteratorRep_ = Private::IteratorImplHelper_<value_type, DataStructureImplType_>;
154 DataStructureImplType_ fData_;
163 template <
typename T>
167 AssertRepValidType_ ();
169 template <
typename T>
170 template <IEqualsComparer<T> EQUALS_COMPARER>
171 inline Set_LinkedList<T>::Set_LinkedList (EQUALS_COMPARER&& equalsComparer)
172 : inherited{Memory::MakeSharedPtr<Rep_<remove_cvref_t<EQUALS_COMPARER>>> (forward<EQUALS_COMPARER> (equalsComparer))}
174 AssertRepValidType_ ();
176 template <
typename T>
181 AssertRepValidType_ ();
183 template <
typename T>
184 template <IEqualsComparer<T> EQUALS_COMPARER>
186 : Set_LinkedList{forward<EQUALS_COMPARER> (equalsComparer)}
189 AssertRepValidType_ ();
191#if !qCompilerAndStdLib_RequiresNotMatchInlineOutOfLineForTemplateClassBeingDefined_Buggy
192 template <
typename T>
193 template <IIterableOfTo<T> ITERABLE_OF_ADDABLE>
194 requires (not derived_from<remove_cvref_t<ITERABLE_OF_ADDABLE>, Set_LinkedList<T>>)
198 this->AddAll (forward<ITERABLE_OF_ADDABLE> (src));
199 AssertRepValidType_ ();
202 template <
typename T>
203 template <IEqualsComparer<T> EQUALS_COMPARER, IIterableOfTo<T> ITERABLE_OF_ADDABLE>
205 : Set_LinkedList{forward<EQUALS_COMPARER> (equalsComparer)}
208 AssertRepValidType_ ();
210 template <
typename T>
211 template <IInputIterator<T> ITERATOR_OF_ADDABLE>
216 AssertRepValidType_ ();
218 template <
typename T>
219 template <IEqualsComparer<T> EQUALS_COMPARER, IInputIterator<T> ITERATOR_OF_ADDABLE>
221 : Set_LinkedList{forward<EQUALS_COMPARER> (equalsComparer)}
224 AssertRepValidType_ ();
226 template <
typename T>
227 inline void Set_LinkedList<T>::AssertRepValidType_ ()
const
230 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
qStroika_ATTRIBUTE_NO_UNIQUE_ADDRESS - used for the attribute [[no_unique_address]]
#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...
Set_LinkedList<T> is an LinkedList-based concrete implementation of the Set<T> container pattern.
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)
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 CONTAINER_OF_T As(CONTAINER_OF_T_CONSTRUCTOR_ARGS... args) const
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,...