Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Stack.inl
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include <vector>
5
6#include "Stroika/Foundation/Common/Concepts.h"
8#include "Stroika/Foundation/Containers/Private/IterableUtils.h"
10
12
13 /*
14 ********************************************************************************
15 ************************************* Stack<T> *********************************
16 ********************************************************************************
17 */
18 template <typename T>
20 : inherited{Factory::Stack_Factory<T>::Default () ()}
21 {
22 _AssertRepValidType ();
23 }
24#if qCompilerAndStdLib_RequiresNotMatchInlineOutOfLineForTemplateClassBeingDefined_Buggy
25 template <typename T>
26 template <typename ITERABLE_OF_ADDABLE, enable_if_t<IIterableOfTo<ITERABLE_OF_ADDABLE, T> and not derived_from<remove_cvref_t<ITERABLE_OF_ADDABLE>, Stack<T>>>*>
27 inline Stack<T>::Stack (ITERABLE_OF_ADDABLE&& src)
28 : Stack{begin (src), end (src)}
29 {
30 }
31#else
32 template <typename T>
33 template <IIterableOfTo<T> ITERABLE_OF_ADDABLE>
34 inline Stack<T>::Stack (ITERABLE_OF_ADDABLE&& src)
35 requires (not derived_from<remove_cvref_t<ITERABLE_OF_ADDABLE>, Stack<T>>)
36 : Stack{begin (src), end (src)}
37 {
38 }
39#endif
40 template <typename T>
41 inline Stack<T>::Stack (const shared_ptr<_IRep>& src) noexcept
42 : inherited{(RequireExpression (src != nullptr), src)}
43 {
44 _AssertRepValidType ();
45 }
46 template <typename T>
47 inline Stack<T>::Stack (shared_ptr<_IRep>&& src) noexcept
48 : inherited{(RequireExpression (src != nullptr), move (src))}
49 {
50 _AssertRepValidType ();
51 }
52 template <typename T>
53 template <IInputIterator<T> ITERATOR_OF_ADDABLE>
54 inline Stack<T>::Stack (ITERATOR_OF_ADDABLE&& start, ITERATOR_OF_ADDABLE&& end)
55 : inherited{Factory::Stack_Factory<T>::Default () (forward<ITERATOR_OF_ADDABLE> (start), forward<ITERATOR_OF_ADDABLE> (end))}
56 {
57 }
58 template <typename T>
59 inline void Stack<T>::Push (ArgByValueType<value_type> item)
60 {
61 _SafeReadWriteRepAccessor<_IRep>{this}._GetWriteableRep ().Push (item);
62 }
63 template <typename T>
64 inline auto Stack<T>::Pop () -> value_type
65 {
66 return _SafeReadWriteRepAccessor<_IRep>{this}._GetWriteableRep ().Pop ();
67 }
68 template <typename T>
69 inline auto Stack<T>::Top () const -> value_type
70 {
71 return _SafeReadRepAccessor<_IRep>{this}._ConstGetRep ().Top ();
72 }
73 template <typename T>
74 inline void Stack<T>::RemoveAll ()
75 {
76 _SafeReadRepAccessor<_IRep> tmp{this}; // important to use READ not WRITE accessor, because write accessor would have already cloned the data
77 if (not tmp._ConstGetRep ().empty ()) {
78 this->_fRep = tmp._ConstGetRep ().CloneEmpty ();
79 }
80 }
81 template <typename T>
82 inline void Stack<T>::clear ()
83 {
84 RemoveAll ();
85 }
86 template <typename T>
87 inline void Stack<T>::_AssertRepValidType () const
88 {
90 _SafeReadRepAccessor<_IRep> ignored{this};
91 }
92 }
93 template <typename T>
94 inline bool Stack<T>::operator== (const Stack& rhs) const
95 requires (equality_comparable<T>)
96 {
97 return EqualsComparer<>{}(*this, rhs);
98 }
99 template <typename T>
100 inline auto Stack<T>::operator<=> (const Stack& rhs) const
101 requires (three_way_comparable<T>)
102 {
103 return ThreeWayComparer<>{}(*this, rhs);
104 }
105
106}
#define qStroika_Foundation_Debug_AssertionsChecked
The qStroika_Foundation_Debug_AssertionsChecked flag determines if assertions are checked and validat...
Definition Assertions.h:48
#define RequireExpression(c)
Definition Assertions.h:267
typename Iterable< T >::template SequentialEqualsComparer< T_EQUALS_COMPARER > EqualsComparer
simply indirect to @Iterable<T>::SequentialEqualsComparer
Definition Stack.h:154
nonvirtual bool operator==(const Stack &rhs) const
Definition Stack.inl:94
typename inherited::value_type value_type
Definition Stack.h:88
nonvirtual value_type Pop()
Definition Stack.inl:64
nonvirtual auto operator<=>(const Stack &rhs) const
Definition Stack.inl:100
nonvirtual void Push(ArgByValueType< value_type > item)
Definition Stack.inl:59
nonvirtual void clear()
STL-ish alias for RemoveAll ().
Definition Stack.inl:82
Iterable<T> is a base class for containers which easily produce an Iterator<T> to traverse them.
Definition Iterable.h:237