Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Stack_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 ******************************* Stack_Factory<T> *******************************
11 ********************************************************************************
12 */
13 template <typename T>
14 constexpr Stack_Factory<T>::Stack_Factory (const FactoryFunctionType& f)
15 : fFactory_{f}
16 {
17 }
18 template <typename T>
20 : Stack_Factory{AccessDefault_ ()}
21 {
22 }
23 template <typename T>
24 constexpr Stack_Factory<T>::Stack_Factory ([[maybe_unused]] const Hints& hints)
25 : Stack_Factory{nullptr}
26 {
27 }
28 template <typename T>
30 {
31 return AccessDefault_ ();
32 }
33 template <typename T>
35 {
36 if (this->fFactory_ == nullptr) [[likely]] {
37 static const auto kDefault_ = Concrete::Stack_LinkedList<T>{}; // some stacks remain empty, so why not share them...
38 return kDefault_;
39 }
40 else {
41 return this->fFactory_ ();
42 }
43 }
44 template <typename T>
45 template <typename IT>
46 auto Stack_Factory<T>::operator() (IT&& start, IT&& end) const -> ConstructedType
47 {
48 if (this->fFactory_ == nullptr) [[likely]] {
49 return Concrete::Stack_LinkedList<T>{forward<IT> (start), forward<IT> (end)};
50 }
51 else {
52 ConstructedType r = this->fFactory_ ();
53 vector<T> tmp;
54 copy (forward<IT> (start), forward<IT> (end), back_inserter (tmp));
55 for (auto ri = tmp.rbegin (); ri != tmp.rend (); ++ri) {
56 r.Push (*ri);
57 }
58 return r;
59 }
60 }
61 template <typename T>
62 void Stack_Factory<T>::Register (const optional<Stack_Factory>& f)
63 {
64 AccessDefault_ () = f.has_value () ? *f : Stack_Factory{Hints{}};
65 }
66 template <typename T>
68 {
69 static Stack_Factory sDefault_{Hints{}};
70 return sDefault_;
71 }
72
73}
Stack_LinkedList<T> is an LinkedList-based concrete implementation of the Stack<T> container pattern.
Singleton factory object - Used to create the default backend implementation of a Stack<> container; ...
static void Register(const optional< Stack_Factory > &f=nullopt)