Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Stroika::Foundation::Containers::Collection< T > Class Template Reference

A Collection<T> is a container to manage an un-ordered collection of items, without equality defined for T. More...

#include <Collection.h>

Inheritance diagram for Stroika::Foundation::Containers::Collection< T >:
Stroika::Foundation::Traversal::Iterable< T > Stroika::Foundation::Containers::Private::ArrayBasedContainer< Collection_Array< T >, Collection< T >, false > Stroika::Foundation::Containers::Concrete::Collection_LinkedList< T > Stroika::Foundation::Containers::Concrete::Collection_stdforward_list< T > Stroika::Foundation::Containers::SortedCollection< T > Stroika::Foundation::Containers::Concrete::Collection_Array< T > Stroika::Foundation::Containers::Private::SkipListBasedContainer< SortedCollection_SkipList< T >, SortedCollection< T >, true > Stroika::Foundation::Containers::Concrete::SortedCollection_LinkedList< T > Stroika::Foundation::Containers::Concrete::SortedCollection_stdmultiset< T > Stroika::Foundation::Containers::Concrete::SortedCollection_SkipList< T >

Classes

class  _IRep
 Implementation detail for Collection<T> implementors. More...
 

Public Types

using ArchetypeContainerType = Collection
 
using value_type = typename inherited::value_type
 
- Public Types inherited from Stroika::Foundation::Traversal::Iterable< T >
using value_type = T
 value_type is an alias for the type iterated over - like vector<T>::value_type
 
using iterator = Iterator< T >
 
using const_iterator = Iterator< T >
 

Public Member Functions

 Collection ()
 
template<Common::IEqualsComparer< T > EQUALS_COMPARER = equal_to<T>>
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 Add (ArgByValueType< value_type > item)
 
template<IInputIterator< T > ITERATOR_OF_ADDABLE, sentinel_for< remove_cvref_t< ITERATOR_OF_ADDABLE > > ITERATOR_OF_ADDABLE2>
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)
 
template<Common::IPotentiallyComparer< T > EQUALS_COMPARER = equal_to<T>>
nonvirtual void Remove (ArgByValueType< value_type > item, EQUALS_COMPARER &&equalsComparer={})
 Remove () the argument value (which must exist)
 
template<Common::IEqualsComparer< T > EQUALS_COMPARER = equal_to<T>>
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 void RemoveAll ()
 RemoveAll removes all, or all matching (predicate, iterator range, equals comparer or whatever) items.
 
template<typename RESULT_CONTAINER = Collection<T>, invocable< T > ELEMENT_MAPPER>
requires (convertible_to<invoke_result_t<ELEMENT_MAPPER, T>, typename RESULT_CONTAINER::value_type> or convertible_to<invoke_result_t<ELEMENT_MAPPER, T>, optional<typename RESULT_CONTAINER::value_type>>)
nonvirtual RESULT_CONTAINER Map (ELEMENT_MAPPER &&elementMapper) const
 'override' Iterable<>::Map () function so RESULT_CONTAINER defaults to Collection, and improve that case to clone properties from this rep (such is rep type, comparisons etc).
 
template<derived_from< Iterable< T > > RESULT_CONTAINER = Collection<T>, predicate< T > INCLUDE_PREDICATE>
nonvirtual RESULT_CONTAINER Where (INCLUDE_PREDICATE &&includeIfTrue) const
 return a subset of the Collection for which includeIfTrue returns true.
 
nonvirtual void clear ()
 
template<Common::IEqualsComparer< T > EQUALS_COMPARER = equal_to<T>>
nonvirtual void erase (ArgByValueType< value_type > item, EQUALS_COMPARER &&equalsComparer={})
 
nonvirtual Collectionoperator+= (ArgByValueType< value_type > item)
 
- Public Member Functions inherited from Stroika::Foundation::Traversal::Iterable< T >
 Iterable (const Iterable &) noexcept=default
 Iterable are safely copyable (by value). Since Iterable uses COW, this just copies the underlying pointer and increments the reference count.
 
 Iterable (Iterable &&) noexcept=default
 Iterable are safely moveable.
 
template<IIterableOfTo< T > CONTAINER_OF_T>
requires (not derived_from<remove_cvref_t<CONTAINER_OF_T>, Iterable<T>>)
 Iterable (CONTAINER_OF_T &&from)
 
 Iterable (const initializer_list< T > &from)
 
nonvirtual operator bool () const
 
nonvirtual Iterator< T > MakeIterator () const
 Create an iterator object which can be used to traverse the 'Iterable'.
 
nonvirtual size_t size () const
 Returns the number of items contained.
 
nonvirtual bool empty () const
 Returns true iff size() == 0.
 
template<Common::IPotentiallyComparer< T > EQUALS_COMPARER = equal_to<T>>
nonvirtual bool Contains (ArgByValueType< T > element, EQUALS_COMPARER &&equalsComparer=EQUALS_COMPARER{}) const
 
nonvirtual Iterator< T > begin () const
 Support for ranged for, and STL syntax in general.
 
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.
 
template<predicate< T > THAT_FUNCTION>
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, and return an iterator pointing at the first element (depending on seq) found true. (or use First() to do same thing but return optional<>)
 
template<IIterableOfFrom< T > CONTAINER_OF_T, typename... CONTAINER_OF_T_CONSTRUCTOR_ARGS>
nonvirtual CONTAINER_OF_T As (CONTAINER_OF_T_CONSTRUCTOR_ARGS... args) const
 
nonvirtual T Nth (ptrdiff_t n) const
 Find the Nth element of the Iterable<>
 
nonvirtual T NthValue (ptrdiff_t n, ArgByValueType< T > defaultValue={}) const
 Find the Nth element of the Iterable<>, but allow for n to be out of range, and just return argument default-value.
 
template<derived_from< Iterable< T > > RESULT_CONTAINER = Iterable<T>, predicate< T > INCLUDE_PREDICATE>
nonvirtual RESULT_CONTAINER Where (INCLUDE_PREDICATE &&includeIfTrue) const
 produce a subset of this iterable where argument function returns true
 
template<Common::IPotentiallyComparer< T > EQUALS_COMPARER = equal_to<T>>
nonvirtual Iterable< T > Distinct (EQUALS_COMPARER &&equalsComparer=EQUALS_COMPARER{}) const
 
template<ranges::range RESULT_CONTAINER = Iterable<T>, invocable< T > ELEMENT_MAPPER>
requires (convertible_to<invoke_result_t<ELEMENT_MAPPER, T>, typename RESULT_CONTAINER::value_type> or convertible_to<invoke_result_t<ELEMENT_MAPPER, T>, optional<typename RESULT_CONTAINER::value_type>>)
nonvirtual RESULT_CONTAINER Map (ELEMENT_MAPPER &&elementMapper) const
 functional API which iterates over all members of an Iterable, applies a map function to each element, and collects the results in a new Iterable
 
template<typename REDUCED_TYPE = T>
nonvirtual optional< REDUCED_TYPE > Reduce (const function< REDUCED_TYPE(ArgByValueType< T >, ArgByValueType< T >)> &op) const
 Walk the entire list of items, and use the argument 'op' to combine (reduce) items to a resulting single item.
 
template<typename REDUCED_TYPE = T>
nonvirtual REDUCED_TYPE ReduceValue (const function< REDUCED_TYPE(ArgByValueType< T >, ArgByValueType< T >)> &op, ArgByValueType< REDUCED_TYPE > defaultValue={}) const
 
template<typename RESULT_T = Characters::String, invocable< T > CONVERT_TO_RESULT = decltype (kDefaultToStringConverter<>), invocable< RESULT_T, RESULT_T, bool > COMBINER = decltype (Characters::kDefaultStringCombiner)>
requires (convertible_to<invoke_result_t<CONVERT_TO_RESULT, T>, RESULT_T> and convertible_to<invoke_result_t<COMBINER, RESULT_T, RESULT_T, bool>, RESULT_T>)
nonvirtual RESULT_T Join (const CONVERT_TO_RESULT &convertToResult=kDefaultToStringConverter<>, const COMBINER &combiner=Characters::kDefaultStringCombiner) const
 ape the JavaScript/python 'join' function - take the parts of 'this' iterable and combine them into a new object (typically a string)
 
nonvirtual Iterable< T > Skip (size_t nItems) const
 
nonvirtual Iterable< T > Take (size_t nItems) const
 
nonvirtual Iterable< T > Slice (size_t from, size_t to) const
 
nonvirtual Iterable< T > Top () const
 return the top/largest (possibly just top N) values from this Iterable<T>
 
template<Common::IPotentiallyComparer< T > INORDER_COMPARER_TYPE = less<T>>
nonvirtual Iterable< T > OrderBy (INORDER_COMPARER_TYPE &&inorderComparer=INORDER_COMPARER_TYPE{}, Execution::SequencePolicy seq=Execution::SequencePolicy::ePar) const
 
template<Common::IPotentiallyComparer< T > INORDER_COMPARER_TYPE = less<T>>
nonvirtual bool IsOrderedBy (INORDER_COMPARER_TYPE &&inorderComparer=INORDER_COMPARER_TYPE{}) const
 
nonvirtual optional< T > First () const
 return first element in iterable, or if 'that' specified, first where 'that' is true, (or return nullopt if none)
 
nonvirtual T FirstValue (ArgByValueType< T > defaultValue={}) const
 return first element in iterable provided default
 
nonvirtual optional< T > Last () const
 return last element in iterable, or if 'that' specified, last where 'that' is true, (or return missing)
 
nonvirtual T LastValue (ArgByValueType< T > defaultValue={}) const
 
nonvirtual bool All (const function< bool(ArgByValueType< T >)> &testEachElt) const
 return true iff argument predicate returns true for each element of the iterable
 
nonvirtual optional< T > Min () const
 
template<typename RESULT_TYPE = T>
nonvirtual RESULT_TYPE MinValue (ArgByValueType< RESULT_TYPE > defaultValue={}) const
 
nonvirtual optional< T > Max () const
 
template<typename RESULT_TYPE = T>
nonvirtual RESULT_TYPE MaxValue (ArgByValueType< RESULT_TYPE > defaultValue={}) const
 
template<typename RESULT_TYPE = T>
nonvirtual optional< RESULT_TYPE > Mean () const
 
template<typename RESULT_TYPE = T>
nonvirtual RESULT_TYPE MeanValue (ArgByValueType< RESULT_TYPE > defaultValue={}) const
 
template<typename RESULT_TYPE = T>
nonvirtual optional< RESULT_TYPE > Sum () const
 
template<typename RESULT_TYPE = T>
nonvirtual RESULT_TYPE SumValue (ArgByValueType< RESULT_TYPE > defaultValue={}) const
 
template<constructible_from< T > RESULT_TYPE = T, Common::IPotentiallyComparer< RESULT_TYPE > INORDER_COMPARE_FUNCTION = less<RESULT_TYPE>>
nonvirtual optional< RESULT_TYPE > Median (const INORDER_COMPARE_FUNCTION &compare={}) const
 
template<constructible_from< T > RESULT_TYPE = T>
nonvirtual RESULT_TYPE MedianValue (ArgByValueType< RESULT_TYPE > defaultValue={}) const
 
nonvirtual Iterable< T > Repeat (size_t count) const
 
nonvirtual bool Any () const
 Any() same as not empty (); Any (includeIfTrue) returns true iff includeIfTrue returns true on any values in iterable.
 
nonvirtual size_t Count () const
 with no args, same as size, with function filter arg, returns number of items that pass.
 
nonvirtual size_t length () const
 STL-ish alias for size() - really in STL only used in string, I think, but still makes sense as an alias.
 

Protected Member Functions

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 - _SafeReadWriteRepAccessor<_IRep>{this}._GetWriteableRep ()) but where we also handle the cloning/patching of the associated iterator.
 
- Protected Member Functions inherited from Stroika::Foundation::Traversal::Iterable< T >
 Iterable (const shared_ptr< _IRep > &rep) noexcept
 Iterable's are typically constructed as concrete subtype objects, whose CTOR passed in a shared copyable rep.
 
nonvirtual Memory::SharedByValue_State _GetSharingState () const
 

Additional Inherited Members

- Static Public Member Functions inherited from Stroika::Foundation::Traversal::Iterable< T >
template<ranges::range LHS_CONTAINER_TYPE, ranges::range RHS_CONTAINER_TYPE, IEqualsComparer< T > EQUALS_COMPARER = equal_to<T>>
static bool SetEquals (const LHS_CONTAINER_TYPE &lhs, const RHS_CONTAINER_TYPE &rhs, EQUALS_COMPARER &&equalsComparer=EQUALS_COMPARER{})
 
template<ranges::range LHS_CONTAINER_TYPE, ranges::range RHS_CONTAINER_TYPE, IEqualsComparer< T > EQUALS_COMPARER = equal_to<T>>
static bool MultiSetEquals (const LHS_CONTAINER_TYPE &lhs, const RHS_CONTAINER_TYPE &rhs, EQUALS_COMPARER &&equalsComparer=EQUALS_COMPARER{})
 
template<ranges::range LHS_CONTAINER_TYPE, ranges::range RHS_CONTAINER_TYPE, IEqualsComparer< T > EQUALS_COMPARER = equal_to<T>>
static bool SequentialEquals (const LHS_CONTAINER_TYPE &lhs, const RHS_CONTAINER_TYPE &rhs, EQUALS_COMPARER &&equalsComparer=EQUALS_COMPARER{}, bool useIterableSize=false)
 
static constexpr default_sentinel_t end () noexcept
 Support for ranged for, and STL syntax in general.
 
- Static Public Attributes inherited from Stroika::Foundation::Traversal::Iterable< T >
template<same_as< Characters::String > RESULT_T = Characters::String>
static const function< RESULT_T(T)> kDefaultToStringConverter
 
- Protected Types inherited from Stroika::Foundation::Traversal::Iterable< T >
using _SharedByValueRepType = Memory::SharedByValue< _IRep, Memory::SharedByValue_Traits< _IRep, shared_ptr< _IRep >, Rep_Cloner_ > >
 Lazy-copying smart pointer mostly used by implementors (can generally be ignored by users). However, protected because manipulation needed in some subclasses (rarely) - like UpdatableIteratable.
 
- Protected Attributes inherited from Stroika::Foundation::Traversal::Iterable< T >
_SharedByValueRepType _fRep
 

Detailed Description

template<typename T>
class Stroika::Foundation::Containers::Collection< T >

A Collection<T> is a container to manage an un-ordered collection of items, without equality defined for T.

A Collection<T> is a container pattern to manage an un-ordered collection of items, without equality defined for T. This is both an abstract interface, but the Collection<T> class it actually concrete because it automatically binds to a default implementation.

Note
This means that the order in which items appear during iteration is arbitrary and may vary from collection to collection type.

Some sub-types of Collection<T> - like SortedCollection<> - do make specific promises about ordering.

A Collection<T> is the simplest kind of collection. It allows addition and removal of elements, but makes no guarantees about element ordering.

Performance Collections are typically designed to optimize item addition and iteration. They are fairly slow at item access (as they have no keys). Removing items is usually slow, except in the context of an Iterator<T>, where it is usually very fast.

Note
See ReadMe.md for common features of all Stroika containers (especially constructors, iterators, etc)
Thread-Safety C++-Standard-Thread-Safety

Concrete Implementations: o

See also
Concrete::Collection_Array<> o
Concrete::Collection_LinkedList<> o
Concrete::Collection_stdforward_list<> o
Concrete::SortedCollection_stdmultiset<> o
Concrete::SortedCollection_SkipList<>
Note
Shake Considered adding a Shake() method (when this was called Bag<T>), but that would restrict the use to backends capable of this randomizing of order (eg. not hash tables or trees), and is incompatible with the idea of subtypes like SortedCollection<T>. Also since a Collection<> intrinsically has no ordering, I'm not totally sure what it would mean to Shake/change its ordering?
EQUALS_COMPARER (operator==, operator!=) We do not provide a notion of 'Equals' or operator==, operator!=, because its not clear how to compare collections (no ordering defined, sometimes sorted, no equals defined for ELTS etc)

The caller may use the inherited (from Iterable<>) SetEquals, MultiSetEquals, or SequenceEquals() as appropriate. Methods that require and equals comparer, take one as argument with appropriate defaulting.

Note
Comparisons: static_assert (not equality_comparable<Collection<...>>);

o No comparisons are provided, because there is no intrinsic way to compare collections for equality, less etc. (order not defined) See inherited Iterable<>::SequentialEquals, Iterable<>::MultiSetEquals, , Iterable<>::SetEquals.

Definition at line 102 of file Collection.h.

Member Typedef Documentation

◆ ArchetypeContainerType

template<typename T >
using Stroika::Foundation::Containers::Collection< T >::ArchetypeContainerType = Collection

Use this typedef in templates to recover the basic functional container pattern of concrete types.

Definition at line 110 of file Collection.h.

◆ value_type

template<typename T >
using Stroika::Foundation::Containers::Collection< T >::value_type = typename inherited::value_type
See also
inherited::value_type

Definition at line 116 of file Collection.h.

Constructor & Destructor Documentation

◆ Collection()

template<typename T >
Stroika::Foundation::Containers::Collection< T >::Collection ( )

For the CTOR overload with ITERABLE_OF_ADDABLE, its anything that supports c.begin(), c.end () to find all the elements, and which has elements (iterated) convertible to T.

Example Usage
std::vector<int> v;
Collection<int> c1 = {1, 2, 3};
Collection<int> c3{ c1 };
Collection<int> c4{ c1.begin (), c1.end () };
Collection<int> c5{ s };
Collection<int> c6{ v };
Collection<int> c7{ v.begin (), v.end () };
Collection<int> c8{ move (c1) };
A Collection<T> is a container to manage an un-ordered collection of items, without equality defined ...
Definition Collection.h:102
A generalization of a vector: a container whose elements are keyed by the natural numbers.
Definition Sequence.h:187
nonvirtual Iterator< T > begin() const
Support for ranged for, and STL syntax in general.
static constexpr default_sentinel_t end() noexcept
Support for ranged for, and STL syntax in general.
Note
Most other containers (e.g. Set<>, Sequence<>) have the 'ITERABLE_OF_ADDABLE&& src' CTOR be explicit, whereas Collection does not. This is because converting to a Set or Sequence has some semantics, and the programmer should be clear on this. But a Collection<> acts just like an Iterable<T> (except that its modifiable). So allow this case to be non-explicit.
See general information about container constructors that applies here

Definition at line 22 of file Collection.inl.

Member Function Documentation

◆ Add()

template<typename T >
void Stroika::Foundation::Containers::Collection< T >::Add ( ArgByValueType< value_type item)

Add the given item(s) to this Collection<T>. Note - if the given items are already present, another copy will be added. No promises are made about where the added value will appear in iteration.

Note
overload taking Iterator<T>* addedAt returns an iterator pointing at the added item.
mutates container

Definition at line 97 of file Collection.inl.

◆ AddAll()

template<typename T >
template<IInputIterator< T > ITERATOR_OF_ADDABLE, sentinel_for< remove_cvref_t< ITERATOR_OF_ADDABLE > > ITERATOR_OF_ADDABLE2>
nonvirtual void Stroika::Foundation::Containers::Collection< T >::AddAll ( ITERATOR_OF_ADDABLE &&  start,
ITERATOR_OF_ADDABLE2 &&  end 
)
Aliases
AddAll/2 is alias for .net AddRange ()
Note
mutates container

◆ Update()

template<typename T >
void Stroika::Foundation::Containers::Collection< T >::Update ( const Iterator< value_type > &  i,
ArgByValueType< value_type newValue,
Iterator< value_type > *  nextI = nullptr 
)

This function requires that the iterator 'i' came from this container.

The value pointed to by 'i' is updated - replaced with the value 'newValue'.

Note
if you update the container, and wish to continue iterating, you must pass in an &i to nextI, and continue using that iterator (i is invalid after this call). It is left undefined, whether or not you will encounter the item 'i' again in iteration (for example, if the container is sorted, and you change the associated value to larger, you probably will encounter it again).
- this nextI value is therefore of very little value, since you cannot reliably continue iterating with it, knowing what you will get next.

This is basically the same as {Remove (i); Add (newValue);} except that it might perform better.

Note
mutates container

Definition at line 111 of file Collection.inl.

◆ Remove()

template<typename T >
template<Common::IPotentiallyComparer< T > EQUALS_COMPARER = equal_to<T>>
nonvirtual void Stroika::Foundation::Containers::Collection< T >::Remove ( ArgByValueType< value_type item,
EQUALS_COMPARER &&  equalsComparer = {} 
)

Remove () the argument value (which must exist)

See also
RemoveIf() to remove an item that may not exist

This will reduce the size of the container by one.

Parameters
nextI- if provided (not null) - will be filled in with the next value after where iterator i is pointing - since i is invalidated by changing the container)
Note
mutates container

◆ RemoveIf()

template<typename T >
template<Common::IEqualsComparer< T > EQUALS_COMPARER = equal_to<T>>
nonvirtual bool Stroika::Foundation::Containers::Collection< T >::RemoveIf ( ArgByValueType< value_type item,
EQUALS_COMPARER &&  equalsComparer = {} 
)

RemoveIf () the (the first matching) argument value, if present. Returns true if item removed.

It is legal to remove something that is not there. This function removes the first instance of item (or each item for the 'items' overload), meaning that another instance of item could still be in the Collection<T> after the remove.

The overload Remove(PREDICATE) applies the function p(T) -> bool and deletes the first entry (if any) that return true for the predicate.

Note
mutates container

◆ RemoveAll()

template<typename T >
void Stroika::Foundation::Containers::Collection< T >::RemoveAll ( )

RemoveAll removes all, or all matching (predicate, iterator range, equals comparer or whatever) items.

The no-arg overload removes all (quickly).

The overloads that remove some subset of the items returns the number of items so removed.

The overload with Iterator<T> arguments (start/end) must be iterators from this container.

Note
mutates container

Definition at line 155 of file Collection.inl.

◆ Where()

template<typename T >
template<derived_from< Iterable< T > > RESULT_CONTAINER = Collection<T>, predicate< T > INCLUDE_PREDICATE>
nonvirtual RESULT_CONTAINER Stroika::Foundation::Containers::Collection< T >::Where ( INCLUDE_PREDICATE &&  includeIfTrue) const

return a subset of the Collection for which includeIfTrue returns true.

Defaults to returning a Collection<>, but pass in Iterable<T> type argument to get a lazy-evaluated iterable result.

Example Usage
Collection<int> c { 1, 2, 3, 4, 5, 6 };
EXPECT_TRUE (c.Where ([] (int i) { return i % 2 == 0; }).SetEquals (Iterable<int> { 2, 4, 6 }));
EXPECT_TRUE (c.Where<Iterable<int>> ([] (int i) { return i % 2 == 0; }).SetEquals (Iterable<int> { 2, 4, 6 })); // to get lazy evaluation
Iterable<T> is a base class for containers which easily produce an Iterator<T> to traverse them.
Definition Iterable.h:237
static bool SetEquals(const LHS_CONTAINER_TYPE &lhs, const RHS_CONTAINER_TYPE &rhs, EQUALS_COMPARER &&equalsComparer=EQUALS_COMPARER{})
Definition Iterable.inl:320

◆ clear()

template<typename T >
void Stroika::Foundation::Containers::Collection< T >::clear ( )
Aliases
RemoveAll ().
Note
mutates container

Definition at line 202 of file Collection.inl.

◆ erase()

template<typename T >
template<Common::IEqualsComparer< T > EQUALS_COMPARER = equal_to<T>>
nonvirtual void Stroika::Foundation::Containers::Collection< T >::erase ( ArgByValueType< value_type item,
EQUALS_COMPARER &&  equalsComparer = {} 
)
Aliases
Remove ().
Note
mutates container

◆ operator+=()

template<typename T >
auto Stroika::Foundation::Containers::Collection< T >::operator+= ( ArgByValueType< value_type item)

operator+ is syntactic sugar on Add() or AddAll() - depending on the overload.

DEVELOPER NOTE Note - we use an overload of Collection<T> for the container case instead of a template, because I'm not sure how to use specializations to distinguish the two cases. If I can figure that out, this can transparently be replaced with operator+= (X), with appropriate specializations.

Note
mutates container

Definition at line 248 of file Collection.inl.

◆ _GetWritableRepAndPatchAssociatedIterator()

template<typename T >
auto Stroika::Foundation::Containers::Collection< T >::_GetWritableRepAndPatchAssociatedIterator ( const Iterator< value_type > &  i)
protected

Utility to get WRITABLE underlying shared_ptr (replacement for what we normally do - _SafeReadWriteRepAccessor<_IRep>{this}._GetWriteableRep ()) but where we also handle the cloning/patching of the associated iterator.

When you have a non-const operation (such as Remove) with an argument of an Iterator<>, then due to COW, you may end up cloning the container rep, and yet the Iterator<> contains a pointer to the earlier rep (and so maybe unusable).

Prior to Stroika 2.1b14, this was handled elegantly, and automatically, by the iterator patching mechanism. But that was deprecated (due to cost, and rarity of use), in favor of this more restricted feature, where we just patch the iterators on an as-needed basis.

Definition at line 260 of file Collection.inl.


The documentation for this class was generated from the following files: