Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
SortedKeyedCollection_stdset.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4
5// Moved #includes outside #include guard to avoid deadly embrace
6#include "Stroika/Foundation/StroikaPreComp.h"
7
8#include <set>
9
11
12#ifndef _Stroika_Foundation_Containers_Concrete_SortedKeyedCollection_stdset_h_
13#define _Stroika_Foundation_Containers_Concrete_SortedKeyedCollection_stdset_h_
14
15/**
16 * \file
17 *
18 * \note Code-Status: <a href="Code-Status.md#Beta">Beta</a>
19 *
20 */
22
23 using Common::IInOrderComparer;
24
25 /**
26 * \brief SortedKeyedCollection_stdset<KEY_TYPE,MAPPED_VALUE_TYPE> is an std::map-based concrete implementation of the SortedKeyedCollection<KEY_TYPE,MAPPED_VALUE_TYPE> container pattern.
27 *
28 * \note Runtime performance/complexity:
29 * Very good low overhead implementation
30 *
31 * o size () is constant complexity
32 * o Uses Memory::BlockAllocatorOrStdAllocatorAsAppropriate
33 *
34 * \note \em Thread-Safety <a href="Thread-Safety.md#C++-Standard-Thread-Safety">C++-Standard-Thread-Safety</a>
35 */
36 template <typename T, typename KEY_TYPE, typename TRAITS = KeyedCollection_DefaultTraits<T, KEY_TYPE>>
37 class SortedKeyedCollection_stdset : public SortedKeyedCollection<T, KEY_TYPE, TRAITS> {
38 private:
40
41 public:
42 using TraitsType = typename inherited::TraitsType;
43 using KeyExtractorType = typename inherited::KeyExtractorType;
44 using KeyEqualityComparerType = typename inherited::KeyEqualityComparerType;
45 using KeyThreeWayComparerType = typename inherited::KeyThreeWayComparerType;
46 using KeyType = typename inherited::KeyType;
47 using key_type = typename inherited::key_type;
48 using value_type = typename inherited::value_type;
49
50 public:
51 /**
52 * \brief SetInOrderComparer is the COMPARER passed to the STL set. It intrinsically uses the provided extractor and key comparer
53 */
54 template <IInOrderComparer<KEY_TYPE> KEY_INORDER_COMPARER = less<key_type>>
56 static_assert (not is_reference_v<KEY_INORDER_COMPARER>);
57 SetInOrderComparer () = delete;
58 SetInOrderComparer (const KeyExtractorType& keyExtractor, const KEY_INORDER_COMPARER& inorderComparer)
59 : fKeyExtractor_{keyExtractor}
60 , fKeyComparer_{inorderComparer}
61 {
62 }
63 int operator() (const value_type& lhs, const KEY_TYPE& rhs) const
64 {
65 return fKeyComparer_ (fKeyExtractor_ (lhs), rhs);
66 };
67 int operator() (const KEY_TYPE& lhs, const value_type& rhs) const
68 {
69 return fKeyComparer_ (lhs, fKeyExtractor_ (rhs));
70 };
71 int operator() (const value_type& lhs, const value_type& rhs) const
72 {
73 return fKeyComparer_ (fKeyExtractor_ (lhs), fKeyExtractor_ (rhs));
74 };
75 [[no_unique_address]] const KeyExtractorType fKeyExtractor_;
76 [[no_unique_address]] const KEY_INORDER_COMPARER fKeyComparer_;
77 using is_transparent = int; // see https://en.cppreference.com/w/cpp/container/set/find - allows overloads to lookup by key
78 };
79
80 public:
81 /**
82 * \brief STDSET is std::set<> that can be used inside KeyedCollection_stdset
83 */
84 template <IInOrderComparer<KEY_TYPE> KEY_INORDER_COMPARER = less<key_type>>
85 using STDSET =
86 set<value_type, SetInOrderComparer<KEY_INORDER_COMPARER>, Memory::BlockAllocatorOrStdAllocatorAsAppropriate<value_type, sizeof (value_type) <= 1024>>;
87
88 public:
89 template <IInOrderComparer<KEY_TYPE> KEY_INORDER_COMPARER = less<KEY_TYPE>>
90 SortedKeyedCollection_stdset (KEY_INORDER_COMPARER&& keyComparer = KEY_INORDER_COMPARER{})
94 template <IInOrderComparer<KEY_TYPE> KEY_INORDER_COMPARER = less<KEY_TYPE>>
95 SortedKeyedCollection_stdset (const KeyExtractorType& keyExtractor, KEY_INORDER_COMPARER&& keyComparer = KEY_INORDER_COMPARER{});
96 template <IIterableOfTo<T> ITERABLE_OF_ADDABLE, IInOrderComparer<KEY_TYPE> KEY_INORDER_COMPARER = equal_to<KEY_TYPE>>
98 not derived_from<remove_cvref_t<ITERABLE_OF_ADDABLE>, SortedKeyedCollection_stdset<T, KEY_TYPE, TRAITS>>)
99 SortedKeyedCollection_stdset (ITERABLE_OF_ADDABLE&& src)
100#if qCompilerAndStdLib_RequiresNotMatchInlineOutOfLineForTemplateClassBeingDefined_Buggy
101 : SortedKeyedCollection_stdset{KeyExtractorType{}, KEY_INORDER_COMPARER{}}
102 {
103 this->AddAll (src);
104 AssertRepValidType_ ();
105 }
106#endif
107 ;
108 template <IIterableOfTo<T> ITERABLE_OF_ADDABLE, IInOrderComparer<KEY_TYPE> KEY_INORDER_COMPARER = less<KEY_TYPE>>
109 SortedKeyedCollection_stdset (KEY_INORDER_COMPARER&& keyComparer, ITERABLE_OF_ADDABLE&& src)
110 requires (IKeyedCollection_ExtractorCanBeDefaulted<T, KEY_TYPE, TRAITS>);
111 template <IInOrderComparer<KEY_TYPE> KEY_INORDER_COMPARER, IIterableOfTo<T> ITERABLE_OF_ADDABLE>
112 SortedKeyedCollection_stdset (const KeyExtractorType& keyExtractor, KEY_INORDER_COMPARER&& keyComparer, ITERABLE_OF_ADDABLE&& src);
113 template <IInputIterator<T> ITERATOR_OF_ADDABLE, IInOrderComparer<KEY_TYPE> KEY_INORDER_COMPARER = less<KEY_TYPE>>
114 SortedKeyedCollection_stdset (ITERATOR_OF_ADDABLE&& start, ITERATOR_OF_ADDABLE&& end)
115 requires (IKeyedCollection_ExtractorCanBeDefaulted<T, KEY_TYPE, TRAITS>);
116 template <IInputIterator<T> ITERATOR_OF_ADDABLE, IInOrderComparer<KEY_TYPE> KEY_INORDER_COMPARER = less<KEY_TYPE>>
117 SortedKeyedCollection_stdset (KEY_INORDER_COMPARER&& keyComparer, ITERATOR_OF_ADDABLE&& start, ITERATOR_OF_ADDABLE&& end)
118 requires (IKeyedCollection_ExtractorCanBeDefaulted<T, KEY_TYPE, TRAITS>);
119 template <IInOrderComparer<KEY_TYPE> KEY_INORDER_COMPARER, IInputIterator<T> ITERATOR_OF_ADDABLE>
120 SortedKeyedCollection_stdset (const KeyExtractorType& keyExtractor, KEY_INORDER_COMPARER&& keyComparer, ITERATOR_OF_ADDABLE&& start,
121 ITERATOR_OF_ADDABLE&& end);
122
123 public:
124 /**
125 */
126 nonvirtual SortedKeyedCollection_stdset& operator= (SortedKeyedCollection_stdset&&) noexcept = default;
127 nonvirtual SortedKeyedCollection_stdset& operator= (const SortedKeyedCollection_stdset&) = default;
128
129 private:
130 using IImplRepBase_ = typename SortedKeyedCollection<T, KEY_TYPE, TRAITS>::_IRep;
131 template <qCompilerAndStdLib_ConstraintDiffersInTemplateRedeclaration_BWA (IInOrderComparer<KEY_TYPE>) KEY_INORDER_COMPARER>
132 class Rep_;
133
134 private:
135 nonvirtual void AssertRepValidType_ () const;
136 };
137
138}
139
140/*
141 ********************************************************************************
142 ******************************* Implementation Details *************************
143 ********************************************************************************
144 */
145#include "SortedKeyedCollection_stdset.inl"
146
147#endif /*_Stroika_Foundation_Containers_Concrete_SortedKeyedCollection_stdset_h_ */
conditional_t< qStroika_Foundation_Memory_PreferBlockAllocation and andTrueCheck, BlockAllocator< T >, std::allocator< T > > BlockAllocatorOrStdAllocatorAsAppropriate
for type T, either use BlockAllocator<T>, or std::allocator
SortedKeyedCollection_stdset<KEY_TYPE,MAPPED_VALUE_TYPE> is an std::map-based concrete implementation...
set< value_type, SetInOrderComparer< KEY_INORDER_COMPARER >, Memory::BlockAllocatorOrStdAllocatorAsAppropriate< value_type, sizeof(value_type)<=1024 > > STDSET
STDSET is std::set<> that can be used inside KeyedCollection_stdset.
nonvirtual unsigned int AddAll(ITERATOR_OF_ADDABLE &&start, ITERATOR_OF_ADDABLE2 &&end)
A SortedKeyedCollection is a KeyedCollection<T> which remains sorted (iteration produces items sorted...
static constexpr default_sentinel_t end() noexcept
Support for ranged for, and STL syntax in general.
SetInOrderComparer is the COMPARER passed to the STL set. It intrinsically uses the provided extracto...