6 #include <initializer_list>
16 template<
typename _Key>
17 class vs_stack_strategy;
25 template<
typename _Key,
typename _Strategy = vs_stack_strategy<_Key>>
30 "Provided invalid strategy class in template");
50 : _v_s(std::stack<_Key>()) { }
61 : _v_s(std::stack<_Key>())
64 [&](std::stack<_Key>& _stack){
78 : _v_s(__vs_stack._v_s.Get()) { }
94 {
return _v_s.Get().top(); }
101 {
return _v_s.Get().size(); }
112 _v_s.Set(_v_s.Get(), [&](std::stack<_Key>& _stack){ _stack.push(__x); return true; });
121 if (_v_s.Get().size() > 0)
122 _v_s.Set(_v_s.Get(), [](std::stack<_Key>& _stack){ _stack.pop(); return true; });
135 template<
typename _Key>
141 merge(std::stack<_Key>& dst, std::stack<_Key>& src)
143 while (src.size() > 0)
158 template<
typename _Key>
161 std::stack<_Key> reversedStack;
163 while (temp.
size() != 0) {
164 reversedStack.
push(temp.
top());
168 std::ostringstream o;
170 while (reversedStack.size() != 0) {
171 o << reversedStack.top();
173 if (reversedStack.size() != 0) {
Wrapper to make any class Versioned.
const T & Get() const
Get the current value of the object in the current Revision.
bool Set(const T &v, const std::function< bool(T &)> &updater=nullptr)
Set new value of the object.
simpliest determenistic merge strategy.
void merge_same_element(std::stack< _Key > &dst, _Key &dstk, _Key &srck)
void merge(std::stack< _Key > &dst, std::stack< _Key > &src)
A versioned mimic of a stl::stack, suitable for multithread.
vs_stack(std::initializer_list< _Key > __l)
Builds a vs_stack from an initializer_list.
void pop()
Remove first element of stack.
const _Key & top() const
access top element
vs_stack(const vs_stack &__vs_stack)
vs_stack copy constructor
vs_stack()
Creates a vs_stack with no elements.
std::stack< _Key >::size_type size_type
void push(const _Key &__x)
Attempts to push an element into the stack.
Versioned< std::stack< _Key >, _Strategy > _Versioned
size_type size() const noexcept
size of underlying stack
concept IsMergeStrategy
Concept for compile-time type checking passed user strategies.
std::ostream & operator<<(std::ostream &os, vs_stack< _Key > const &value)
Implementation of the class Revision.
Implementation of the Versioned classes and interface.