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