4#ifndef _Stroika_Foundation_Containers_KeyedCollection_h_
5#define _Stroika_Foundation_Containers_KeyedCollection_h_ 1
7#include "Stroika/Foundation/StroikaPreComp.h"
9#include "Stroika/Foundation/Common/Common.h"
11#include "Stroika/Foundation/Common/Concepts.h"
24 using Common::IEqualsComparer;
25 using Traversal::IInputIterator;
26 using Traversal::IIterableOfTo;
27 using Traversal::Iterable;
28 using Traversal::Iterator;
32 template <
typename POTENTIAL_KEY_EXTRACTOR,
typename T,
typename KEY_TYPE>
33 concept IKeyedCollection_KeyExctractor =
34 is_invocable_v<POTENTIAL_KEY_EXTRACTOR, T> and is_convertible_v<std::invoke_result_t<POTENTIAL_KEY_EXTRACTOR, T>, KEY_TYPE>;
67 template <
typename T,
typename KEY_TYPE,
typename KEY_EXTRACTOR_TYPE = function<KEY_TYPE (ArgByValueType<T>)>>
82 template <
typename T,
typename KEY_TYPE,
typename TRAITS>
84 is_invocable_v<typename TRAITS::KeyExtractorType, T> and
85 std::is_convertible_v<std::invoke_result_t<typename TRAITS::KeyExtractorType, T>, KEY_TYPE> and
86 default_initializable<typename TRAITS::KeyExtractorType> and not same_as<
typename TRAITS::KeyExtractorType, function<KEY_TYPE (T)>> and
87 not same_as<
typename TRAITS::KeyExtractorType, function<KEY_TYPE (
const T&)>>;
145 template <
typename T,
typename KEY_TYPE,
typename TRAITS = KeyedCollection_DefaultTraits<T, KEY_TYPE>>
240 template <IEqualsComparer<KEY_TYPE> KEY_EQUALS_COMPARER = equal_to<KEY_TYPE>>
248 template <IIterableOfTo<T> ITERABLE_OF_ADDABLE, IEqualsComparer<KEY_TYPE> KEY_EQUALS_COMPARER = equal_to<KEY_TYPE>>
256 _AssertRepValidType ();
260 template <IIterableOfTo<T> ITERABLE_OF_ADDABLE, IEqualsComparer<KEY_TYPE> KEY_EQUALS_COMPARER = equal_to<KEY_TYPE>>
268 _AssertRepValidType ();
272 template <IEqualsComparer<KEY_TYPE> KEY_EQUALS_COMPARER, IIterableOfTo<T> ITERABLE_OF_ADDABLE>
274 template <IIterableOfTo<T> ITERABLE_OF_ADDABLE>
277 template <IInputIterator<T> ITERATOR_OF_ADDABLE, sentinel_for<remove_cvref_t<ITERATOR_OF_ADDABLE>> ITERATOR_OF_ADDABLE2,
278 IEqualsComparer<KEY_TYPE> KEY_EQUALS_COMPARER = equal_to<KEY_TYPE>>
281 template <IInputIterator<T> ITERATOR_OF_ADDABLE, sentinel_for<remove_cvref_t<ITERATOR_OF_ADDABLE>> ITERATOR_OF_ADDABLE2,
282 IEqualsComparer<KEY_TYPE> KEY_EQUALS_COMPARER = equal_to<KEY_TYPE>>
285 template <IEqualsComparer<KEY_TYPE> KEY_EQUALS_COMPARER, IInputIterator<T> ITERATOR_OF_ADDABLE, sentinel_for<remove_cvref_t<ITERATOR_OF_ADDABLE>> ITERATOR_OF_ADDABLE2>
290 explicit KeyedCollection (shared_ptr<_IRep>&& rep)
noexcept;
291 explicit KeyedCollection (
const shared_ptr<_IRep>& rep)
noexcept;
296 nonvirtual KeyedCollection& operator= (KeyedCollection&&) =
default;
297 nonvirtual KeyedCollection& operator= (
const KeyedCollection&) =
default;
359 template <
typename THROW_IF_MISSING>
396 template <IInputIterator<T> ITERATOR_OF_ADDABLE, sentinel_for<remove_cvref_t<ITERATOR_OF_ADDABLE>> ITERATOR_OF_ADDABLE2>
398 template <IIterableOfTo<T> ITERABLE_OF_ADDABLE>
448 template <IInputIterator<T> ITERATOR_OF_ADDABLE>
450 template <IIterableOfTo<T> ITERABLE_OF_ADDABLE>
453 template <predicate<T> PREDICATE>
460 template <
typename RESULT_CONTAINER = KeyedCollection<T, KEY_TYPE, TRAITS>, invocable<T> ELEMENT_MAPPER>
473 template <derived_from<Iterable<T>> RESULT_CONTAINER = KeyedCollection<T, KEY_TYPE, TRAITS>, predicate<T> INCLUDE_PREDICATE>
514 nonvirtual
void clear ();
543 template <
typename T2>
549 template <
typename T2>
550 using _SafeReadWriteRepAccessor =
typename inherited::template _SafeReadWriteRepAccessor<T2>;
553 nonvirtual
void _AssertRepValidType ()
const;
562 template <
typename T,
typename KEY_TYPE,
typename TRAITS>
571 virtual shared_ptr<_IRep> CloneEmpty ()
const = 0;
587 template <
typename T,
typename KEY_TYPE,
typename TRAITS>
603#include "KeyedCollection.inl"
Implementation detail for KeyedCollection<KEY_TYPE, T, TRAITS> implementors.
a cross between Mapping<KEY, T> and Collection<T> and Set<T>
nonvirtual KeyedCollection & operator+=(ArgByValueType< value_type > item)
nonvirtual bool operator==(const KeyedCollection &rhs) const
nonvirtual value_type LookupValue(ArgByValueType< KeyType > key, ArgByValueType< value_type > defaultValue=value_type{}) const
nonvirtual void erase(ArgByValueType< value_type > item)
typename inherited::value_type value_type
nonvirtual bool Add(ArgByValueType< value_type > item)
nonvirtual KeyedCollection & operator-=(ArgByValueType< value_type > item)
nonvirtual bool Contains(ArgByValueType< KeyType > item) const
nonvirtual KeyExtractorType GetKeyExtractor() const
nonvirtual bool RemoveIf(ArgByValueType< KeyType > item)
nonvirtual RESULT_CONTAINER Where(INCLUDE_PREDICATE &&includeIfTrue) const
nonvirtual size_t RemoveAll(ITERATOR_OF_ADDABLE &&start, ITERATOR_OF_ADDABLE &&end)
RemoveAll removes all, or all matching (predicate, iterator range, equals comparer or whatever) items...
nonvirtual KeyEqualityComparerType GetKeyEqualityComparer() const
typename TRAITS::KeyExtractorType KeyExtractorType
nonvirtual void Remove(const Iterator< value_type > &i, const Iterator< value_type > *nextI=nullptr)
Remove the argument value (which must exist) from the KeyedCollection.
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 unsigned int AddAll(ITERATOR_OF_ADDABLE &&start, ITERATOR_OF_ADDABLE2 &&end)
nonvirtual optional< value_type > Lookup(ArgByValueType< KeyType > key) const
Common::ComparisonRelationDeclaration< Common::ComparisonRelationType::eEquals, function< bool(ArgByValueType< KEY_TYPE >, ArgByValueType< KEY_TYPE >)> > KeyEqualityComparerType
nonvirtual RESULT_CONTAINER Map(ELEMENT_MAPPER &&elementMapper) const
'override' Iterable<>::Map () function so RESULT_CONTAINER defaults to KeyedCollection,...
nonvirtual value_type LookupChecked(ArgByValueType< KeyType > key, THROW_IF_MISSING &&throwIfMissing) const
nonvirtual Iterable< KeyType > Keys() const
Implementation detail for iterator implementors.
Iterable<T> is a base class for containers which easily produce an Iterator<T> to traverse them.
nonvirtual CONTAINER_OF_T As(CONTAINER_OF_T_CONSTRUCTOR_ARGS... args) const
T value_type
value_type is an alias for the type iterated over - like vector<T>::value_type
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....
conditional_t<(sizeof(CHECK_T)<=2 *sizeof(void *)) and is_trivially_copyable_v< CHECK_T >, CHECK_T, const CHECK_T & > ArgByValueType
This is an alias for 'T' - but how we want to pass it on stack as formal parameter.
KEY_EXTRACTOR_TYPE KeyExtractorType