4#ifndef _Stroika_Foundation_Containers_Association_h_
5#define _Stroika_Foundation_Containers_Association_h_ 1
7#include "Stroika/Foundation/StroikaPreComp.h"
9#include "Stroika/Foundation/Common/Common.h"
11#include "Stroika/Foundation/Common/Concepts.h"
12#include "Stroika/Foundation/Common/KeyValuePair.h"
13#include "Stroika/Foundation/Containers/Common.h"
49 using Common::IEqualsComparer;
50 using Common::KeyValuePair;
51 using Traversal::IInputIterator;
52 using Traversal::IIterableOfTo;
53 using Traversal::Iterable;
54 using Traversal::Iterator;
112 template <
typename KEY_TYPE,
typename MAPPED_VALUE_TYPE>
181 template <IEqualsComparer<KEY_TYPE> KEY_EQUALS_COMPARER>
193#if qCompilerAndStdLib_RequiresNotMatchInlineOutOfLineForTemplateClassBeingDefined_Buggy
197 _AssertRepValidType ();
201 template <IEqualsComparer<KEY_TYPE> KEY_EQUALS_COMPARER, IIterableOfTo<KeyValuePair<KEY_TYPE, MAPPED_VALUE_TYPE>> ITERABLE_OF_ADDABLE>
203 template <IInputIterator<KeyValuePair<KEY_TYPE, MAPPED_VALUE_TYPE>> ITERATOR_OF_ADDABLE, sentinel_for<remove_cvref_t<ITERATOR_OF_ADDABLE>> ITERATOR_OF_ADDABLE2>
206 template <IEqualsComparer<KEY_TYPE> KEY_EQUALS_COMPARER, IInputIterator<KeyValuePair<KEY_TYPE, MAPPED_VALUE_TYPE>> ITERATOR_OF_ADDABLE,
207 sentinel_for<remove_cvref_t<ITERATOR_OF_ADDABLE>> ITERATOR_OF_ADDABLE2>
211 explicit Association (shared_ptr<_IRep>&& rep)
noexcept;
212 explicit Association (
const shared_ptr<_IRep>& rep)
noexcept;
223 nonvirtual KeyEqualsCompareFunctionType GetKeyEqualsComparer ()
const;
348 template <Common::IEqualsComparer<MAPPED_VALUE_TYPE> VALUE_EQUALS_COMPARER = equal_to<MAPPED_VALUE_TYPE>>
370 template <IIterableOfTo<KeyValuePair<KEY_TYPE, MAPPED_VALUE_TYPE>> ITERABLE_OF_ADDABLE>
372 template <IInputIterator<KeyValuePair<KEY_TYPE, MAPPED_VALUE_TYPE>> ITERATOR_OF_ADDABLE, sentinel_for<remove_cvref_t<ITERATOR_OF_ADDABLE>> ITERATOR_OF_ADDABLE2>
408 template <
typename ITERABLE_OF_KEY_OR_ADDABLE>
410 template <
typename ITERATOR_OF_KEY_OR_ADDABLE, sentinel_for<remove_cvref_t<ITERATOR_OF_KEY_OR_ADDABLE>> ITERATOR_OF_KEY_OR_ADDABLE2>
412 template <predicate<KeyValuePair<KEY_TYPE, MAPPED_VALUE_TYPE>> PREDICATE>
449 template <IIterableOfTo<KEY_TYPE> ITERABLE_OF_KEY_TYPE>
456 template <
typename RESULT_CONTAINER = Association<KEY_TYPE, MAPPED_VALUE_TYPE>, invocable<KeyValuePair<KEY_TYPE, MAPPED_VALUE_TYPE>> ELEMENT_MAPPER>
477 template <derived_from<Iterable<KeyValuePair<KEY_TYPE, MAPPED_VALUE_TYPE>>> RESULT_CONTAINER = Association<KEY_TYPE, MAPPED_VALUE_TYPE>,
typename INCLUDE_PREDICATE>
498 template <
typename CONTAINER_OF_KEYS>
514 template <
typename CONTAINER_OF_Key_T>
533 template <qCompilerAndStdLib_Constra
intDiffersInTemplateRedeclaration_BWA (Common::IEqualsComparer<MAPPED_VALUE_TYPE>) VALUE_EQUALS_COMPARER = equal_to<MAPPED_VALUE_TYPE>>
569 nonvirtual
void clear ();
574 template <IIterableOfTo<KeyValuePair<KEY_TYPE, MAPPED_VALUE_TYPE>> ITERABLE_OF_ADDABLE>
580 template <IIterableOfTo<KeyValuePair<KEY_TYPE, MAPPED_VALUE_TYPE>> ITERABLE_OF_ADDABLE>
586 template <
typename ITERABLE_OF_KEY_OR_ADDABLE>
592 template <
typename T2>
598 template <
typename T2>
602 nonvirtual
void _AssertRepValidType ()
const;
611 template <
typename KEY_TYPE,
typename MAPPED_VALUE_TYPE>
620 virtual ~_IRep () =
default;
624 virtual shared_ptr<_IRep> CloneEmpty ()
const = 0;
649 template <
typename KEY_TYPE,
typename MAPPED_VALUE_TYPE>
650 template <qCompilerAndStdLib_Constra
intDiffersInTemplateRedeclaration_BWA (Common::IEqualsComparer<MAPPED_VALUE_TYPE>) VALUE_EQUALS_COMPARER>
665#include "Association.inl"
#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...
Implementation detail for Association<T> implementors.
An Association pairs key values with (possibly multiple or none) mapped_type values....
nonvirtual CONTAINER_OF_Key_T As() const
nonvirtual optional< mapped_type > LookupOne(ArgByValueType< key_type > key) const
Lookup and return the first (maybe arbitrarily chosen which is first) value with this key,...
nonvirtual bool RemoveIf(ArgByValueType< key_type > key)
Remove the given item, if it exists. Return true if found and removed.
nonvirtual void Remove(ArgByValueType< key_type > key)
Remove the given item (which must exist).
nonvirtual void clear()
STL-ish alias for RemoveAll ().
nonvirtual void Update(const Iterator< value_type > &i, ArgByValueType< mapped_type > newValue, Iterator< value_type > *nextI=nullptr)
MAPPED_VALUE_TYPE mapped_type
nonvirtual size_t OccurrencesOf(ArgByValueType< key_type > item) const
nonvirtual bool ContainsKey(ArgByValueType< key_type > key) const
nonvirtual void RetainAll(const ITERABLE_OF_KEY_TYPE &items)
nonvirtual void Add(ArgByValueType< key_type > key, ArgByValueType< mapped_type > newElt)
nonvirtual void erase(ArgByValueType< key_type > key)
STL-ish alias for Remove ().
nonvirtual RESULT_CONTAINER Where(INCLUDE_PREDICATE &&includeIfTrue) const
nonvirtual void AddAll(ITERABLE_OF_ADDABLE &&items)
nonvirtual Traversal::Iterable< mapped_type > Lookup(ArgByValueType< key_type > key) const
Return an Iterable<mapped_type> of all the associated items (can be empty if none)....
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 Iterable< key_type > Keys() const
nonvirtual void Accumulate(ArgByValueType< key_type > key, ArgByValueType< mapped_type > newValue, const function< mapped_type(ArgByValueType< mapped_type >, ArgByValueType< mapped_type >)> &f=[](ArgByValueType< mapped_type > l, ArgByValueType< mapped_type > r) -> mapped_type { return l+r;}, mapped_type initialValue={})
like Add (key, newValue) - BUT newValue is COMBINED with the 'f' argument.
nonvirtual mapped_type LookupOneChecked(ArgByValueType< key_type > key, const THROW_IF_MISSING &throwIfMissing) const
Lookup and return the first (maybe arbitrarily chosen which is first) value with this key,...
typename inherited::value_type value_type
nonvirtual bool operator==(const Association &rhs) const
nonvirtual RESULT_CONTAINER Map(ELEMENT_MAPPER &&elementMapper) const
'override' Iterable<>::Map () function so RESULT_CONTAINER defaults to Association,...
nonvirtual mapped_type LookupOneValue(ArgByValueType< key_type > key, ArgByValueType< mapped_type > defaultValue=mapped_type{}) const
Lookup and return the first (maybe arbitrarily chosen which is first) value with this key,...
nonvirtual const Iterable< mapped_type > operator[](ArgByValueType< key_type > key) const
Shortcut for Lookup.
nonvirtual ArchetypeContainerType WithKeys(const CONTAINER_OF_KEYS &includeKeys) const
nonvirtual bool ContainsMappedValue(ArgByValueType< mapped_type > v, const VALUE_EQUALS_COMPARER &valueEqualsComparer={}) const
nonvirtual Iterable< mapped_type > MappedValues() const
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.
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.
Compare Associations<>s for equality.