forked from mutouyun/nixy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack.h
102 lines (82 loc) · 2.16 KB
/
stack.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
The Nixy Library
Code covered by the MIT License
Author: mutouyun (http://darkc.at)
*/
#pragma once
#include "nixycore/container/deque.h"
#include "nixycore/utility/rvalue.h"
#include "nixycore/general/general.h"
#include <stack> // std::stack
//////////////////////////////////////////////////////////////////////////
NX_BEG
//////////////////////////////////////////////////////////////////////////
#ifdef NX_SP_CXX11_ALIAS
template <typename T, typename SeqT = nx::deque<T> >
using stack = std::stack<T, SeqT>;
#else /*NX_SP_CXX11_ALIAS*/
template <typename T, typename SeqT = nx::deque<T> >
class stack : public std::stack<T, SeqT>
{
typedef std::stack<T, SeqT> base_t;
public:
#ifdef NX_SP_CXX11_INHERITING
using base_t::stack;
#else /*NX_SP_CXX11_INHERITING*/
explicit stack(const SeqT& s = SeqT())
: base_t(s)
{}
stack(const stack& rhs)
: base_t(rhs)
{}
#ifdef NX_SP_CXX11_STACK_SWAP
stack(nx_rref(stack, true) rhs)
: base_t()
{
base_t::swap(moved(rhs));
}
#endif
#endif/*NX_SP_CXX11_INHERITING*/
stack& operator=(stack rhs)
{
rhs.swap(*this);
return (*this);
}
};
/*
Special swap algorithm
*/
template <typename T, typename S>
inline void swap(stack<T, S>& x, stack<T, S>& y)
{
x.swap(y);
}
#endif/*NX_SP_CXX11_ALIAS*/
/*
Special assign algorithm
*/
template <typename T, typename S, typename V>
inline void insert(std::stack<T, S>& set, typename std::stack<T, S>::iterator /*ite*/, const V& val)
{
set.push(val);
}
template <typename T, typename S>
inline void erase(std::stack<T, S>& set, typename std::stack<T, S>::iterator /*ite*/)
{
set.pop();
}
#ifndef NX_SP_CXX11_ALIAS
template <typename T, typename S, typename V>
inline void insert(stack<T, S>& set, typename stack<T, S>::iterator /*ite*/, const V& val)
{
set.push(val);
}
template <typename T, typename S>
inline void erase(stack<T, S>& set, typename stack<T, S>::iterator /*ite*/)
{
set.pop();
}
#endif/*NX_SP_CXX11_ALIAS*/
//////////////////////////////////////////////////////////////////////////
NX_END
//////////////////////////////////////////////////////////////////////////