Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===--------------------------- queue ------------------------------------===// |
| 3 | // |
Howard Hinnant | c566dc3 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
Howard Hinnant | ee11c31 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP_QUEUE |
| 12 | #define _LIBCPP_QUEUE |
| 13 | |
| 14 | /* |
| 15 | queue synopsis |
| 16 | |
| 17 | namespace std |
| 18 | { |
| 19 | |
| 20 | template <class T, class Container = deque<T>> |
| 21 | class queue |
| 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 | queue(); |
| 35 | explicit queue(const container_type& c); |
| 36 | explicit queue(container_type&& c); |
| 37 | queue(queue&& q); |
| 38 | template <class Alloc> |
| 39 | explicit queue(const Alloc& a); |
| 40 | template <class Alloc> |
| 41 | queue(const container_type& c, const Alloc& a); |
| 42 | template <class Alloc> |
| 43 | queue(container_type&& c, const Alloc& a); |
| 44 | template <class Alloc> |
| 45 | queue(queue&& q, const Alloc& a); |
| 46 | |
| 47 | queue& operator=(queue&& q); |
| 48 | |
| 49 | bool empty() const; |
| 50 | size_type size() const; |
| 51 | |
| 52 | reference front(); |
| 53 | const_reference front() const; |
| 54 | reference back(); |
| 55 | const_reference back() const; |
| 56 | |
| 57 | void push(const value_type& v); |
| 58 | void push(value_type&& v); |
| 59 | template <class... Args> void emplace(Args&&... args); |
| 60 | void pop(); |
| 61 | |
| 62 | void swap(queue& q); |
| 63 | }; |
| 64 | |
| 65 | template <class T, class Container> |
| 66 | bool operator==(const queue<T, Container>& x,const queue<T, Container>& y); |
| 67 | |
| 68 | template <class T, class Container> |
| 69 | bool operator< (const queue<T, Container>& x,const queue<T, Container>& y); |
| 70 | |
| 71 | template <class T, class Container> |
| 72 | bool operator!=(const queue<T, Container>& x,const queue<T, Container>& y); |
| 73 | |
| 74 | template <class T, class Container> |
| 75 | bool operator> (const queue<T, Container>& x,const queue<T, Container>& y); |
| 76 | |
| 77 | template <class T, class Container> |
| 78 | bool operator>=(const queue<T, Container>& x,const queue<T, Container>& y); |
| 79 | |
| 80 | template <class T, class Container> |
| 81 | bool operator<=(const queue<T, Container>& x,const queue<T, Container>& y); |
| 82 | |
| 83 | template <class T, class Container> |
| 84 | void swap(queue<T, Container>& x, queue<T, Container>& y); |
| 85 | |
| 86 | template <class T, class Container = vector<T>, |
| 87 | class Compare = less<typename Container::value_type>> |
| 88 | class priority_queue |
| 89 | { |
| 90 | public: |
| 91 | typedef Container container_type; |
| 92 | typedef typename container_type::value_type value_type; |
| 93 | typedef typename container_type::reference reference; |
| 94 | typedef typename container_type::const_reference const_reference; |
| 95 | typedef typename container_type::size_type size_type; |
| 96 | |
| 97 | protected: |
| 98 | container_type c; |
| 99 | Compare comp; |
| 100 | |
| 101 | public: |
| 102 | explicit priority_queue(const Compare& comp = Compare()); |
| 103 | priority_queue(const Compare& comp, const container_type& c); |
| 104 | explicit priority_queue(const Compare& comp, container_type&& c); |
| 105 | template <class InputIterator> |
| 106 | priority_queue(InputIterator first, InputIterator last, |
| 107 | const Compare& comp = Compare()); |
| 108 | template <class InputIterator> |
| 109 | priority_queue(InputIterator first, InputIterator last, |
| 110 | const Compare& comp, const container_type& c); |
| 111 | template <class InputIterator> |
| 112 | priority_queue(InputIterator first, InputIterator last, |
| 113 | const Compare& comp, container_type&& c); |
| 114 | priority_queue(priority_queue&& q); |
| 115 | priority_queue& operator=(priority_queue&& q); |
| 116 | template <class Alloc> |
| 117 | explicit priority_queue(const Alloc& a); |
| 118 | template <class Alloc> |
| 119 | priority_queue(const Compare& comp, const Alloc& a); |
| 120 | template <class Alloc> |
| 121 | priority_queue(const Compare& comp, const container_type& c, |
| 122 | const Alloc& a); |
| 123 | template <class Alloc> |
| 124 | priority_queue(const Compare& comp, container_type&& c, |
| 125 | const Alloc& a); |
| 126 | template <class Alloc> |
| 127 | priority_queue(priority_queue&& q, const Alloc& a); |
| 128 | |
| 129 | bool empty() const; |
| 130 | size_type size() const; |
| 131 | const_reference top() const; |
| 132 | |
| 133 | void push(const value_type& v); |
| 134 | void push(value_type&& v); |
| 135 | template <class... Args> void emplace(Args&&... args); |
| 136 | void pop(); |
| 137 | |
| 138 | void swap(priority_queue& q); |
| 139 | }; |
| 140 | |
| 141 | template <class T, class Container, class Compare> |
| 142 | void swap(priority_queue<T, Container, Compare>& x, |
| 143 | priority_queue<T, Container, Compare>& y); |
| 144 | |
| 145 | } // std |
| 146 | |
| 147 | */ |
| 148 | |
| 149 | #include <__config> |
| 150 | #include <deque> |
| 151 | #include <vector> |
| 152 | #include <functional> |
| 153 | #include <algorithm> |
| 154 | |
| 155 | #pragma GCC system_header |
| 156 | |
| 157 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 158 | |
| 159 | template <class _Tp, class _Container> class queue; |
| 160 | |
| 161 | template <class _Tp, class _Container> |
| 162 | bool |
| 163 | operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y); |
| 164 | |
| 165 | template <class _Tp, class _Container> |
| 166 | bool |
| 167 | operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y); |
| 168 | |
| 169 | template <class _Tp, class _Container = deque<_Tp> > |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 170 | class _LIBCPP_VISIBLE queue |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 171 | { |
| 172 | public: |
| 173 | typedef _Container container_type; |
| 174 | typedef typename container_type::value_type value_type; |
| 175 | typedef typename container_type::reference reference; |
| 176 | typedef typename container_type::const_reference const_reference; |
| 177 | typedef typename container_type::size_type size_type; |
| 178 | |
| 179 | protected: |
| 180 | container_type c; |
| 181 | |
| 182 | public: |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 183 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 184 | queue() : c() {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 185 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 186 | explicit queue(const container_type& __c) : c(__c) {} |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 187 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 188 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 189 | explicit queue(container_type&& __c) : c(_STD::move(__c)) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 190 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 191 | queue(queue&& __q) : c(_STD::move(__q.c)) {} |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 192 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 193 | template <class _Alloc> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 194 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 195 | explicit queue(const _Alloc& __a, |
| 196 | typename enable_if<uses_allocator<container_type, |
| 197 | _Alloc>::value>::type* = 0) |
| 198 | : c(__a) {} |
| 199 | template <class _Alloc> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 200 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 201 | queue(const queue& __q, const _Alloc& __a, |
| 202 | typename enable_if<uses_allocator<container_type, |
| 203 | _Alloc>::value>::type* = 0) |
| 204 | : c(__q.c, __a) {} |
| 205 | template <class _Alloc> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 206 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 207 | queue(const container_type& __c, const _Alloc& __a, |
| 208 | typename enable_if<uses_allocator<container_type, |
| 209 | _Alloc>::value>::type* = 0) |
| 210 | : c(__c, __a) {} |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 211 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 212 | template <class _Alloc> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 213 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 214 | queue(container_type&& __c, const _Alloc& __a, |
| 215 | typename enable_if<uses_allocator<container_type, |
| 216 | _Alloc>::value>::type* = 0) |
| 217 | : c(_STD::move(__c), __a) {} |
| 218 | template <class _Alloc> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 219 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 220 | queue(queue&& __q, const _Alloc& __a, |
| 221 | typename enable_if<uses_allocator<container_type, |
| 222 | _Alloc>::value>::type* = 0) |
| 223 | : c(_STD::move(__q.c), __a) {} |
| 224 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 225 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 226 | queue& operator=(queue&& __q) |
| 227 | { |
| 228 | c = _STD::move(__q.c); |
| 229 | return *this; |
| 230 | } |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 231 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 232 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 233 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 234 | bool empty() const {return c.empty();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 235 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 236 | size_type size() const {return c.size();} |
| 237 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 238 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 239 | reference front() {return c.front();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 240 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 241 | const_reference front() const {return c.front();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 242 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 243 | reference back() {return c.back();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 244 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 245 | const_reference back() const {return c.back();} |
| 246 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 247 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 248 | void push(const value_type& __v) {c.push_back(__v);} |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 249 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 250 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 251 | void push(value_type&& __v) {c.push_back(_STD::move(__v));} |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 252 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 253 | template <class... _Args> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 254 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 255 | void emplace(_Args&&... __args) |
| 256 | {c.emplace_back(_STD::forward<_Args>(__args)...);} |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 257 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 258 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 259 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 260 | void pop() {c.pop_front();} |
| 261 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 262 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 263 | void swap(queue& __q) |
| 264 | { |
| 265 | using _STD::swap; |
| 266 | swap(c, __q.c); |
| 267 | } |
| 268 | |
| 269 | template <class _T1, class _C1> |
| 270 | friend |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 271 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 272 | bool |
| 273 | operator==(const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 274 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 275 | template <class _T1, class _C1> |
| 276 | friend |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 277 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 278 | bool |
| 279 | operator< (const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y); |
| 280 | }; |
| 281 | |
| 282 | template <class _Tp, class _Container> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 283 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 284 | bool |
| 285 | operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y) |
| 286 | { |
| 287 | return __x.c == __y.c; |
| 288 | } |
| 289 | |
| 290 | template <class _Tp, class _Container> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 291 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 292 | bool |
| 293 | operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y) |
| 294 | { |
| 295 | return __x.c < __y.c; |
| 296 | } |
| 297 | |
| 298 | template <class _Tp, class _Container> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 299 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 300 | bool |
| 301 | operator!=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y) |
| 302 | { |
| 303 | return !(__x == __y); |
| 304 | } |
| 305 | |
| 306 | template <class _Tp, class _Container> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 307 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 308 | bool |
| 309 | operator> (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y) |
| 310 | { |
| 311 | return __y < __x; |
| 312 | } |
| 313 | |
| 314 | template <class _Tp, class _Container> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 315 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 316 | bool |
| 317 | operator>=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y) |
| 318 | { |
| 319 | return !(__x < __y); |
| 320 | } |
| 321 | |
| 322 | template <class _Tp, class _Container> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 323 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 324 | bool |
| 325 | operator<=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y) |
| 326 | { |
| 327 | return !(__y < __x); |
| 328 | } |
| 329 | |
| 330 | template <class _Tp, class _Container> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 331 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 332 | void |
| 333 | swap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y) |
| 334 | { |
| 335 | __x.swap(__y); |
| 336 | } |
| 337 | |
| 338 | template <class _Tp, class _Container, class _Alloc> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 339 | struct _LIBCPP_VISIBLE uses_allocator<queue<_Tp, _Container>, _Alloc> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 340 | : public uses_allocator<_Container, _Alloc> |
| 341 | { |
| 342 | }; |
| 343 | |
| 344 | template <class _Tp, class _Container = vector<_Tp>, |
| 345 | class _Compare = less<typename _Container::value_type> > |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 346 | class _LIBCPP_VISIBLE priority_queue |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 347 | { |
| 348 | public: |
| 349 | typedef _Container container_type; |
| 350 | typedef _Compare value_compare; |
| 351 | typedef typename container_type::value_type value_type; |
| 352 | typedef typename container_type::reference reference; |
| 353 | typedef typename container_type::const_reference const_reference; |
| 354 | typedef typename container_type::size_type size_type; |
| 355 | |
| 356 | protected: |
| 357 | container_type c; |
| 358 | value_compare comp; |
| 359 | |
| 360 | public: |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 361 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 362 | explicit priority_queue(const value_compare& __comp = value_compare()) |
| 363 | : c(), comp(__comp) {} |
| 364 | priority_queue(const value_compare& __comp, const container_type& __c); |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 365 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 366 | explicit priority_queue(const value_compare& __comp, container_type&& __c); |
| 367 | #endif |
| 368 | template <class _InputIter> |
| 369 | priority_queue(_InputIter __f, _InputIter __l, |
| 370 | const value_compare& __comp = value_compare()); |
| 371 | template <class _InputIter> |
| 372 | priority_queue(_InputIter __f, _InputIter __l, |
| 373 | const value_compare& __comp, const container_type& __c); |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 374 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 375 | template <class _InputIter> |
| 376 | priority_queue(_InputIter __f, _InputIter __l, |
| 377 | const value_compare& __comp, container_type&& __c); |
| 378 | priority_queue(priority_queue&& __q); |
| 379 | priority_queue& operator=(priority_queue&& __q); |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 380 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 381 | template <class _Alloc> |
| 382 | explicit priority_queue(const _Alloc& __a, |
| 383 | typename enable_if<uses_allocator<container_type, |
| 384 | _Alloc>::value>::type* = 0); |
| 385 | template <class _Alloc> |
| 386 | priority_queue(const value_compare& __comp, const _Alloc& __a, |
| 387 | typename enable_if<uses_allocator<container_type, |
| 388 | _Alloc>::value>::type* = 0); |
| 389 | template <class _Alloc> |
| 390 | priority_queue(const value_compare& __comp, const container_type& __c, |
| 391 | const _Alloc& __a, |
| 392 | typename enable_if<uses_allocator<container_type, |
| 393 | _Alloc>::value>::type* = 0); |
| 394 | template <class _Alloc> |
| 395 | priority_queue(const priority_queue& __q, const _Alloc& __a, |
| 396 | typename enable_if<uses_allocator<container_type, |
| 397 | _Alloc>::value>::type* = 0); |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 398 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 399 | template <class _Alloc> |
| 400 | priority_queue(const value_compare& __comp, container_type&& __c, |
| 401 | const _Alloc& __a, |
| 402 | typename enable_if<uses_allocator<container_type, |
| 403 | _Alloc>::value>::type* = 0); |
| 404 | template <class _Alloc> |
| 405 | priority_queue(priority_queue&& __q, const _Alloc& __a, |
| 406 | typename enable_if<uses_allocator<container_type, |
| 407 | _Alloc>::value>::type* = 0); |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 408 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 409 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 410 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 411 | bool empty() const {return c.empty();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 412 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 413 | size_type size() const {return c.size();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 414 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 415 | const_reference top() const {return c.front();} |
| 416 | |
| 417 | void push(const value_type& __v); |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 418 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 419 | void push(value_type&& __v); |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 420 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 421 | template <class... _Args> void emplace(_Args&&... __args); |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 422 | #endif |
| 423 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 424 | void pop(); |
| 425 | |
| 426 | void swap(priority_queue& __q); |
| 427 | }; |
| 428 | |
| 429 | template <class _Tp, class _Container, class _Compare> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 430 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 431 | priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Compare& __comp, |
| 432 | const container_type& __c) |
| 433 | : c(__c), |
| 434 | comp(__comp) |
| 435 | { |
| 436 | _STD::make_heap(c.begin(), c.end(), comp); |
| 437 | } |
| 438 | |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 439 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 440 | |
| 441 | template <class _Tp, class _Container, class _Compare> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 442 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 443 | priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp, |
| 444 | container_type&& __c) |
| 445 | : c(_STD::move(__c)), |
| 446 | comp(__comp) |
| 447 | { |
| 448 | _STD::make_heap(c.begin(), c.end(), comp); |
| 449 | } |
| 450 | |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 451 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 452 | |
| 453 | template <class _Tp, class _Container, class _Compare> |
| 454 | template <class _InputIter> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 455 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 456 | priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l, |
| 457 | const value_compare& __comp) |
| 458 | : c(__f, __l), |
| 459 | comp(__comp) |
| 460 | { |
| 461 | _STD::make_heap(c.begin(), c.end(), comp); |
| 462 | } |
| 463 | |
| 464 | template <class _Tp, class _Container, class _Compare> |
| 465 | template <class _InputIter> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 466 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 467 | priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l, |
| 468 | const value_compare& __comp, |
| 469 | const container_type& __c) |
| 470 | : c(__c), |
| 471 | comp(__comp) |
| 472 | { |
| 473 | c.insert(c.end(), __f, __l); |
| 474 | _STD::make_heap(c.begin(), c.end(), comp); |
| 475 | } |
| 476 | |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 477 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 478 | |
| 479 | template <class _Tp, class _Container, class _Compare> |
| 480 | template <class _InputIter> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 481 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 482 | priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l, |
| 483 | const value_compare& __comp, |
| 484 | container_type&& __c) |
| 485 | : c(_STD::move(__c)), |
| 486 | comp(__comp) |
| 487 | { |
| 488 | c.insert(c.end(), __f, __l); |
| 489 | _STD::make_heap(c.begin(), c.end(), comp); |
| 490 | } |
| 491 | |
| 492 | template <class _Tp, class _Container, class _Compare> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 493 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 494 | priority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q) |
| 495 | : c(_STD::move(__q.c)), |
| 496 | comp(_STD::move(__q.comp)) |
| 497 | { |
| 498 | } |
| 499 | |
| 500 | template <class _Tp, class _Container, class _Compare> |
| 501 | priority_queue<_Tp, _Container, _Compare>& |
| 502 | priority_queue<_Tp, _Container, _Compare>::operator=(priority_queue&& __q) |
| 503 | { |
| 504 | c = _STD::move(__q.c); |
| 505 | comp = _STD::move(__q.comp); |
| 506 | return *this; |
| 507 | } |
| 508 | |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 509 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 510 | |
| 511 | template <class _Tp, class _Container, class _Compare> |
| 512 | template <class _Alloc> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 513 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 514 | priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Alloc& __a, |
| 515 | typename enable_if<uses_allocator<container_type, |
| 516 | _Alloc>::value>::type*) |
| 517 | : c(__a) |
| 518 | { |
| 519 | } |
| 520 | |
| 521 | template <class _Tp, class _Container, class _Compare> |
| 522 | template <class _Alloc> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 523 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 524 | priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp, |
| 525 | const _Alloc& __a, |
| 526 | typename enable_if<uses_allocator<container_type, |
| 527 | _Alloc>::value>::type*) |
| 528 | : c(__a), |
| 529 | comp(__comp) |
| 530 | { |
| 531 | } |
| 532 | |
| 533 | template <class _Tp, class _Container, class _Compare> |
| 534 | template <class _Alloc> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 535 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 536 | priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp, |
| 537 | const container_type& __c, |
| 538 | const _Alloc& __a, |
| 539 | typename enable_if<uses_allocator<container_type, |
| 540 | _Alloc>::value>::type*) |
| 541 | : c(__c, __a), |
| 542 | comp(__comp) |
| 543 | { |
| 544 | _STD::make_heap(c.begin(), c.end(), comp); |
| 545 | } |
| 546 | |
| 547 | template <class _Tp, class _Container, class _Compare> |
| 548 | template <class _Alloc> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 549 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 550 | priority_queue<_Tp, _Container, _Compare>::priority_queue(const priority_queue& __q, |
| 551 | const _Alloc& __a, |
| 552 | typename enable_if<uses_allocator<container_type, |
| 553 | _Alloc>::value>::type*) |
| 554 | : c(__q.c, __a), |
| 555 | comp(__q.comp) |
| 556 | { |
| 557 | _STD::make_heap(c.begin(), c.end(), comp); |
| 558 | } |
| 559 | |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 560 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 561 | |
| 562 | template <class _Tp, class _Container, class _Compare> |
| 563 | template <class _Alloc> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 564 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 565 | priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp, |
| 566 | container_type&& __c, |
| 567 | const _Alloc& __a, |
| 568 | typename enable_if<uses_allocator<container_type, |
| 569 | _Alloc>::value>::type*) |
| 570 | : c(_STD::move(__c), __a), |
| 571 | comp(__comp) |
| 572 | { |
| 573 | _STD::make_heap(c.begin(), c.end(), comp); |
| 574 | } |
| 575 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 576 | template <class _Tp, class _Container, class _Compare> |
| 577 | template <class _Alloc> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 578 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 579 | priority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q, |
| 580 | const _Alloc& __a, |
| 581 | typename enable_if<uses_allocator<container_type, |
| 582 | _Alloc>::value>::type*) |
| 583 | : c(_STD::move(__q.c), __a), |
| 584 | comp(_STD::move(__q.comp)) |
| 585 | { |
| 586 | _STD::make_heap(c.begin(), c.end(), comp); |
| 587 | } |
| 588 | |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 589 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 590 | |
| 591 | template <class _Tp, class _Container, class _Compare> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 592 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 593 | void |
| 594 | priority_queue<_Tp, _Container, _Compare>::push(const value_type& __v) |
| 595 | { |
| 596 | c.push_back(__v); |
| 597 | _STD::push_heap(c.begin(), c.end(), comp); |
| 598 | } |
| 599 | |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 600 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 601 | |
| 602 | template <class _Tp, class _Container, class _Compare> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 603 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 604 | void |
| 605 | priority_queue<_Tp, _Container, _Compare>::push(value_type&& __v) |
| 606 | { |
| 607 | c.push_back(_STD::move(__v)); |
| 608 | _STD::push_heap(c.begin(), c.end(), comp); |
| 609 | } |
| 610 | |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 611 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 612 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 613 | template <class _Tp, class _Container, class _Compare> |
| 614 | template <class... _Args> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 615 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 616 | void |
| 617 | priority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args) |
| 618 | { |
| 619 | c.emplace_back(_STD::forward<_Args>(__args)...); |
| 620 | _STD::push_heap(c.begin(), c.end(), comp); |
| 621 | } |
| 622 | |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 623 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 624 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 625 | |
| 626 | template <class _Tp, class _Container, class _Compare> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 627 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 628 | void |
| 629 | priority_queue<_Tp, _Container, _Compare>::pop() |
| 630 | { |
| 631 | _STD::pop_heap(c.begin(), c.end(), comp); |
| 632 | c.pop_back(); |
| 633 | } |
| 634 | |
| 635 | template <class _Tp, class _Container, class _Compare> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 636 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 637 | void |
| 638 | priority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q) |
| 639 | { |
| 640 | using _STD::swap; |
| 641 | swap(c, __q.c); |
| 642 | swap(comp, __q.comp); |
| 643 | } |
| 644 | |
| 645 | template <class _Tp, class _Container, class _Compare> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 646 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 647 | void |
| 648 | swap(priority_queue<_Tp, _Container, _Compare>& __x, |
| 649 | priority_queue<_Tp, _Container, _Compare>& __y) |
| 650 | { |
| 651 | __x.swap(__y); |
| 652 | } |
| 653 | |
| 654 | template <class _Tp, class _Container, class _Compare, class _Alloc> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 655 | struct _LIBCPP_VISIBLE uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 656 | : public uses_allocator<_Container, _Alloc> |
| 657 | { |
| 658 | }; |
| 659 | |
| 660 | _LIBCPP_END_NAMESPACE_STD |
| 661 | |
| 662 | #endif // _LIBCPP_QUEUE |