Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Set_Factory.inl
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
6
7namespace Stroika::Foundation::Containers::Factory {
8
9 /*
10 ********************************************************************************
11 ************************ Set_Factory<T, EQUALS_COMPARER> ***********************
12 ********************************************************************************
13 */
14 template <typename T, IEqualsComparer<T> EQUALS_COMPARER>
15 constexpr Set_Factory<T, EQUALS_COMPARER>::Set_Factory (const FactoryFunctionType& f)
16 : fFactory_{f}
17 {
18 }
19 template <typename T, IEqualsComparer<T> EQUALS_COMPARER>
21 : Set_Factory{AccessDefault_ ()}
22 {
23 }
24 template <typename T, IEqualsComparer<T> EQUALS_COMPARER>
25 constexpr Set_Factory<T, EQUALS_COMPARER>::Set_Factory ([[maybe_unused]] const Hints& hints)
26 : Set_Factory{nullptr}
27 {
28 }
29 template <typename T, IEqualsComparer<T> EQUALS_COMPARER>
31 {
32 return AccessDefault_ ();
33 }
34 template <typename T, IEqualsComparer<T> EQUALS_COMPARER>
35 inline auto Set_Factory<T, EQUALS_COMPARER>::operator() (const EQUALS_COMPARER& equalsComparer) const -> ConstructedType
36 {
37 if (this->fFactory_ == nullptr) [[likely]] {
38 if constexpr (same_as<EQUALS_COMPARER, equal_to<T>> and totally_ordered<T>) {
39 static const auto kDefault_ = Concrete::SortedSet_stdset<T>{};
40 return kDefault_;
41 }
42 else {
43 /*
44 * Not good for large sets, due to lack of indexing/quick lookup. So issue with realloc not such a biggie
45 * and probably better than linked list since better locality (and have to walk whole list anyhow to see if present).
46 */
47 return Concrete::Set_Array<T>{equalsComparer};
48 }
49 }
50 else {
51 return this->fFactory_ (equalsComparer);
52 }
53 }
54 template <typename T, IEqualsComparer<T> EQUALS_COMPARER>
55 void Set_Factory<T, EQUALS_COMPARER>::Register (const optional<Set_Factory>& f)
56 {
57 AccessDefault_ () = f.has_value () ? *f : Set_Factory{Hints{}};
58 }
59 template <typename T, IEqualsComparer<T> EQUALS_COMPARER>
61 {
62 static Set_Factory sDefault_{Hints{}};
63 return sDefault_;
64 }
65
66}
Set_Array<T> is an Array-based concrete implementation of the Set<T> container pattern.
Definition Set_Array.h:32
SortedSet_stdset<T> is an std::set-based concrete implementation of the SortedSet<T> container patter...
Singleton factory object - Used to create the default backend implementation of a Set<> container; ty...
Definition Set_Factory.h:28
nonvirtual ConstructedType operator()(const EQUALS_COMPARER &equalsComparer={}) const
static void Register(const optional< Set_Factory > &f=nullopt)
Set<T> is a container of T, where once an item is added, additionally adds () do nothing.
Definition Set.h:105