Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Sequence_Factory.inl
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
5
6namespace Stroika::Foundation::Containers::Factory {
7
8 /*
9 ********************************************************************************
10 **************************** Sequence_Factory<T> *******************************
11 ********************************************************************************
12 */
13 template <typename T>
14 constexpr Sequence_Factory<T>::Sequence_Factory (const FactoryFunctionType& f)
15 : fFactory_{f}
16 {
17 }
18 template <typename T>
20 : Sequence_Factory{AccessDefault_ ()}
21 {
22 }
23 template <typename T>
24 constexpr Sequence_Factory<T>::Sequence_Factory ([[maybe_unused]] const Hints& hints)
25 : Sequence_Factory{nullptr}
26 {
27 }
28 template <typename T>
30 {
31 return AccessDefault_ ();
32 }
33 template <typename T>
35 {
36 if (this->fFactory_ == nullptr) {
37 // Sequence_Array not always the best. Linked list can perform better for some uses,
38 // but not clear how best to characterize them in hints --LGP 2023-04-19
39 static const auto kDefault_ = Concrete::Sequence_Array<T>{}; // internal call to CloneEmpty if ever added to, but some sequences are empty, so why not share
40 return kDefault_;
41 }
42 else {
43 return this->fFactory_ ();
44 }
45 }
46 template <typename T>
47 void Sequence_Factory<T>::Register (const optional<Sequence_Factory>& f)
48 {
49 AccessDefault_ () = f.has_value () ? *f : Sequence_Factory{Hints{}};
50 }
51 template <typename T>
53 {
54 static Sequence_Factory sDefault_{Hints{}};
55 return sDefault_;
56 }
57
58}
Sequence_Array<T> is an Array-based concrete implementation of the Sequence<T> container pattern.
Singleton factory object - Used to create the default backend implementation of a Sequence<> containe...
static void Register(const optional< Sequence_Factory > &f=nullopt)
A generalization of a vector: a container whose elements are keyed by the natural numbers.
Definition Sequence.h:187