Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1 | // -*- C++ -*- |
Louis Dionne | eb8650a | 2021-11-17 21:25:01 | [diff] [blame] | 2 | //===----------------------------------------------------------------------===// |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 3 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 | [diff] [blame] | 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_QUEUE |
| 11 | #define _LIBCPP_QUEUE |
| 12 | |
| 13 | /* |
| 14 | queue synopsis |
| 15 | |
| 16 | namespace std |
| 17 | { |
| 18 | |
| 19 | template <class T, class Container = deque<T>> |
| 20 | class queue |
| 21 | { |
| 22 | public: |
| 23 | typedef Container container_type; |
| 24 | typedef typename container_type::value_type value_type; |
| 25 | typedef typename container_type::reference reference; |
| 26 | typedef typename container_type::const_reference const_reference; |
| 27 | typedef typename container_type::size_type size_type; |
| 28 | |
| 29 | protected: |
| 30 | container_type c; |
| 31 | |
| 32 | public: |
Howard Hinnant | 6971d82 | 2011-06-04 21:32:33 | [diff] [blame] | 33 | queue() = default; |
| 34 | ~queue() = default; |
| 35 | |
| 36 | queue(const queue& q) = default; |
| 37 | queue(queue&& q) = default; |
| 38 | |
| 39 | queue& operator=(const queue& q) = default; |
| 40 | queue& operator=(queue&& q) = default; |
| 41 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 42 | explicit queue(const container_type& c); |
Howard Hinnant | 6971d82 | 2011-06-04 21:32:33 | [diff] [blame] | 43 | explicit queue(container_type&& c) |
Nikolas Klauser | f3aed36 | 2022-01-06 11:36:07 | [diff] [blame] | 44 | template<class InputIterator> |
| 45 | queue(InputIterator first, InputIterator last); // since C++23 |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 46 | template<container-compatible-range<T> R> queue(from_range_t, R&& rg); // since C++23 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 47 | template <class Alloc> |
| 48 | explicit queue(const Alloc& a); |
| 49 | template <class Alloc> |
| 50 | queue(const container_type& c, const Alloc& a); |
| 51 | template <class Alloc> |
| 52 | queue(container_type&& c, const Alloc& a); |
| 53 | template <class Alloc> |
Howard Hinnant | 6971d82 | 2011-06-04 21:32:33 | [diff] [blame] | 54 | queue(const queue& q, const Alloc& a); |
| 55 | template <class Alloc> |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 56 | queue(queue&& q, const Alloc& a); |
Nikolas Klauser | f3aed36 | 2022-01-06 11:36:07 | [diff] [blame] | 57 | template <class InputIterator, class Alloc> |
| 58 | queue(InputIterator first, InputIterator last, const Alloc&); // since C++23 |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 59 | template<container-compatible-range<T> R, class Alloc> |
| 60 | queue(from_range_t, R&& rg, const Alloc&); // since C++23 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 61 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 62 | bool empty() const; |
| 63 | size_type size() const; |
| 64 | |
| 65 | reference front(); |
| 66 | const_reference front() const; |
| 67 | reference back(); |
| 68 | const_reference back() const; |
| 69 | |
| 70 | void push(const value_type& v); |
| 71 | void push(value_type&& v); |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 72 | template<container-compatible-range<T> R> |
| 73 | void push_range(R&& rg); // C++23 |
Marshall Clow | 63b560b | 2017-01-24 23:09:12 | [diff] [blame] | 74 | template <class... Args> reference emplace(Args&&... args); // reference in C++17 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 75 | void pop(); |
| 76 | |
Eric Fiselier | f07dd8d | 2016-04-21 23:38:59 | [diff] [blame] | 77 | void swap(queue& q) noexcept(is_nothrow_swappable_v<Container>) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 78 | }; |
| 79 | |
Marshall Clow | 5b8b8b5 | 2018-05-22 01:57:53 | [diff] [blame] | 80 | template<class Container> |
| 81 | queue(Container) -> queue<typename Container::value_type, Container>; // C++17 |
Louis Dionne | a2a1ec2 | 2019-05-29 16:01:36 | [diff] [blame] | 82 | |
Nikolas Klauser | f3aed36 | 2022-01-06 11:36:07 | [diff] [blame] | 83 | template<class InputIterator> |
| 84 | queue(InputIterator, InputIterator) -> queue<iter-value-type<InputIterator>>; // since C++23 |
| 85 | |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 86 | template<ranges::input_range R> |
| 87 | queue(from_range_t, R&&) -> queue<ranges::range_value_t<R>>; // since C++23 |
| 88 | |
Louis Dionne | a2a1ec2 | 2019-05-29 16:01:36 | [diff] [blame] | 89 | template<class Container, class Allocator> |
Marshall Clow | 5b8b8b5 | 2018-05-22 01:57:53 | [diff] [blame] | 90 | queue(Container, Allocator) -> queue<typename Container::value_type, Container>; // C++17 |
| 91 | |
Nikolas Klauser | f3aed36 | 2022-01-06 11:36:07 | [diff] [blame] | 92 | template<class InputIterator, class Allocator> |
| 93 | queue(InputIterator, InputIterator, Allocator) |
| 94 | -> queue<iter-value-type<InputIterator>, |
| 95 | deque<iter-value-type<InputIterator>, Allocator>>; // since C++23 |
| 96 | |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 97 | template<ranges::input_range R, class Allocator> |
| 98 | queue(from_range_t, R&&, Allocator) |
| 99 | -> queue<ranges::range_value_t<R>, deque<ranges::range_value_t<R>, Allocator>>; // since C++23 |
| 100 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 101 | template <class T, class Container> |
| 102 | bool operator==(const queue<T, Container>& x,const queue<T, Container>& y); |
| 103 | |
| 104 | template <class T, class Container> |
| 105 | bool operator< (const queue<T, Container>& x,const queue<T, Container>& y); |
| 106 | |
| 107 | template <class T, class Container> |
| 108 | bool operator!=(const queue<T, Container>& x,const queue<T, Container>& y); |
| 109 | |
| 110 | template <class T, class Container> |
| 111 | bool operator> (const queue<T, Container>& x,const queue<T, Container>& y); |
| 112 | |
| 113 | template <class T, class Container> |
| 114 | bool operator>=(const queue<T, Container>& x,const queue<T, Container>& y); |
| 115 | |
| 116 | template <class T, class Container> |
| 117 | bool operator<=(const queue<T, Container>& x,const queue<T, Container>& y); |
| 118 | |
Hristo Hristov | 172d990 | 2023-03-14 16:32:15 | [diff] [blame] | 119 | template<class T, three_way_comparable Container> |
| 120 | compare_three_way_result_t<Container> |
| 121 | operator<=>(const queue<T, Container>& x, const queue<T, Container>& y); // since C++20 |
| 122 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 123 | template <class T, class Container> |
Howard Hinnant | 6971d82 | 2011-06-04 21:32:33 | [diff] [blame] | 124 | void swap(queue<T, Container>& x, queue<T, Container>& y) |
| 125 | noexcept(noexcept(x.swap(y))); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 126 | |
| 127 | template <class T, class Container = vector<T>, |
| 128 | class Compare = less<typename Container::value_type>> |
| 129 | class priority_queue |
| 130 | { |
| 131 | public: |
| 132 | typedef Container container_type; |
| 133 | typedef typename container_type::value_type value_type; |
| 134 | typedef typename container_type::reference reference; |
| 135 | typedef typename container_type::const_reference const_reference; |
| 136 | typedef typename container_type::size_type size_type; |
| 137 | |
| 138 | protected: |
| 139 | container_type c; |
| 140 | Compare comp; |
| 141 | |
| 142 | public: |
Marek Kurdej | a11f8b1 | 2021-01-19 07:21:09 | [diff] [blame] | 143 | priority_queue() : priority_queue(Compare()) {} // C++20 |
| 144 | explicit priority_queue(const Compare& x) : priority_queue(x, Container()) {} |
| 145 | priority_queue(const Compare& x, const Container&); |
Arthur O'Dwyer | 3894a8a | 2021-03-02 05:23:21 | [diff] [blame] | 146 | explicit priority_queue(const Compare& x = Compare(), Container&& = Container()); // before C++20 |
Marek Kurdej | a11f8b1 | 2021-01-19 07:21:09 | [diff] [blame] | 147 | priority_queue(const Compare& x, Container&&); // C++20 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 148 | template <class InputIterator> |
| 149 | priority_queue(InputIterator first, InputIterator last, |
| 150 | const Compare& comp = Compare()); |
| 151 | template <class InputIterator> |
| 152 | priority_queue(InputIterator first, InputIterator last, |
Arthur O'Dwyer | 3894a8a | 2021-03-02 05:23:21 | [diff] [blame] | 153 | const Compare& comp, const Container& c); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 154 | template <class InputIterator> |
| 155 | priority_queue(InputIterator first, InputIterator last, |
Arthur O'Dwyer | 3894a8a | 2021-03-02 05:23:21 | [diff] [blame] | 156 | const Compare& comp, Container&& c); |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 157 | template <container-compatible-range<T> R> |
| 158 | priority_queue(from_range_t, R&& rg, const Compare& x = Compare()); // since C++23 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 159 | template <class Alloc> |
| 160 | explicit priority_queue(const Alloc& a); |
| 161 | template <class Alloc> |
| 162 | priority_queue(const Compare& comp, const Alloc& a); |
| 163 | template <class Alloc> |
Arthur O'Dwyer | 3894a8a | 2021-03-02 05:23:21 | [diff] [blame] | 164 | priority_queue(const Compare& comp, const Container& c, |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 165 | const Alloc& a); |
| 166 | template <class Alloc> |
Arthur O'Dwyer | 3894a8a | 2021-03-02 05:23:21 | [diff] [blame] | 167 | priority_queue(const Compare& comp, Container&& c, |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 168 | const Alloc& a); |
Arthur O'Dwyer | 3894a8a | 2021-03-02 05:23:21 | [diff] [blame] | 169 | template <class InputIterator> |
| 170 | priority_queue(InputIterator first, InputIterator last, |
| 171 | const Alloc& a); |
| 172 | template <class InputIterator> |
| 173 | priority_queue(InputIterator first, InputIterator last, |
| 174 | const Compare& comp, const Alloc& a); |
| 175 | template <class InputIterator> |
| 176 | priority_queue(InputIterator first, InputIterator last, |
| 177 | const Compare& comp, const Container& c, const Alloc& a); |
| 178 | template <class InputIterator> |
| 179 | priority_queue(InputIterator first, InputIterator last, |
| 180 | const Compare& comp, Container&& c, const Alloc& a); |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 181 | template <container-compatible-range<T> R, class Alloc> |
| 182 | priority_queue(from_range_t, R&& rg, const Compare&, const Alloc&); // since C++23 |
| 183 | template <container-compatible-range<T> R, class Alloc> |
| 184 | priority_queue(from_range_t, R&& rg, const Alloc&); // since C++23 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 185 | template <class Alloc> |
Howard Hinnant | 6971d82 | 2011-06-04 21:32:33 | [diff] [blame] | 186 | priority_queue(const priority_queue& q, const Alloc& a); |
| 187 | template <class Alloc> |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 188 | priority_queue(priority_queue&& q, const Alloc& a); |
| 189 | |
| 190 | bool empty() const; |
| 191 | size_type size() const; |
| 192 | const_reference top() const; |
| 193 | |
| 194 | void push(const value_type& v); |
| 195 | void push(value_type&& v); |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 196 | template<container-compatible-range<T> R> |
| 197 | void push_range(R&& rg); // C++23 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 198 | template <class... Args> void emplace(Args&&... args); |
| 199 | void pop(); |
| 200 | |
Howard Hinnant | 6971d82 | 2011-06-04 21:32:33 | [diff] [blame] | 201 | void swap(priority_queue& q) |
Eric Fiselier | f07dd8d | 2016-04-21 23:38:59 | [diff] [blame] | 202 | noexcept(is_nothrow_swappable_v<Container> && |
| 203 | is_nothrow_swappable_v<Comp>) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 204 | }; |
| 205 | |
Marshall Clow | 5b8b8b5 | 2018-05-22 01:57:53 | [diff] [blame] | 206 | template <class Compare, class Container> |
| 207 | priority_queue(Compare, Container) |
| 208 | -> priority_queue<typename Container::value_type, Container, Compare>; // C++17 |
Louis Dionne | a2a1ec2 | 2019-05-29 16:01:36 | [diff] [blame] | 209 | |
| 210 | template<class InputIterator, |
Arthur O'Dwyer | 3894a8a | 2021-03-02 05:23:21 | [diff] [blame] | 211 | class Compare = less<iter-value-type<InputIterator>>, |
| 212 | class Container = vector<iter-value-type<InputIterator>>> |
Marshall Clow | 5b8b8b5 | 2018-05-22 01:57:53 | [diff] [blame] | 213 | priority_queue(InputIterator, InputIterator, Compare = Compare(), Container = Container()) |
Arthur O'Dwyer | 3894a8a | 2021-03-02 05:23:21 | [diff] [blame] | 214 | -> priority_queue<iter-value-type<InputIterator>, Container, Compare>; // C++17 |
Louis Dionne | a2a1ec2 | 2019-05-29 16:01:36 | [diff] [blame] | 215 | |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 216 | template<ranges::input_range R, class Compare = less<ranges::range_value_t<R>>> |
| 217 | priority_queue(from_range_t, R&&, Compare = Compare()) |
| 218 | -> priority_queue<ranges::range_value_t<R>, vector<ranges::range_value_t<R>>, Compare>; // C++23 |
| 219 | |
Marshall Clow | 5b8b8b5 | 2018-05-22 01:57:53 | [diff] [blame] | 220 | template<class Compare, class Container, class Allocator> |
| 221 | priority_queue(Compare, Container, Allocator) |
| 222 | -> priority_queue<typename Container::value_type, Container, Compare>; // C++17 |
| 223 | |
Arthur O'Dwyer | 3894a8a | 2021-03-02 05:23:21 | [diff] [blame] | 224 | template<class InputIterator, class Allocator> |
| 225 | priority_queue(InputIterator, InputIterator, Allocator) |
| 226 | -> priority_queue<iter-value-type<InputIterator>, |
| 227 | vector<iter-value-type<InputIterator>, Allocator>, |
Konstantin Varlamov | 68072a7 | 2021-11-09 17:21:02 | [diff] [blame] | 228 | less<iter-value-type<InputIterator>>>; // C++17 |
Arthur O'Dwyer | 3894a8a | 2021-03-02 05:23:21 | [diff] [blame] | 229 | |
| 230 | template<class InputIterator, class Compare, class Allocator> |
| 231 | priority_queue(InputIterator, InputIterator, Compare, Allocator) |
| 232 | -> priority_queue<iter-value-type<InputIterator>, |
Konstantin Varlamov | 68072a7 | 2021-11-09 17:21:02 | [diff] [blame] | 233 | vector<iter-value-type<InputIterator>, Allocator>, Compare>; // C++17 |
Arthur O'Dwyer | 3894a8a | 2021-03-02 05:23:21 | [diff] [blame] | 234 | |
| 235 | template<class InputIterator, class Compare, class Container, class Allocator> |
| 236 | priority_queue(InputIterator, InputIterator, Compare, Container, Allocator) |
Konstantin Varlamov | 68072a7 | 2021-11-09 17:21:02 | [diff] [blame] | 237 | -> priority_queue<typename Container::value_type, Container, Compare>; // C++17 |
Arthur O'Dwyer | 3894a8a | 2021-03-02 05:23:21 | [diff] [blame] | 238 | |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 239 | template<ranges::input_range R, class Compare, class Allocator> |
| 240 | priority_queue(from_range_t, R&&, Compare, Allocator) |
| 241 | -> priority_queue<ranges::range_value_t<R>, vector<ranges::range_value_t<R>, Allocator>, |
| 242 | Compare>; // C++23 |
| 243 | |
| 244 | template<ranges::input_range R, class Allocator> |
| 245 | priority_queue(from_range_t, R&&, Allocator) |
| 246 | -> priority_queue<ranges::range_value_t<R>, vector<ranges::range_value_t<R>, Allocator>>; // C++23 |
| 247 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 248 | template <class T, class Container, class Compare> |
| 249 | void swap(priority_queue<T, Container, Compare>& x, |
Howard Hinnant | 6971d82 | 2011-06-04 21:32:33 | [diff] [blame] | 250 | priority_queue<T, Container, Compare>& y) |
| 251 | noexcept(noexcept(x.swap(y))); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 252 | |
| 253 | } // std |
| 254 | |
| 255 | */ |
| 256 | |
Nikolas Klauser | 2e2f315 | 2022-02-15 17:18:08 | [diff] [blame] | 257 | #include <__algorithm/make_heap.h> |
| 258 | #include <__algorithm/pop_heap.h> |
| 259 | #include <__algorithm/push_heap.h> |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 260 | #include <__algorithm/ranges_copy.h> |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 261 | #include <__config> |
Nikolas Klauser | 34f7380 | 2022-05-20 22:45:51 | [diff] [blame] | 262 | #include <__functional/operations.h> |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 263 | #include <__iterator/back_insert_iterator.h> |
Nikolas Klauser | f3aed36 | 2022-01-06 11:36:07 | [diff] [blame] | 264 | #include <__iterator/iterator_traits.h> |
Christopher Di Bella | 050b064 | 2021-07-01 13:25:35 | [diff] [blame] | 265 | #include <__memory/uses_allocator.h> |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 266 | #include <__ranges/access.h> |
| 267 | #include <__ranges/concepts.h> |
| 268 | #include <__ranges/container_compatible_range.h> |
| 269 | #include <__ranges/from_range.h> |
Christopher Di Bella | 6adbc83 | 2021-06-05 02:47:47 | [diff] [blame] | 270 | #include <__utility/forward.h> |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 271 | #include <deque> |
Arthur O'Dwyer | bfbd73f | 2021-05-19 15:57:04 | [diff] [blame] | 272 | #include <vector> |
Mark de Wever | bd6e684 | 2021-12-22 17:14:14 | [diff] [blame] | 273 | #include <version> |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 274 | |
Nikolas Klauser | db1978b | 2022-06-16 20:43:46 | [diff] [blame] | 275 | // standard-mandated includes |
Nikolas Klauser | 473a160 | 2022-09-22 16:05:08 | [diff] [blame] | 276 | |
| 277 | // [queue.syn] |
Nikolas Klauser | db1978b | 2022-06-16 20:43:46 | [diff] [blame] | 278 | #include <compare> |
| 279 | #include <initializer_list> |
| 280 | |
Howard Hinnant | 073458b | 2011-10-17 20:05:10 | [diff] [blame] | 281 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Arthur O'Dwyer | fa6b9e4 | 2022-02-02 01:16:40 | [diff] [blame] | 282 | # pragma GCC system_header |
Howard Hinnant | 073458b | 2011-10-17 20:05:10 | [diff] [blame] | 283 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 284 | |
Louis Dionne | 7b46225 | 2024-01-25 20:48:46 | [diff] [blame] | 285 | _LIBCPP_PUSH_MACROS |
| 286 | #include <__undef_macros> |
| 287 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 288 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 289 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 290 | template <class _Tp, class _Container = deque<_Tp> > |
| 291 | class _LIBCPP_TEMPLATE_VIS queue; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 292 | |
| 293 | template <class _Tp, class _Container> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 294 | _LIBCPP_HIDE_FROM_ABI bool operator==(const queue<_Tp, _Container>& __x, const queue<_Tp, _Container>& __y); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 295 | |
| 296 | template <class _Tp, class _Container> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 297 | _LIBCPP_HIDE_FROM_ABI bool operator<(const queue<_Tp, _Container>& __x, const queue<_Tp, _Container>& __y); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 298 | |
Marshall Clow | 3afa22a | 2015-02-18 17:51:56 | [diff] [blame] | 299 | template <class _Tp, class _Container /*= deque<_Tp>*/> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 300 | class _LIBCPP_TEMPLATE_VIS queue { |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 301 | public: |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 302 | typedef _Container container_type; |
| 303 | typedef typename container_type::value_type value_type; |
| 304 | typedef typename container_type::reference reference; |
| 305 | typedef typename container_type::const_reference const_reference; |
| 306 | typedef typename container_type::size_type size_type; |
| 307 | static_assert((is_same<_Tp, value_type>::value), ""); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 308 | |
| 309 | protected: |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 310 | container_type c; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 311 | |
| 312 | public: |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 313 | _LIBCPP_HIDE_FROM_ABI queue() _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value) : c() {} |
Howard Hinnant | 6971d82 | 2011-06-04 21:32:33 | [diff] [blame] | 314 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 315 | _LIBCPP_HIDE_FROM_ABI queue(const queue& __q) : c(__q.c) {} |
Howard Hinnant | 6971d82 | 2011-06-04 21:32:33 | [diff] [blame] | 316 | |
Nikolas Klauser | 4f15267 | 2023-02-13 23:56:09 | [diff] [blame] | 317 | #if _LIBCPP_STD_VER >= 23 |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 318 | template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 319 | _LIBCPP_HIDE_FROM_ABI queue(_InputIterator __first, _InputIterator __last) : c(__first, __last) {} |
Nikolas Klauser | f3aed36 | 2022-01-06 11:36:07 | [diff] [blame] | 320 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 321 | template <_ContainerCompatibleRange<_Tp> _Range> |
| 322 | _LIBCPP_HIDE_FROM_ABI queue(from_range_t, _Range&& __range) : c(from_range, std::forward<_Range>(__range)) {} |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 323 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 324 | template <class _InputIterator, |
| 325 | class _Alloc, |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 326 | __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0, |
| 327 | __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 328 | _LIBCPP_HIDE_FROM_ABI queue(_InputIterator __first, _InputIterator __second, const _Alloc& __alloc) |
| 329 | : c(__first, __second, __alloc) {} |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 330 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 331 | template <_ContainerCompatibleRange<_Tp> _Range, |
| 332 | class _Alloc, |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 333 | __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 334 | _LIBCPP_HIDE_FROM_ABI queue(from_range_t, _Range&& __range, const _Alloc& __alloc) |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 335 | : c(from_range, std::forward<_Range>(__range), __alloc) {} |
| 336 | |
Nikolas Klauser | f3aed36 | 2022-01-06 11:36:07 | [diff] [blame] | 337 | #endif |
| 338 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 339 | _LIBCPP_HIDE_FROM_ABI queue& operator=(const queue& __q) { |
| 340 | c = __q.c; |
| 341 | return *this; |
| 342 | } |
Eric Fiselier | f5427b2 | 2017-04-18 21:23:18 | [diff] [blame] | 343 | |
| 344 | #ifndef _LIBCPP_CXX03_LANG |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 345 | _LIBCPP_HIDE_FROM_ABI queue(queue&& __q) _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value) |
| 346 | : c(std::move(__q.c)) {} |
Howard Hinnant | 6971d82 | 2011-06-04 21:32:33 | [diff] [blame] | 347 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 348 | _LIBCPP_HIDE_FROM_ABI queue& operator=(queue&& __q) _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value) { |
| 349 | c = std::move(__q.c); |
| 350 | return *this; |
| 351 | } |
Louis Dionne | 4cd6ca1 | 2021-04-20 16:03:32 | [diff] [blame] | 352 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 6971d82 | 2011-06-04 21:32:33 | [diff] [blame] | 353 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 354 | _LIBCPP_HIDE_FROM_ABI explicit queue(const container_type& __c) : c(__c) {} |
Eric Fiselier | f5427b2 | 2017-04-18 21:23:18 | [diff] [blame] | 355 | #ifndef _LIBCPP_CXX03_LANG |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 356 | _LIBCPP_HIDE_FROM_ABI explicit queue(container_type&& __c) : c(std::move(__c)) {} |
Louis Dionne | 4cd6ca1 | 2021-04-20 16:03:32 | [diff] [blame] | 357 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 358 | |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 359 | template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0> |
| 360 | _LIBCPP_HIDE_FROM_ABI explicit queue(const _Alloc& __a) : c(__a) {} |
| 361 | |
| 362 | template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0> |
| 363 | _LIBCPP_HIDE_FROM_ABI queue(const queue& __q, const _Alloc& __a) : c(__q.c, __a) {} |
| 364 | |
| 365 | template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0> |
| 366 | _LIBCPP_HIDE_FROM_ABI queue(const container_type& __c, const _Alloc& __a) : c(__c, __a) {} |
| 367 | |
| 368 | #ifndef _LIBCPP_CXX03_LANG |
| 369 | template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0> |
| 370 | _LIBCPP_HIDE_FROM_ABI queue(container_type&& __c, const _Alloc& __a) : c(std::move(__c), __a) {} |
| 371 | |
| 372 | template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0> |
| 373 | _LIBCPP_HIDE_FROM_ABI queue(queue&& __q, const _Alloc& __a) : c(std::move(__q.c), __a) {} |
Louis Dionne | 4cd6ca1 | 2021-04-20 16:03:32 | [diff] [blame] | 374 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 375 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 376 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI bool empty() const { return c.empty(); } |
| 377 | _LIBCPP_HIDE_FROM_ABI size_type size() const { return c.size(); } |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 378 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 379 | _LIBCPP_HIDE_FROM_ABI reference front() { return c.front(); } |
| 380 | _LIBCPP_HIDE_FROM_ABI const_reference front() const { return c.front(); } |
| 381 | _LIBCPP_HIDE_FROM_ABI reference back() { return c.back(); } |
| 382 | _LIBCPP_HIDE_FROM_ABI const_reference back() const { return c.back(); } |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 383 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 384 | _LIBCPP_HIDE_FROM_ABI void push(const value_type& __v) { c.push_back(__v); } |
Eric Fiselier | f5427b2 | 2017-04-18 21:23:18 | [diff] [blame] | 385 | #ifndef _LIBCPP_CXX03_LANG |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 386 | _LIBCPP_HIDE_FROM_ABI void push(value_type&& __v) { c.push_back(std::move(__v)); } |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 387 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 388 | # if _LIBCPP_STD_VER >= 23 |
| 389 | template <_ContainerCompatibleRange<_Tp> _Range> |
| 390 | _LIBCPP_HIDE_FROM_ABI void push_range(_Range&& __range) { |
| 391 | if constexpr (requires(container_type& __c) { __c.append_range(std::forward<_Range>(__range)); }) { |
| 392 | c.append_range(std::forward<_Range>(__range)); |
| 393 | } else { |
| 394 | ranges::copy(std::forward<_Range>(__range), std::back_inserter(c)); |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 395 | } |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 396 | } |
| 397 | # endif |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 398 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 399 | template <class... _Args> |
| 400 | _LIBCPP_HIDE_FROM_ABI |
| 401 | # if _LIBCPP_STD_VER >= 17 |
| 402 | decltype(auto) |
| 403 | emplace(_Args&&... __args) { |
| 404 | return c.emplace_back(std::forward<_Args>(__args)...); |
| 405 | } |
| 406 | # else |
| 407 | void |
| 408 | emplace(_Args&&... __args) { |
| 409 | c.emplace_back(std::forward<_Args>(__args)...); |
| 410 | } |
| 411 | # endif |
Louis Dionne | 4cd6ca1 | 2021-04-20 16:03:32 | [diff] [blame] | 412 | #endif // _LIBCPP_CXX03_LANG |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 413 | _LIBCPP_HIDE_FROM_ABI void pop() { c.pop_front(); } |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 414 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 415 | _LIBCPP_HIDE_FROM_ABI void swap(queue& __q) _NOEXCEPT_(__is_nothrow_swappable<container_type>::value) { |
| 416 | using std::swap; |
| 417 | swap(c, __q.c); |
| 418 | } |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 419 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 420 | _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI const _Container& __get_container() const { return c; } |
Mark de Wever | 04d4f4b | 2022-05-05 16:57:32 | [diff] [blame] | 421 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 422 | template <class _T1, class _OtherContainer> |
| 423 | friend _LIBCPP_HIDE_FROM_ABI bool |
| 424 | operator==(const queue<_T1, _OtherContainer>& __x, const queue<_T1, _OtherContainer>& __y); |
Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 | [diff] [blame] | 425 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 426 | template <class _T1, class _OtherContainer> |
| 427 | friend _LIBCPP_HIDE_FROM_ABI bool |
| 428 | operator<(const queue<_T1, _OtherContainer>& __x, const queue<_T1, _OtherContainer>& __y); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 429 | }; |
| 430 | |
Nikolas Klauser | 4f15267 | 2023-02-13 23:56:09 | [diff] [blame] | 431 | #if _LIBCPP_STD_VER >= 17 |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 432 | template <class _Container, class = enable_if_t<!__is_allocator<_Container>::value> > |
| 433 | queue(_Container) -> queue<typename _Container::value_type, _Container>; |
Louis Dionne | a2a1ec2 | 2019-05-29 16:01:36 | [diff] [blame] | 434 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 435 | template <class _Container, |
| 436 | class _Alloc, |
| 437 | class = enable_if_t<!__is_allocator<_Container>::value>, |
| 438 | class = enable_if_t<uses_allocator<_Container, _Alloc>::value> > |
| 439 | queue(_Container, _Alloc) -> queue<typename _Container::value_type, _Container>; |
Marshall Clow | 5b8b8b5 | 2018-05-22 01:57:53 | [diff] [blame] | 440 | #endif |
| 441 | |
Nikolas Klauser | 4f15267 | 2023-02-13 23:56:09 | [diff] [blame] | 442 | #if _LIBCPP_STD_VER >= 23 |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 443 | template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 444 | queue(_InputIterator, _InputIterator) -> queue<__iter_value_type<_InputIterator>>; |
Nikolas Klauser | f3aed36 | 2022-01-06 11:36:07 | [diff] [blame] | 445 | |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 446 | template <ranges::input_range _Range> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 447 | queue(from_range_t, _Range&&) -> queue<ranges::range_value_t<_Range>>; |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 448 | |
Nikolas Klauser | f3aed36 | 2022-01-06 11:36:07 | [diff] [blame] | 449 | template <class _InputIterator, |
| 450 | class _Alloc, |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 451 | __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0, |
| 452 | __enable_if_t<__is_allocator<_Alloc>::value, int> = 0> |
| 453 | queue(_InputIterator, |
| 454 | _InputIterator, |
| 455 | _Alloc) -> queue<__iter_value_type<_InputIterator>, deque<__iter_value_type<_InputIterator>, _Alloc>>; |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 456 | |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 457 | template <ranges::input_range _Range, class _Alloc, __enable_if_t<__is_allocator<_Alloc>::value, int> = 0> |
| 458 | queue(from_range_t, |
| 459 | _Range&&, |
| 460 | _Alloc) -> queue<ranges::range_value_t<_Range>, deque<ranges::range_value_t<_Range>, _Alloc>>; |
Nikolas Klauser | f3aed36 | 2022-01-06 11:36:07 | [diff] [blame] | 461 | #endif |
| 462 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 463 | template <class _Tp, class _Container> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 464 | inline _LIBCPP_HIDE_FROM_ABI bool operator==(const queue<_Tp, _Container>& __x, const queue<_Tp, _Container>& __y) { |
| 465 | return __x.c == __y.c; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | template <class _Tp, class _Container> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 469 | inline _LIBCPP_HIDE_FROM_ABI bool operator<(const queue<_Tp, _Container>& __x, const queue<_Tp, _Container>& __y) { |
| 470 | return __x.c < __y.c; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | template <class _Tp, class _Container> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 474 | inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const queue<_Tp, _Container>& __x, const queue<_Tp, _Container>& __y) { |
| 475 | return !(__x == __y); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | template <class _Tp, class _Container> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 479 | inline _LIBCPP_HIDE_FROM_ABI bool operator>(const queue<_Tp, _Container>& __x, const queue<_Tp, _Container>& __y) { |
| 480 | return __y < __x; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | template <class _Tp, class _Container> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 484 | inline _LIBCPP_HIDE_FROM_ABI bool operator>=(const queue<_Tp, _Container>& __x, const queue<_Tp, _Container>& __y) { |
| 485 | return !(__x < __y); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | template <class _Tp, class _Container> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 489 | inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const queue<_Tp, _Container>& __x, const queue<_Tp, _Container>& __y) { |
| 490 | return !(__y < __x); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 491 | } |
| 492 | |
Hristo Hristov | 172d990 | 2023-03-14 16:32:15 | [diff] [blame] | 493 | #if _LIBCPP_STD_VER >= 20 |
| 494 | |
| 495 | template <class _Tp, three_way_comparable _Container> |
| 496 | _LIBCPP_HIDE_FROM_ABI compare_three_way_result_t<_Container> |
| 497 | operator<=>(const queue<_Tp, _Container>& __x, const queue<_Tp, _Container>& __y) { |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 498 | // clang 16 bug: declaring `friend operator<=>` causes "use of overloaded operator '*' is ambiguous" errors |
| 499 | return __x.__get_container() <=> __y.__get_container(); |
Hristo Hristov | 172d990 | 2023-03-14 16:32:15 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | #endif |
| 503 | |
Nikolas Klauser | 9f3e3ef | 2023-09-02 00:52:02 | [diff] [blame] | 504 | template <class _Tp, class _Container, __enable_if_t<__is_swappable<_Container>::value, int> = 0> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 505 | inline _LIBCPP_HIDE_FROM_ABI void swap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y) |
| 506 | _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) { |
| 507 | __x.swap(__y); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | template <class _Tp, class _Container, class _Alloc> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 511 | struct _LIBCPP_TEMPLATE_VIS uses_allocator<queue<_Tp, _Container>, _Alloc> : public uses_allocator<_Container, _Alloc> { |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 512 | }; |
| 513 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 514 | template <class _Tp, class _Container = vector<_Tp>, class _Compare = less<typename _Container::value_type> > |
| 515 | class _LIBCPP_TEMPLATE_VIS priority_queue { |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 516 | public: |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 517 | typedef _Container container_type; |
| 518 | typedef _Compare value_compare; |
| 519 | typedef typename container_type::value_type value_type; |
| 520 | typedef typename container_type::reference reference; |
| 521 | typedef typename container_type::const_reference const_reference; |
| 522 | typedef typename container_type::size_type size_type; |
| 523 | static_assert((is_same<_Tp, value_type>::value), ""); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 524 | |
| 525 | protected: |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 526 | container_type c; |
| 527 | value_compare comp; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 528 | |
| 529 | public: |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 530 | _LIBCPP_HIDE_FROM_ABI priority_queue() _NOEXCEPT_( |
| 531 | is_nothrow_default_constructible<container_type>::value&& is_nothrow_default_constructible<value_compare>::value) |
| 532 | : c(), comp() {} |
Howard Hinnant | 6971d82 | 2011-06-04 21:32:33 | [diff] [blame] | 533 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 534 | _LIBCPP_HIDE_FROM_ABI priority_queue(const priority_queue& __q) : c(__q.c), comp(__q.comp) {} |
Howard Hinnant | 6971d82 | 2011-06-04 21:32:33 | [diff] [blame] | 535 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 536 | _LIBCPP_HIDE_FROM_ABI priority_queue& operator=(const priority_queue& __q) { |
| 537 | c = __q.c; |
| 538 | comp = __q.comp; |
| 539 | return *this; |
| 540 | } |
Eric Fiselier | f5427b2 | 2017-04-18 21:23:18 | [diff] [blame] | 541 | |
| 542 | #ifndef _LIBCPP_CXX03_LANG |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 543 | _LIBCPP_HIDE_FROM_ABI priority_queue(priority_queue&& __q) _NOEXCEPT_( |
| 544 | is_nothrow_move_constructible<container_type>::value&& is_nothrow_move_constructible<value_compare>::value) |
| 545 | : c(std::move(__q.c)), comp(std::move(__q.comp)) {} |
Howard Hinnant | 6971d82 | 2011-06-04 21:32:33 | [diff] [blame] | 546 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 547 | _LIBCPP_HIDE_FROM_ABI priority_queue& operator=(priority_queue&& __q) |
| 548 | _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value&& is_nothrow_move_assignable<value_compare>::value) { |
| 549 | c = std::move(__q.c); |
| 550 | comp = std::move(__q.comp); |
| 551 | return *this; |
| 552 | } |
Louis Dionne | 4cd6ca1 | 2021-04-20 16:03:32 | [diff] [blame] | 553 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 6971d82 | 2011-06-04 21:32:33 | [diff] [blame] | 554 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 555 | _LIBCPP_HIDE_FROM_ABI explicit priority_queue(const value_compare& __comp) : c(), comp(__comp) {} |
| 556 | _LIBCPP_HIDE_FROM_ABI priority_queue(const value_compare& __comp, const container_type& __c); |
Eric Fiselier | f5427b2 | 2017-04-18 21:23:18 | [diff] [blame] | 557 | #ifndef _LIBCPP_CXX03_LANG |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 558 | _LIBCPP_HIDE_FROM_ABI priority_queue(const value_compare& __comp, container_type&& __c); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 559 | #endif |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 560 | template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> = 0> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 561 | _LIBCPP_HIDE_FROM_ABI priority_queue(_InputIter __f, _InputIter __l, const value_compare& __comp = value_compare()); |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 562 | |
| 563 | template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> = 0> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 564 | _LIBCPP_HIDE_FROM_ABI |
| 565 | priority_queue(_InputIter __f, _InputIter __l, const value_compare& __comp, const container_type& __c); |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 566 | |
Eric Fiselier | f5427b2 | 2017-04-18 21:23:18 | [diff] [blame] | 567 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 568 | template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> = 0> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 569 | _LIBCPP_HIDE_FROM_ABI |
| 570 | priority_queue(_InputIter __f, _InputIter __l, const value_compare& __comp, container_type&& __c); |
Louis Dionne | 4cd6ca1 | 2021-04-20 16:03:32 | [diff] [blame] | 571 | #endif // _LIBCPP_CXX03_LANG |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 572 | |
| 573 | #if _LIBCPP_STD_VER >= 23 |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 574 | template <_ContainerCompatibleRange<_Tp> _Range> |
| 575 | _LIBCPP_HIDE_FROM_ABI priority_queue(from_range_t, _Range&& __range, const value_compare& __comp = value_compare()) |
| 576 | : c(from_range, std::forward<_Range>(__range)), comp(__comp) { |
| 577 | std::make_heap(c.begin(), c.end(), comp); |
| 578 | } |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 579 | #endif |
| 580 | |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 581 | template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0> |
| 582 | _LIBCPP_HIDE_FROM_ABI explicit priority_queue(const _Alloc& __a); |
| 583 | |
| 584 | template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0> |
| 585 | _LIBCPP_HIDE_FROM_ABI priority_queue(const value_compare& __comp, const _Alloc& __a); |
| 586 | |
| 587 | template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0> |
| 588 | _LIBCPP_HIDE_FROM_ABI priority_queue(const value_compare& __comp, const container_type& __c, const _Alloc& __a); |
| 589 | |
| 590 | template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0> |
| 591 | _LIBCPP_HIDE_FROM_ABI priority_queue(const priority_queue& __q, const _Alloc& __a); |
| 592 | |
Eric Fiselier | f5427b2 | 2017-04-18 21:23:18 | [diff] [blame] | 593 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 594 | template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0> |
| 595 | _LIBCPP_HIDE_FROM_ABI priority_queue(const value_compare& __comp, container_type&& __c, const _Alloc& __a); |
| 596 | |
| 597 | template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0> |
| 598 | _LIBCPP_HIDE_FROM_ABI priority_queue(priority_queue&& __q, const _Alloc& __a); |
Louis Dionne | 4cd6ca1 | 2021-04-20 16:03:32 | [diff] [blame] | 599 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 600 | |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 601 | template < |
| 602 | class _InputIter, |
| 603 | class _Alloc, |
| 604 | __enable_if_t<__has_input_iterator_category<_InputIter>::value && uses_allocator<container_type, _Alloc>::value, |
| 605 | int> = 0> |
| 606 | _LIBCPP_HIDE_FROM_ABI priority_queue(_InputIter __f, _InputIter __l, const _Alloc& __a); |
Arthur O'Dwyer | 3894a8a | 2021-03-02 05:23:21 | [diff] [blame] | 607 | |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 608 | template < |
| 609 | class _InputIter, |
| 610 | class _Alloc, |
| 611 | __enable_if_t<__has_input_iterator_category<_InputIter>::value && uses_allocator<container_type, _Alloc>::value, |
| 612 | int> = 0> |
| 613 | _LIBCPP_HIDE_FROM_ABI priority_queue(_InputIter __f, _InputIter __l, const value_compare& __comp, const _Alloc& __a); |
Arthur O'Dwyer | 3894a8a | 2021-03-02 05:23:21 | [diff] [blame] | 614 | |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 615 | template < |
| 616 | class _InputIter, |
| 617 | class _Alloc, |
| 618 | __enable_if_t<__has_input_iterator_category<_InputIter>::value && uses_allocator<container_type, _Alloc>::value, |
| 619 | int> = 0> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 620 | _LIBCPP_HIDE_FROM_ABI priority_queue( |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 621 | _InputIter __f, _InputIter __l, const value_compare& __comp, const container_type& __c, const _Alloc& __a); |
Arthur O'Dwyer | 3894a8a | 2021-03-02 05:23:21 | [diff] [blame] | 622 | |
| 623 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 624 | template < |
| 625 | class _InputIter, |
| 626 | class _Alloc, |
| 627 | __enable_if_t<__has_input_iterator_category<_InputIter>::value && uses_allocator<container_type, _Alloc>::value, |
| 628 | int> = 0> |
| 629 | _LIBCPP_HIDE_FROM_ABI |
| 630 | priority_queue(_InputIter __f, _InputIter __l, const value_compare& __comp, container_type&& __c, const _Alloc& __a); |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 631 | #endif // _LIBCPP_CXX03_LANG |
Arthur O'Dwyer | 3894a8a | 2021-03-02 05:23:21 | [diff] [blame] | 632 | |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 633 | #if _LIBCPP_STD_VER >= 23 |
| 634 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 635 | template <_ContainerCompatibleRange<_Tp> _Range, |
| 636 | class _Alloc, |
| 637 | class = enable_if_t<uses_allocator<_Container, _Alloc>::value>> |
| 638 | _LIBCPP_HIDE_FROM_ABI priority_queue(from_range_t, _Range&& __range, const value_compare& __comp, const _Alloc& __a) |
| 639 | : c(from_range, std::forward<_Range>(__range), __a), comp(__comp) { |
| 640 | std::make_heap(c.begin(), c.end(), comp); |
| 641 | } |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 642 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 643 | template <_ContainerCompatibleRange<_Tp> _Range, |
| 644 | class _Alloc, |
| 645 | class = enable_if_t<uses_allocator<_Container, _Alloc>::value>> |
| 646 | _LIBCPP_HIDE_FROM_ABI priority_queue(from_range_t, _Range&& __range, const _Alloc& __a) |
| 647 | : c(from_range, std::forward<_Range>(__range), __a), comp() { |
| 648 | std::make_heap(c.begin(), c.end(), comp); |
| 649 | } |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 650 | |
| 651 | #endif |
| 652 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 653 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI bool empty() const { return c.empty(); } |
| 654 | _LIBCPP_HIDE_FROM_ABI size_type size() const { return c.size(); } |
| 655 | _LIBCPP_HIDE_FROM_ABI const_reference top() const { return c.front(); } |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 656 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 657 | _LIBCPP_HIDE_FROM_ABI void push(const value_type& __v); |
Eric Fiselier | f5427b2 | 2017-04-18 21:23:18 | [diff] [blame] | 658 | #ifndef _LIBCPP_CXX03_LANG |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 659 | _LIBCPP_HIDE_FROM_ABI void push(value_type&& __v); |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 660 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 661 | # if _LIBCPP_STD_VER >= 23 |
| 662 | template <_ContainerCompatibleRange<_Tp> _Range> |
| 663 | _LIBCPP_HIDE_FROM_ABI void push_range(_Range&& __range) { |
| 664 | if constexpr (requires(container_type& __c) { __c.append_range(std::forward<_Range>(__range)); }) { |
| 665 | c.append_range(std::forward<_Range>(__range)); |
| 666 | } else { |
| 667 | ranges::copy(std::forward<_Range>(__range), std::back_inserter(c)); |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 668 | } |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 669 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 670 | std::make_heap(c.begin(), c.end(), comp); |
| 671 | } |
| 672 | # endif |
| 673 | |
| 674 | template <class... _Args> |
| 675 | _LIBCPP_HIDE_FROM_ABI void emplace(_Args&&... __args); |
Louis Dionne | 4cd6ca1 | 2021-04-20 16:03:32 | [diff] [blame] | 676 | #endif // _LIBCPP_CXX03_LANG |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 677 | _LIBCPP_HIDE_FROM_ABI void pop(); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 678 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 679 | _LIBCPP_HIDE_FROM_ABI void swap(priority_queue& __q) |
| 680 | _NOEXCEPT_(__is_nothrow_swappable<container_type>::value&& __is_nothrow_swappable<value_compare>::value); |
Mark de Wever | 04d4f4b | 2022-05-05 16:57:32 | [diff] [blame] | 681 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 682 | _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI const _Container& __get_container() const { return c; } |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 683 | }; |
| 684 | |
Louis Dionne | 0166690 | 2021-08-17 15:59:07 | [diff] [blame] | 685 | #if _LIBCPP_STD_VER >= 17 |
Marshall Clow | 5b8b8b5 | 2018-05-22 01:57:53 | [diff] [blame] | 686 | template <class _Compare, |
| 687 | class _Container, |
Louis Dionne | 4e0ea2c | 2021-08-17 16:26:09 | [diff] [blame] | 688 | class = enable_if_t<!__is_allocator<_Compare>::value>, |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 689 | class = enable_if_t<!__is_allocator<_Container>::value> > |
| 690 | priority_queue(_Compare, _Container) -> priority_queue<typename _Container::value_type, _Container, _Compare>; |
Louis Dionne | a2a1ec2 | 2019-05-29 16:01:36 | [diff] [blame] | 691 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 692 | template <class _InputIterator, |
| 693 | class _Compare = less<__iter_value_type<_InputIterator>>, |
| 694 | class _Container = vector<__iter_value_type<_InputIterator>>, |
| 695 | class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>, |
| 696 | class = enable_if_t<!__is_allocator<_Compare>::value>, |
| 697 | class = enable_if_t<!__is_allocator<_Container>::value> > |
Marshall Clow | 5b8b8b5 | 2018-05-22 01:57:53 | [diff] [blame] | 698 | priority_queue(_InputIterator, _InputIterator, _Compare = _Compare(), _Container = _Container()) |
Arthur O'Dwyer | 199d2eb | 2021-03-04 04:02:20 | [diff] [blame] | 699 | -> priority_queue<__iter_value_type<_InputIterator>, _Container, _Compare>; |
Louis Dionne | a2a1ec2 | 2019-05-29 16:01:36 | [diff] [blame] | 700 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 701 | template <class _Compare, |
| 702 | class _Container, |
| 703 | class _Alloc, |
| 704 | class = enable_if_t<!__is_allocator<_Compare>::value>, |
| 705 | class = enable_if_t<!__is_allocator<_Container>::value>, |
| 706 | class = enable_if_t<uses_allocator<_Container, _Alloc>::value> > |
| 707 | priority_queue(_Compare, _Container, _Alloc) -> priority_queue<typename _Container::value_type, _Container, _Compare>; |
Arthur O'Dwyer | 3894a8a | 2021-03-02 05:23:21 | [diff] [blame] | 708 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 709 | template <class _InputIterator, |
| 710 | class _Allocator, |
| 711 | class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>, |
| 712 | class = enable_if_t<__is_allocator<_Allocator>::value> > |
Arthur O'Dwyer | 3894a8a | 2021-03-02 05:23:21 | [diff] [blame] | 713 | priority_queue(_InputIterator, _InputIterator, _Allocator) |
| 714 | -> priority_queue<__iter_value_type<_InputIterator>, |
| 715 | vector<__iter_value_type<_InputIterator>, _Allocator>, |
| 716 | less<__iter_value_type<_InputIterator>>>; |
| 717 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 718 | template <class _InputIterator, |
| 719 | class _Compare, |
| 720 | class _Allocator, |
| 721 | class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>, |
| 722 | class = enable_if_t<!__is_allocator<_Compare>::value>, |
| 723 | class = enable_if_t<__is_allocator<_Allocator>::value> > |
Arthur O'Dwyer | 3894a8a | 2021-03-02 05:23:21 | [diff] [blame] | 724 | priority_queue(_InputIterator, _InputIterator, _Compare, _Allocator) |
| 725 | -> priority_queue<__iter_value_type<_InputIterator>, |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 726 | vector<__iter_value_type<_InputIterator>, _Allocator>, |
| 727 | _Compare>; |
Arthur O'Dwyer | 3894a8a | 2021-03-02 05:23:21 | [diff] [blame] | 728 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 729 | template <class _InputIterator, |
| 730 | class _Compare, |
| 731 | class _Container, |
| 732 | class _Alloc, |
| 733 | class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>, |
| 734 | class = enable_if_t<!__is_allocator<_Compare>::value>, |
| 735 | class = enable_if_t<!__is_allocator<_Container>::value>, |
| 736 | class = enable_if_t<uses_allocator<_Container, _Alloc>::value> > |
Arthur O'Dwyer | 3894a8a | 2021-03-02 05:23:21 | [diff] [blame] | 737 | priority_queue(_InputIterator, _InputIterator, _Compare, _Container, _Alloc) |
| 738 | -> priority_queue<typename _Container::value_type, _Container, _Compare>; |
Marshall Clow | 5b8b8b5 | 2018-05-22 01:57:53 | [diff] [blame] | 739 | #endif |
| 740 | |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 741 | #if _LIBCPP_STD_VER >= 23 |
| 742 | |
| 743 | template <ranges::input_range _Range, |
| 744 | class _Compare = less<ranges::range_value_t<_Range>>, |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 745 | class = enable_if_t<!__is_allocator<_Compare>::value>> |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 746 | priority_queue(from_range_t, _Range&&, _Compare = _Compare()) |
| 747 | -> priority_queue<ranges::range_value_t<_Range>, vector<ranges::range_value_t<_Range>>, _Compare>; |
| 748 | |
| 749 | template <ranges::input_range _Range, |
| 750 | class _Compare, |
| 751 | class _Alloc, |
| 752 | class = enable_if_t<!__is_allocator<_Compare>::value>, |
| 753 | class = enable_if_t<__is_allocator<_Alloc>::value>> |
| 754 | priority_queue(from_range_t, _Range&&, _Compare, _Alloc) |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 755 | -> priority_queue<ranges::range_value_t<_Range>, vector<ranges::range_value_t<_Range>, _Alloc>, _Compare>; |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 756 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 757 | template <ranges::input_range _Range, class _Alloc, class = enable_if_t<__is_allocator<_Alloc>::value>> |
varconst | 87f3ff3 | 2023-06-03 02:23:29 | [diff] [blame] | 758 | priority_queue(from_range_t, _Range&&, _Alloc) |
| 759 | -> priority_queue<ranges::range_value_t<_Range>, vector<ranges::range_value_t<_Range>, _Alloc>>; |
| 760 | |
| 761 | #endif |
| 762 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 763 | template <class _Tp, class _Container, class _Compare> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 764 | inline priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Compare& __comp, const container_type& __c) |
| 765 | : c(__c), comp(__comp) { |
| 766 | std::make_heap(c.begin(), c.end(), comp); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 767 | } |
| 768 | |
Eric Fiselier | f5427b2 | 2017-04-18 21:23:18 | [diff] [blame] | 769 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 770 | |
| 771 | template <class _Tp, class _Container, class _Compare> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 772 | inline priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp, container_type&& __c) |
| 773 | : c(std::move(__c)), comp(__comp) { |
| 774 | std::make_heap(c.begin(), c.end(), comp); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 775 | } |
| 776 | |
Louis Dionne | 4cd6ca1 | 2021-04-20 16:03:32 | [diff] [blame] | 777 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 778 | |
| 779 | template <class _Tp, class _Container, class _Compare> |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 780 | template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> > |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 781 | inline priority_queue<_Tp, _Container, _Compare>::priority_queue( |
| 782 | _InputIter __f, _InputIter __l, const value_compare& __comp) |
| 783 | : c(__f, __l), comp(__comp) { |
| 784 | std::make_heap(c.begin(), c.end(), comp); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | template <class _Tp, class _Container, class _Compare> |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 788 | template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> > |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 789 | inline priority_queue<_Tp, _Container, _Compare>::priority_queue( |
| 790 | _InputIter __f, _InputIter __l, const value_compare& __comp, const container_type& __c) |
| 791 | : c(__c), comp(__comp) { |
| 792 | c.insert(c.end(), __f, __l); |
| 793 | std::make_heap(c.begin(), c.end(), comp); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 794 | } |
| 795 | |
Eric Fiselier | f5427b2 | 2017-04-18 21:23:18 | [diff] [blame] | 796 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 797 | |
| 798 | template <class _Tp, class _Container, class _Compare> |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 799 | template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> > |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 800 | inline priority_queue<_Tp, _Container, _Compare>::priority_queue( |
| 801 | _InputIter __f, _InputIter __l, const value_compare& __comp, container_type&& __c) |
| 802 | : c(std::move(__c)), comp(__comp) { |
| 803 | c.insert(c.end(), __f, __l); |
| 804 | std::make_heap(c.begin(), c.end(), comp); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 805 | } |
| 806 | |
Louis Dionne | 4cd6ca1 | 2021-04-20 16:03:32 | [diff] [blame] | 807 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 808 | |
| 809 | template <class _Tp, class _Container, class _Compare> |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 810 | template <class _Alloc, __enable_if_t<uses_allocator<_Container, _Alloc>::value, int> > |
| 811 | inline priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Alloc& __a) : c(__a) {} |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 812 | |
| 813 | template <class _Tp, class _Container, class _Compare> |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 814 | template <class _Alloc, __enable_if_t<uses_allocator<_Container, _Alloc>::value, int> > |
| 815 | inline priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp, const _Alloc& __a) |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 816 | : c(__a), comp(__comp) {} |
| 817 | |
| 818 | template <class _Tp, class _Container, class _Compare> |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 819 | template <class _Alloc, __enable_if_t<uses_allocator<_Container, _Alloc>::value, int> > |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 820 | inline priority_queue<_Tp, _Container, _Compare>::priority_queue( |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 821 | const value_compare& __comp, const container_type& __c, const _Alloc& __a) |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 822 | : c(__c, __a), comp(__comp) { |
| 823 | std::make_heap(c.begin(), c.end(), comp); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | template <class _Tp, class _Container, class _Compare> |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 827 | template <class _Alloc, __enable_if_t<uses_allocator<_Container, _Alloc>::value, int> > |
| 828 | inline priority_queue<_Tp, _Container, _Compare>::priority_queue(const priority_queue& __q, const _Alloc& __a) |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 829 | : c(__q.c, __a), comp(__q.comp) {} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 830 | |
Eric Fiselier | f5427b2 | 2017-04-18 21:23:18 | [diff] [blame] | 831 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 832 | |
| 833 | template <class _Tp, class _Container, class _Compare> |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 834 | template <class _Alloc, __enable_if_t<uses_allocator<_Container, _Alloc>::value, int> > |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 835 | inline priority_queue<_Tp, _Container, _Compare>::priority_queue( |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 836 | const value_compare& __comp, container_type&& __c, const _Alloc& __a) |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 837 | : c(std::move(__c), __a), comp(__comp) { |
| 838 | std::make_heap(c.begin(), c.end(), comp); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 839 | } |
| 840 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 841 | template <class _Tp, class _Container, class _Compare> |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 842 | template <class _Alloc, __enable_if_t<uses_allocator<_Container, _Alloc>::value, int> > |
| 843 | inline priority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q, const _Alloc& __a) |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 844 | : c(std::move(__q.c), __a), comp(std::move(__q.comp)) {} |
Arthur O'Dwyer | 3894a8a | 2021-03-02 05:23:21 | [diff] [blame] | 845 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 846 | #endif // _LIBCPP_CXX03_LANG |
Arthur O'Dwyer | 3894a8a | 2021-03-02 05:23:21 | [diff] [blame] | 847 | |
| 848 | template <class _Tp, class _Container, class _Compare> |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 849 | template < |
| 850 | class _InputIter, |
| 851 | class _Alloc, |
| 852 | __enable_if_t<__has_input_iterator_category<_InputIter>::value && uses_allocator<_Container, _Alloc>::value, int> > |
| 853 | inline priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l, const _Alloc& __a) |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 854 | : c(__f, __l, __a), comp() { |
| 855 | std::make_heap(c.begin(), c.end(), comp); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 856 | } |
| 857 | |
Arthur O'Dwyer | 3894a8a | 2021-03-02 05:23:21 | [diff] [blame] | 858 | template <class _Tp, class _Container, class _Compare> |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 859 | template < |
| 860 | class _InputIter, |
| 861 | class _Alloc, |
| 862 | __enable_if_t<__has_input_iterator_category<_InputIter>::value && uses_allocator<_Container, _Alloc>::value, int> > |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 863 | inline priority_queue<_Tp, _Container, _Compare>::priority_queue( |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 864 | _InputIter __f, _InputIter __l, const value_compare& __comp, const _Alloc& __a) |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 865 | : c(__f, __l, __a), comp(__comp) { |
| 866 | std::make_heap(c.begin(), c.end(), comp); |
Arthur O'Dwyer | 3894a8a | 2021-03-02 05:23:21 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | template <class _Tp, class _Container, class _Compare> |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 870 | template < |
| 871 | class _InputIter, |
| 872 | class _Alloc, |
| 873 | __enable_if_t<__has_input_iterator_category<_InputIter>::value && uses_allocator<_Container, _Alloc>::value, int> > |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 874 | inline priority_queue<_Tp, _Container, _Compare>::priority_queue( |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 875 | _InputIter __f, _InputIter __l, const value_compare& __comp, const container_type& __c, const _Alloc& __a) |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 876 | : c(__c, __a), comp(__comp) { |
| 877 | c.insert(c.end(), __f, __l); |
| 878 | std::make_heap(c.begin(), c.end(), comp); |
Arthur O'Dwyer | 3894a8a | 2021-03-02 05:23:21 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | #ifndef _LIBCPP_CXX03_LANG |
| 882 | template <class _Tp, class _Container, class _Compare> |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 883 | template < |
| 884 | class _InputIter, |
| 885 | class _Alloc, |
| 886 | __enable_if_t<__has_input_iterator_category<_InputIter>::value && uses_allocator<_Container, _Alloc>::value, int> > |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 887 | inline priority_queue<_Tp, _Container, _Compare>::priority_queue( |
Nikolas Klauser | 76a2472 | 2024-02-20 00:47:38 | [diff] [blame] | 888 | _InputIter __f, _InputIter __l, const value_compare& __comp, container_type&& __c, const _Alloc& __a) |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 889 | : c(std::move(__c), __a), comp(__comp) { |
| 890 | c.insert(c.end(), __f, __l); |
| 891 | std::make_heap(c.begin(), c.end(), comp); |
Arthur O'Dwyer | 3894a8a | 2021-03-02 05:23:21 | [diff] [blame] | 892 | } |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 893 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 894 | |
| 895 | template <class _Tp, class _Container, class _Compare> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 896 | inline void priority_queue<_Tp, _Container, _Compare>::push(const value_type& __v) { |
| 897 | c.push_back(__v); |
| 898 | std::push_heap(c.begin(), c.end(), comp); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 899 | } |
| 900 | |
Eric Fiselier | f5427b2 | 2017-04-18 21:23:18 | [diff] [blame] | 901 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 902 | |
| 903 | template <class _Tp, class _Container, class _Compare> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 904 | inline void priority_queue<_Tp, _Container, _Compare>::push(value_type&& __v) { |
| 905 | c.push_back(std::move(__v)); |
| 906 | std::push_heap(c.begin(), c.end(), comp); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | template <class _Tp, class _Container, class _Compare> |
| 910 | template <class... _Args> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 911 | inline void priority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args) { |
| 912 | c.emplace_back(std::forward<_Args>(__args)...); |
| 913 | std::push_heap(c.begin(), c.end(), comp); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 914 | } |
| 915 | |
Louis Dionne | 4cd6ca1 | 2021-04-20 16:03:32 | [diff] [blame] | 916 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 917 | |
| 918 | template <class _Tp, class _Container, class _Compare> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 919 | inline void priority_queue<_Tp, _Container, _Compare>::pop() { |
| 920 | std::pop_heap(c.begin(), c.end(), comp); |
| 921 | c.pop_back(); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | template <class _Tp, class _Container, class _Compare> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 925 | inline void priority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q) |
| 926 | _NOEXCEPT_(__is_nothrow_swappable<container_type>::value&& __is_nothrow_swappable<value_compare>::value) { |
| 927 | using std::swap; |
| 928 | swap(c, __q.c); |
| 929 | swap(comp, __q.comp); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 930 | } |
| 931 | |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 932 | template <class _Tp, |
| 933 | class _Container, |
| 934 | class _Compare, |
Nikolas Klauser | 9f3e3ef | 2023-09-02 00:52:02 | [diff] [blame] | 935 | __enable_if_t<__is_swappable<_Container>::value && __is_swappable<_Compare>::value, int> = 0> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 936 | inline _LIBCPP_HIDE_FROM_ABI void |
| 937 | swap(priority_queue<_Tp, _Container, _Compare>& __x, priority_queue<_Tp, _Container, _Compare>& __y) |
| 938 | _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) { |
| 939 | __x.swap(__y); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | template <class _Tp, class _Container, class _Compare, class _Alloc> |
Eric Fiselier | e2f2d1ed | 2017-01-04 23:56:00 | [diff] [blame] | 943 | struct _LIBCPP_TEMPLATE_VIS uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc> |
Louis Dionne | 9783f28 | 2023-12-18 19:01:33 | [diff] [blame] | 944 | : public uses_allocator<_Container, _Alloc> {}; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 945 | |
| 946 | _LIBCPP_END_NAMESPACE_STD |
| 947 | |
Louis Dionne | 7b46225 | 2024-01-25 20:48:46 | [diff] [blame] | 948 | _LIBCPP_POP_MACROS |
| 949 | |
Nikolas Klauser | d5e2677 | 2022-09-04 22:01:15 | [diff] [blame] | 950 | #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 |
Nikolas Klauser | 89b356f | 2022-11-02 19:27:42 | [diff] [blame] | 951 | # include <concepts> |
Nikolas Klauser | 75196f8 | 2023-01-08 15:47:53 | [diff] [blame] | 952 | # include <cstdlib> |
Mark de Wever | e31c2a1 | 2022-09-02 15:53:28 | [diff] [blame] | 953 | # include <functional> |
Nikolas Klauser | 0a4aa8a | 2023-02-12 11:32:36 | [diff] [blame] | 954 | # include <type_traits> |
Mark de Wever | e31c2a1 | 2022-09-02 15:53:28 | [diff] [blame] | 955 | #endif |
| 956 | |
Louis Dionne | 4cd6ca1 | 2021-04-20 16:03:32 | [diff] [blame] | 957 | #endif // _LIBCPP_QUEUE |