mCRL2
Loading...
Searching...
No Matches
stack.h
Go to the documentation of this file.
1// Author(s): Jan Friso Groote, Maurice Laveaux
2// Copyright: see the accompanying file COPYING or copy at
3// https://github.com/mCRL2org/mCRL2/blob/master/COPYING
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
9//
17
18#ifndef MCRL2_ATERMPP_STANDARD_CONTAINER_STACK_H
19#define MCRL2_ATERMPP_STANDARD_CONTAINER_STACK_H
20
25
27namespace atermpp
28{
29
31template < class T,
32 class Container = atermpp::deque< T > >
33class stack
34{
35private:
36 Container m_container;
37
38public:
39
41 typedef typename Container::allocator_type allocator_type;
42 typedef typename Container::value_type value_type;
43 typedef typename Container::size_type size_type;
44 typedef typename Container::reference reference;
45 typedef typename Container::const_reference const_reference;
46 typedef typename Container::iterator iterator;
47 typedef typename Container::const_iterator const_iterator;
48
50 explicit stack(const Container& cont = Container())
51 : m_container(cont)
52 {}
53
55 explicit stack( Container&& cont )
56 : m_container(cont)
57 {}
58
59 stack(const stack& other) = default;
60 stack(stack&& other) = default;
61
63 template< class InputIt >
64 stack( InputIt first, InputIt last )
65 : m_container(first, last)
66 {}
67
69 template <class InputIterator>
70 stack(InputIterator first, InputIterator last,
71 const allocator_type& alloc = allocator_type())
72 : m_container(first, last, alloc)
73 {}
74
75 template< class Alloc >
76 explicit stack( const Alloc& alloc )
77 : m_container(alloc)
78 {}
79
80 template< class Alloc >
81 stack( const Container& cont, const Alloc& alloc )
82 : m_container(cont, alloc)
83 {}
84
85 template< class Alloc >
86 stack( Container&& cont, const Alloc& alloc )
87 : m_container(cont, alloc)
88 {}
89
90 template< class Alloc >
91 stack( const stack& other, const Alloc& alloc)
92 : m_container(other.m_container, alloc)
93 {}
94
95 template< class Alloc >
96 stack( stack&& other, const Alloc& alloc)
97 : m_container(std::move(other.m_container), alloc)
98 {}
99
100 template< class InputIt, class Alloc >
101 stack( InputIt first, InputIt last, const Alloc& alloc )
102 : m_container(first, last, alloc)
103 {}
104
106 stack& operator=(const stack& other) = default;
107
109 stack& operator=(stack&& other) = default;
110
112 ~stack()=default;
113
115 {
116 return m_container.back();
117 }
118
120 {
121 return m_container.back();
122 }
123
124 bool empty() const
125 {
126 return m_container.empty();
127 }
128
130 {
131 return m_container.size();
132 }
133
134 void push( const value_type& value )
135 {
136 m_container.push_back(value);
137 }
138
139 void push( value_type&& value )
140 {
141 m_container.push_back(std::move(value));
142 }
143
144 template< class... Args >
145 void emplace( Args&&... args )
146 {
147 m_container.emplace_back(std::forward<Args>(args)...);
148 }
149
150 void pop()
151 {
152 m_container.pop_back();
153 }
154
155 void swap( stack& other ) noexcept
156 {
157 using std::swap; swap(m_container, other.m_container);
158 }
159
160 void mark(std::stack<std::reference_wrapper<detail::_aterm>>& todo) const
161 {
162 m_container.mark(todo);
163 }
164};
165
166} // namespace atermpp
167#endif // MCRL2_ATERMPP_STANDARD_CONTAINER_STACK_H
A deque class in which aterms can be stored.
Definition deque.h:34
A deque class in which aterms can be stored.
Definition stack.h:34
stack & operator=(stack &&other)=default
Move assignment operator.
Container::size_type size_type
Definition stack.h:43
stack(InputIt first, InputIt last, const Alloc &alloc)
Definition stack.h:101
bool empty() const
Definition stack.h:124
stack(const stack &other)=default
stack(InputIt first, InputIt last)
Constructor.
Definition stack.h:64
size_type size() const
Definition stack.h:129
stack(Container &&cont)
Constructor.
Definition stack.h:55
stack(const Container &cont, const Alloc &alloc)
Definition stack.h:81
stack(stack &&other)=default
stack(Container &&cont, const Alloc &alloc)
Definition stack.h:86
Container::iterator iterator
Definition stack.h:46
const_reference top() const
Definition stack.h:119
stack(const Container &cont=Container())
Constructor.
Definition stack.h:50
Container::const_iterator const_iterator
Definition stack.h:47
void pop()
Definition stack.h:150
~stack()=default
Standard destructor.
Container::reference reference
Definition stack.h:44
Container::allocator_type allocator_type
Standard typedefs.
Definition stack.h:41
void push(const value_type &value)
Definition stack.h:134
void swap(stack &other) noexcept
Definition stack.h:155
Container::const_reference const_reference
Definition stack.h:45
stack(const Alloc &alloc)
Definition stack.h:76
stack & operator=(const stack &other)=default
Copy assignment operator.
void emplace(Args &&... args)
Definition stack.h:145
Container::value_type value_type
Definition stack.h:42
void mark(std::stack< std::reference_wrapper< detail::_aterm > > &todo) const
Definition stack.h:160
stack(const stack &other, const Alloc &alloc)
Definition stack.h:91
Container m_container
Definition stack.h:36
stack(stack &&other, const Alloc &alloc)
Definition stack.h:96
reference top()
Definition stack.h:114
stack(InputIterator first, InputIterator last, const allocator_type &alloc=allocator_type())
Constructor.
Definition stack.h:70
void push(value_type &&value)
Definition stack.h:139
The main namespace for the aterm++ library.
Definition algorithm.h:21
STL namespace.
void swap(atermpp::unprotected_aterm_core &t1, atermpp::unprotected_aterm_core &t2) noexcept
Swaps two aterms.
Definition aterm.h:462