| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- | 
|  | 2 | //===---------------------------- stack -----------------------------------===// | 
|  | 3 | // | 
| Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | //                     The LLVM Compiler Infrastructure | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // | 
|  | 6 | // This file is distributed under the University of Illinois Open Source | 
|  | 7 | // License. See LICENSE.TXT for details. | 
|  | 8 | // | 
|  | 9 | //===----------------------------------------------------------------------===// | 
|  | 10 |  | 
|  | 11 | #ifndef _LIBCPP_STACK | 
|  | 12 | #define _LIBCPP_STACK | 
|  | 13 |  | 
|  | 14 | /* | 
|  | 15 | stack synopsis | 
|  | 16 |  | 
|  | 17 | namespace std | 
|  | 18 | { | 
|  | 19 |  | 
|  | 20 | template <class T, class Container = deque<T>> | 
|  | 21 | class stack | 
|  | 22 | { | 
|  | 23 | public: | 
|  | 24 | typedef Container                                container_type; | 
|  | 25 | typedef typename container_type::value_type      value_type; | 
|  | 26 | typedef typename container_type::reference       reference; | 
|  | 27 | typedef typename container_type::const_reference const_reference; | 
|  | 28 | typedef typename container_type::size_type       size_type; | 
|  | 29 |  | 
|  | 30 | protected: | 
|  | 31 | container_type c; | 
|  | 32 |  | 
|  | 33 | public: | 
|  | 34 | explicit stack(); | 
|  | 35 | explicit stack(const container_type& c); | 
|  | 36 | explicit stack(container_type&& c); | 
|  | 37 | stack(stack&& s); | 
|  | 38 | stack& operator=(stack&& s); | 
|  | 39 | template <class Alloc> explicit stack(const Alloc& a); | 
|  | 40 | template <class Alloc> stack(const container_type& c, const Alloc& a); | 
|  | 41 | template <class Alloc> stack(container_type&& c, const Alloc& a); | 
|  | 42 | template <class Alloc> stack(stack&& c, const Alloc& a); | 
|  | 43 |  | 
|  | 44 | bool empty() const; | 
|  | 45 | size_type size() const; | 
|  | 46 | reference top(); | 
|  | 47 | const_reference top() const; | 
|  | 48 |  | 
|  | 49 | void push(const value_type& x); | 
|  | 50 | void push(value_type&& x); | 
|  | 51 | template <class... Args> void emplace(Args&&... args); | 
|  | 52 | void pop(); | 
|  | 53 |  | 
|  | 54 | void swap(stack& c); | 
|  | 55 | }; | 
|  | 56 |  | 
|  | 57 | template <class T, class Container> | 
|  | 58 | bool operator==(const stack<T, Container>& x, const stack<T, Container>& y); | 
|  | 59 | template <class T, class Container> | 
|  | 60 | bool operator< (const stack<T, Container>& x, const stack<T, Container>& y); | 
|  | 61 | template <class T, class Container> | 
|  | 62 | bool operator!=(const stack<T, Container>& x, const stack<T, Container>& y); | 
|  | 63 | template <class T, class Container> | 
|  | 64 | bool operator> (const stack<T, Container>& x, const stack<T, Container>& y); | 
|  | 65 | template <class T, class Container> | 
|  | 66 | bool operator>=(const stack<T, Container>& x, const stack<T, Container>& y); | 
|  | 67 | template <class T, class Container> | 
|  | 68 | bool operator<=(const stack<T, Container>& x, const stack<T, Container>& y); | 
|  | 69 |  | 
|  | 70 | template <class T, class Container> | 
|  | 71 | void swap(stack<T, Container>& x, stack<T, Container>& y); | 
|  | 72 |  | 
|  | 73 | }  // std | 
|  | 74 |  | 
|  | 75 | */ | 
|  | 76 |  | 
|  | 77 | #include <__config> | 
|  | 78 | #include <deque> | 
|  | 79 |  | 
|  | 80 | #pragma GCC system_header | 
|  | 81 |  | 
|  | 82 | _LIBCPP_BEGIN_NAMESPACE_STD | 
|  | 83 |  | 
|  | 84 | template <class _Tp, class _Container> class stack; | 
|  | 85 |  | 
|  | 86 | template <class _Tp, class _Container> | 
|  | 87 | bool | 
|  | 88 | operator==(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y); | 
|  | 89 |  | 
|  | 90 | template <class _Tp, class _Container> | 
|  | 91 | bool | 
|  | 92 | operator< (const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y); | 
|  | 93 |  | 
|  | 94 | template <class _Tp, class _Container = deque<_Tp> > | 
|  | 95 | class stack | 
|  | 96 | { | 
|  | 97 | public: | 
|  | 98 | typedef _Container                               container_type; | 
|  | 99 | typedef typename container_type::value_type      value_type; | 
|  | 100 | typedef typename container_type::reference       reference; | 
|  | 101 | typedef typename container_type::const_reference const_reference; | 
|  | 102 | typedef typename container_type::size_type       size_type; | 
|  | 103 |  | 
|  | 104 | protected: | 
|  | 105 | container_type c; | 
|  | 106 |  | 
|  | 107 | public: | 
|  | 108 | stack() : c() {} | 
|  | 109 | explicit stack(const container_type& __c) : c(__c) {} | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 110 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 111 | explicit stack(container_type&& __c) : c(_STD::move(__c)) {} | 
|  | 112 | stack(stack&& __s) : c(_STD::move(__s.c)) {} | 
|  | 113 | stack& operator=(stack&& __s) {c = _STD::move(__s.c); return *this;} | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 114 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 115 | template <class _Alloc> | 
|  | 116 | explicit stack(const _Alloc& __a, | 
|  | 117 | typename enable_if<uses_allocator<container_type, | 
|  | 118 | _Alloc>::value>::type* = 0) | 
|  | 119 | : c(__a) {} | 
|  | 120 | template <class _Alloc> | 
|  | 121 | stack(const container_type& __c, const _Alloc& __a, | 
|  | 122 | typename enable_if<uses_allocator<container_type, | 
|  | 123 | _Alloc>::value>::type* = 0) | 
|  | 124 | : c(__c, __a) {} | 
|  | 125 | template <class _Alloc> | 
|  | 126 | stack(const stack& __s, const _Alloc& __a, | 
|  | 127 | typename enable_if<uses_allocator<container_type, | 
|  | 128 | _Alloc>::value>::type* = 0) | 
|  | 129 | : c(__s.c, __a) {} | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 130 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 131 | template <class _Alloc> | 
|  | 132 | stack(container_type&& __c, const _Alloc& __a, | 
|  | 133 | typename enable_if<uses_allocator<container_type, | 
|  | 134 | _Alloc>::value>::type* = 0) | 
|  | 135 | : c(_STD::move(__c), __a) {} | 
|  | 136 | template <class _Alloc> | 
|  | 137 | stack(stack&& __s, const _Alloc& __a, | 
|  | 138 | typename enable_if<uses_allocator<container_type, | 
|  | 139 | _Alloc>::value>::type* = 0) | 
|  | 140 | : c(_STD::move(__s.c), __a) {} | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 141 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 142 |  | 
|  | 143 | bool empty()     const      {return c.empty();} | 
|  | 144 | size_type size() const      {return c.size();} | 
|  | 145 | reference top()             {return c.back();} | 
|  | 146 | const_reference top() const {return c.back();} | 
|  | 147 |  | 
|  | 148 | void push(const value_type& __v) {c.push_back(__v);} | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 149 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 150 | void push(value_type&& __v) {c.push_back(_STD::move(__v));} | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 151 | #ifndef _LIBCPP_HAS_NO_VARIADICS | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 152 | template <class... _Args> void emplace(_Args&&... __args) | 
|  | 153 | {c.emplace_back(_STD::forward<_Args>(__args)...);} | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 154 | #endif  // _LIBCPP_HAS_NO_VARIADICS | 
|  | 155 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 156 | void pop() {c.pop_back();} | 
|  | 157 |  | 
|  | 158 | void swap(stack& __s) | 
|  | 159 | { | 
|  | 160 | using _STD::swap; | 
|  | 161 | swap(c, __s.c); | 
|  | 162 | } | 
|  | 163 |  | 
|  | 164 | template <class T1, class _C1> | 
|  | 165 | friend | 
|  | 166 | bool | 
|  | 167 | operator==(const stack<T1, _C1>& __x, const stack<T1, _C1>& __y); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 168 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 169 | template <class T1, class _C1> | 
|  | 170 | friend | 
|  | 171 | bool | 
|  | 172 | operator< (const stack<T1, _C1>& __x, const stack<T1, _C1>& __y); | 
|  | 173 | }; | 
|  | 174 |  | 
|  | 175 | template <class _Tp, class _Container> | 
|  | 176 | inline | 
|  | 177 | bool | 
|  | 178 | operator==(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) | 
|  | 179 | { | 
|  | 180 | return __x.c == __y.c; | 
|  | 181 | } | 
|  | 182 |  | 
|  | 183 | template <class _Tp, class _Container> | 
|  | 184 | inline | 
|  | 185 | bool | 
|  | 186 | operator< (const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) | 
|  | 187 | { | 
|  | 188 | return __x.c < __y.c; | 
|  | 189 | } | 
|  | 190 |  | 
|  | 191 | template <class _Tp, class _Container> | 
|  | 192 | inline | 
|  | 193 | bool | 
|  | 194 | operator!=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) | 
|  | 195 | { | 
|  | 196 | return !(__x == __y); | 
|  | 197 | } | 
|  | 198 |  | 
|  | 199 | template <class _Tp, class _Container> | 
|  | 200 | inline | 
|  | 201 | bool | 
|  | 202 | operator> (const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) | 
|  | 203 | { | 
|  | 204 | return __y < __x; | 
|  | 205 | } | 
|  | 206 |  | 
|  | 207 | template <class _Tp, class _Container> | 
|  | 208 | inline | 
|  | 209 | bool | 
|  | 210 | operator>=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) | 
|  | 211 | { | 
|  | 212 | return !(__x < __y); | 
|  | 213 | } | 
|  | 214 |  | 
|  | 215 | template <class _Tp, class _Container> | 
|  | 216 | inline | 
|  | 217 | bool | 
|  | 218 | operator<=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) | 
|  | 219 | { | 
|  | 220 | return !(__y < __x); | 
|  | 221 | } | 
|  | 222 |  | 
|  | 223 | template <class _Tp, class _Container> | 
|  | 224 | inline | 
|  | 225 | void | 
|  | 226 | swap(stack<_Tp, _Container>& __x, stack<_Tp, _Container>& __y) | 
|  | 227 | { | 
|  | 228 | __x.swap(__y); | 
|  | 229 | } | 
|  | 230 |  | 
|  | 231 | template <class _Tp, class _Container, class _Alloc> | 
|  | 232 | struct uses_allocator<stack<_Tp, _Container>, _Alloc> | 
|  | 233 | : public uses_allocator<_Container, _Alloc> | 
|  | 234 | { | 
|  | 235 | }; | 
|  | 236 |  | 
|  | 237 | _LIBCPP_END_NAMESPACE_STD | 
|  | 238 |  | 
|  | 239 | #endif  // _LIBCPP_STACK |