25 _AssertRepValidType ();
28 template <IInputIterator<T> ITERATOR_OF_ADDABLE, sentinel_for<remove_cvref_t<ITERATOR_OF_ADDABLE>> ITERATOR_OF_ADDABLE2>
32 AddAll (forward<ITERATOR_OF_ADDABLE> (start), forward<ITERATOR_OF_ADDABLE2> (
end));
33 _AssertRepValidType ();
40 _AssertRepValidType ();
46 _AssertRepValidType ();
53 _AssertRepValidType ();
55#if !qCompilerAndStdLib_RequiresNotMatchInlineOutOfLineForTemplateClassBeingDefined_Buggy
57 template <IIterableOfTo<T> ITERABLE_OF_ADDABLE>
58 requires (not derived_from<remove_cvref_t<ITERABLE_OF_ADDABLE>, Collection<T>>)
62 AddAll (forward<ITERABLE_OF_ADDABLE> (src));
63 _AssertRepValidType ();
67 template <Common::IEqualsComparer<T> EQUALS_COMPARER>
70 return this->Find (item, forward<EQUALS_COMPARER> (equalsComparer)) != this->end ();
73 template <IInputIterator<T> ITERATOR_OF_ADDABLE, sentinel_for<remove_cvref_t<ITERATOR_OF_ADDABLE>> ITERATOR_OF_ADDABLE2>
76 _SafeReadWriteRepAccessor<_IRep> tmp{
this};
77 for (
auto i = forward<ITERATOR_OF_ADDABLE> (start); i != forward<ITERATOR_OF_ADDABLE2> (end); ++i) {
78 tmp._GetWriteableRep ().Add (*i,
nullptr);
82 template <IIterableOfTo<T> ITERABLE_OF_ADDABLE>
85 if constexpr (std::is_convertible_v<remove_cvref_t<ITERABLE_OF_ADDABLE>*, Collection<value_type>*>) {
87 if (
static_cast<const Iterable<value_type>*
> (
this) ==
static_cast<const Iterable<value_type>*
> (&items)) [[unlikely]] {
89 vector<value_type> copy{std::begin (items), Iterator<value_type>{std::end (items)}};
90 AddAll (std::begin (copy), std::end (copy));
94 AddAll (std::begin (items), std::end (items));
99 _SafeReadWriteRepAccessor<_IRep>{
this}._GetWriteableRep ().Add (item,
nullptr);
100 Ensure (not this->empty ());
102 template <
typename T>
106 _SafeReadWriteRepAccessor<_IRep>{
this}._GetWriteableRep ().Add (item, addedAt);
107 Ensure (not this->empty ());
108 Ensure (not addedAt->
Done ());
110 template <
typename T>
113 Require (not i.
Done ());
114 auto [writerRep, patchedIterator] = _GetWritableRepAndPatchAssociatedIterator (i);
115 writerRep->Update (patchedIterator, newValue, nextI);
117 template <
typename T>
120 Require (not i.
Done ());
121 auto [writerRep, patchedIterator] = _GetWritableRepAndPatchAssociatedIterator (i);
122 writerRep->Remove (patchedIterator, nextI);
124 template <
typename T>
125 template <Common::IPotentiallyComparer<T> EQUALS_COMPARER>
128 auto i = this->Find (item, forward<EQUALS_COMPARER> (equalsComparer));
129 Require (i != this->end ());
130 auto [writerRep, patchedIterator] = _GetWritableRepAndPatchAssociatedIterator (i);
131 writerRep->Remove (patchedIterator,
nullptr);
133 template <
typename T>
134 template <Common::IEqualsComparer<T> EQUALS_COMPARER>
137 if (
auto i = this->Find (item, forward<EQUALS_COMPARER> (equalsComparer))) {
138 auto [writerRep, patchedIterator] = _GetWritableRepAndPatchAssociatedIterator (i);
139 writerRep->Remove (patchedIterator,
nullptr);
144 template <
typename T>
145 template <predicate<T> PREDICATE>
148 if (
auto i = this->Find (forward<PREDICATE> (p))) {
154 template <
typename T>
157 _SafeReadRepAccessor<_IRep> tmp{
this};
158 if (not tmp._ConstGetRep ().empty ()) {
159 this->_fRep = tmp._ConstGetRep ().CloneEmpty ();
162 template <
typename T>
163 template <Common::IEqualsComparer<T> EQUALS_COMPARER>
167 for (
auto i = start; i != end;) {
168 if (RemoveIf (*i, equalsComparer, &i)) {
174 template <
typename T>
175 template <IIterableOfTo<T> ITERABLE_OF_ADDABLE,
typename EQUALS_COMPARER>
178 if (
static_cast<const void*
> (
this) ==
static_cast<const void*
> (addressof (c))) {
179 return RemoveAll (forward<EQUALS_COMPARER> (equalsComparer));
182 return RemoveAll (std::begin (c), std::end (c), forward<EQUALS_COMPARER> (equalsComparer));
185 template <
typename T>
186 template <predicate<T> PREDICATE>
201 template <
typename T>
206 template <
typename T>
207 template <Common::IEqualsComparer<T> EQUALS_COMPARER>
208 inline void Collection<T>::erase (ArgByValueType<value_type> item, EQUALS_COMPARER&& equalsComparer)
210 Remove (item, forward<EQUALS_COMPARER> (equalsComparer));
212 template <
typename T>
215 Iterator<value_type> nextI{
nullptr};
219 template <
typename T>
220 template <
typename RESULT_CONTAINER, invocable<T> ELEMENT_MAPPER>
222 requires (convertible_to<invoke_result_t<ELEMENT_MAPPER, T>,
typename RESULT_CONTAINER::value_type> or
223 convertible_to<invoke_result_t<ELEMENT_MAPPER, T>, optional<typename RESULT_CONTAINER::value_type>>)
225 if constexpr (same_as<RESULT_CONTAINER, Collection>) {
227 return inherited::template Map<RESULT_CONTAINER> (forward<ELEMENT_MAPPER> (elementMapper),
228 RESULT_CONTAINER{_SafeReadRepAccessor<_IRep>{
this}._ConstGetRep ().CloneEmpty ()});
231 return inherited::template Map<RESULT_CONTAINER> (forward<ELEMENT_MAPPER> (elementMapper));
234 template <
typename T>
235 template <derived_from<Iterable<T>> RESULT_CONTAINER, predicate<T> INCLUDE_PREDICATE>
238 if constexpr (same_as<RESULT_CONTAINER, Collection>) {
240 return inherited::template Where<RESULT_CONTAINER> (
241 forward<INCLUDE_PREDICATE> (includeIfTrue), RESULT_CONTAINER{_SafeReadRepAccessor<_IRep>{
this}._ConstGetRep ().CloneEmpty ()});
244 return inherited::template Where<RESULT_CONTAINER> (forward<INCLUDE_PREDICATE> (includeIfTrue));
247 template <
typename T>
253 template <
typename T>
259 template <
typename T>
262 Require (not i.
Done ());
263 using element_type =
typename inherited::_SharedByValueRepType::element_type;
265 element_type* writableRep = this->_fRep.rwget ([&] (
const element_type& prevRepPtr) ->
typename inherited::_SharedByValueRepType::shared_ptr_type {
266 return Debug::UncheckedDynamicCast<const _IRep&> (prevRepPtr).CloneAndPatchIterator (&patchedIterator);
269 return make_tuple (Debug::UncheckedDynamicCast<_IRep*> (writableRep), move (patchedIterator));
271 template <
typename T>
275 _SafeReadRepAccessor<_IRep>{
this};
284 template <
typename T>
291 template <
typename T>
292 Collection<T>
operator+ (
const Collection<T>& lhs,
const Iterable<T>& rhs)
294 Collection<T> result{lhs};
298 template <
typename T>
299 Collection<T>
operator+ (
const Collection<T>& lhs,
const Collection<T>& rhs)
301 Collection<T> result{lhs};
#define qStroika_Foundation_Debug_AssertionsChecked
The qStroika_Foundation_Debug_AssertionsChecked flag determines if assertions are checked and validat...
#define RequireNotNull(p)
#define RequireExpression(c)
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)
typename inherited::value_type value_type
nonvirtual void Update(const Iterator< value_type > &i, ArgByValueType< value_type > newValue, Iterator< value_type > *nextI=nullptr)
nonvirtual bool Contains(ArgByValueType< value_type > item, EQUALS_COMPARER &&equalsComparer={}) const
Compares items with TRAITS::EqualsCompareFunctionType::Equals, and returns true if any match.
nonvirtual void Remove(ArgByValueType< value_type > item, EQUALS_COMPARER &&equalsComparer={})
Remove () the argument value (which must exist)
nonvirtual RESULT_CONTAINER Map(ELEMENT_MAPPER &&elementMapper) const
'override' Iterable<>::Map () function so RESULT_CONTAINER defaults to Collection,...
nonvirtual void erase(ArgByValueType< value_type > item, EQUALS_COMPARER &&equalsComparer={})
nonvirtual bool RemoveIf(ArgByValueType< value_type > item, EQUALS_COMPARER &&equalsComparer={})
RemoveIf () the (the first matching) argument value, if present. Returns true if item removed.
nonvirtual RESULT_CONTAINER Where(INCLUDE_PREDICATE &&includeIfTrue) const
return a subset of the Collection for which includeIfTrue returns true.
nonvirtual void Add(ArgByValueType< value_type > item)
nonvirtual tuple< _IRep *, Iterator< value_type > > _GetWritableRepAndPatchAssociatedIterator(const Iterator< value_type > &i)
Utility to get WRITABLE underlying shared_ptr (replacement for what we normally do - _SafeReadWriteRe...
nonvirtual Collection & operator+=(ArgByValueType< value_type > item)
nonvirtual void RemoveAll()
RemoveAll removes all, or all matching (predicate, iterator range, equals comparer or whatever) items...
Iterable<T> is a base class for containers which easily produce an Iterator<T> to traverse them.
static constexpr default_sentinel_t end() noexcept
Support for ranged for, and STL syntax in general.
An Iterator<T> is a copyable object which allows traversing the contents of some container....
nonvirtual bool Done() const
Done () means there is nothing left in this iterator (a synonym for (it == container....
Collection< T > operator+(const Iterable< T > &lhs, const Collection< T > &rhs)