2010-05-11 19:42:16 +00:00
|
|
|
// -*- C++ -*-
|
2021-11-17 21:25:01 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2010-05-11 19:42:16 +00:00
|
|
|
//
|
2019-01-19 10:56:40 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-05-11 19:42:16 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_QUEUE
|
|
|
|
#define _LIBCPP_QUEUE
|
|
|
|
|
|
|
|
/*
|
|
|
|
queue synopsis
|
|
|
|
|
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
|
|
|
|
template <class T, class Container = deque<T>>
|
|
|
|
class queue
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef Container container_type;
|
|
|
|
typedef typename container_type::value_type value_type;
|
|
|
|
typedef typename container_type::reference reference;
|
|
|
|
typedef typename container_type::const_reference const_reference;
|
|
|
|
typedef typename container_type::size_type size_type;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
container_type c;
|
|
|
|
|
|
|
|
public:
|
2011-06-04 21:32:33 +00:00
|
|
|
queue() = default;
|
|
|
|
~queue() = default;
|
|
|
|
|
|
|
|
queue(const queue& q) = default;
|
|
|
|
queue(queue&& q) = default;
|
|
|
|
|
|
|
|
queue& operator=(const queue& q) = default;
|
|
|
|
queue& operator=(queue&& q) = default;
|
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
explicit queue(const container_type& c);
|
2011-06-04 21:32:33 +00:00
|
|
|
explicit queue(container_type&& c)
|
2022-01-06 11:36:07 +00:00
|
|
|
template<class InputIterator>
|
|
|
|
queue(InputIterator first, InputIterator last); // since C++23
|
2023-06-03 02:23:29 +00:00
|
|
|
template<container-compatible-range<T> R> queue(from_range_t, R&& rg); // since C++23
|
2010-05-11 19:42:16 +00:00
|
|
|
template <class Alloc>
|
|
|
|
explicit queue(const Alloc& a);
|
|
|
|
template <class Alloc>
|
|
|
|
queue(const container_type& c, const Alloc& a);
|
|
|
|
template <class Alloc>
|
|
|
|
queue(container_type&& c, const Alloc& a);
|
2011-06-04 21:32:33 +00:00
|
|
|
template <class Alloc>
|
|
|
|
queue(const queue& q, const Alloc& a);
|
2010-05-11 19:42:16 +00:00
|
|
|
template <class Alloc>
|
|
|
|
queue(queue&& q, const Alloc& a);
|
2022-01-06 11:36:07 +00:00
|
|
|
template <class InputIterator, class Alloc>
|
|
|
|
queue(InputIterator first, InputIterator last, const Alloc&); // since C++23
|
2023-06-03 02:23:29 +00:00
|
|
|
template<container-compatible-range<T> R, class Alloc>
|
|
|
|
queue(from_range_t, R&& rg, const Alloc&); // since C++23
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
bool empty() const;
|
|
|
|
size_type size() const;
|
|
|
|
|
|
|
|
reference front();
|
|
|
|
const_reference front() const;
|
|
|
|
reference back();
|
|
|
|
const_reference back() const;
|
|
|
|
|
|
|
|
void push(const value_type& v);
|
|
|
|
void push(value_type&& v);
|
2023-06-03 02:23:29 +00:00
|
|
|
template<container-compatible-range<T> R>
|
|
|
|
void push_range(R&& rg); // C++23
|
2017-01-24 23:09:12 +00:00
|
|
|
template <class... Args> reference emplace(Args&&... args); // reference in C++17
|
2010-05-11 19:42:16 +00:00
|
|
|
void pop();
|
|
|
|
|
2016-04-21 23:38:59 +00:00
|
|
|
void swap(queue& q) noexcept(is_nothrow_swappable_v<Container>)
|
2010-05-11 19:42:16 +00:00
|
|
|
};
|
|
|
|
|
2018-05-22 01:57:53 +00:00
|
|
|
template<class Container>
|
|
|
|
queue(Container) -> queue<typename Container::value_type, Container>; // C++17
|
2019-05-29 16:01:36 +00:00
|
|
|
|
2022-01-06 11:36:07 +00:00
|
|
|
template<class InputIterator>
|
|
|
|
queue(InputIterator, InputIterator) -> queue<iter-value-type<InputIterator>>; // since C++23
|
|
|
|
|
2023-06-03 02:23:29 +00:00
|
|
|
template<ranges::input_range R>
|
|
|
|
queue(from_range_t, R&&) -> queue<ranges::range_value_t<R>>; // since C++23
|
|
|
|
|
2019-05-29 16:01:36 +00:00
|
|
|
template<class Container, class Allocator>
|
2018-05-22 01:57:53 +00:00
|
|
|
queue(Container, Allocator) -> queue<typename Container::value_type, Container>; // C++17
|
|
|
|
|
2022-01-06 11:36:07 +00:00
|
|
|
template<class InputIterator, class Allocator>
|
|
|
|
queue(InputIterator, InputIterator, Allocator)
|
|
|
|
-> queue<iter-value-type<InputIterator>,
|
|
|
|
deque<iter-value-type<InputIterator>, Allocator>>; // since C++23
|
|
|
|
|
2023-06-03 02:23:29 +00:00
|
|
|
template<ranges::input_range R, class Allocator>
|
|
|
|
queue(from_range_t, R&&, Allocator)
|
|
|
|
-> queue<ranges::range_value_t<R>, deque<ranges::range_value_t<R>, Allocator>>; // since C++23
|
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
template <class T, class Container>
|
|
|
|
bool operator==(const queue<T, Container>& x,const queue<T, Container>& y);
|
|
|
|
|
|
|
|
template <class T, class Container>
|
|
|
|
bool operator< (const queue<T, Container>& x,const queue<T, Container>& y);
|
|
|
|
|
|
|
|
template <class T, class Container>
|
|
|
|
bool operator!=(const queue<T, Container>& x,const queue<T, Container>& y);
|
|
|
|
|
|
|
|
template <class T, class Container>
|
|
|
|
bool operator> (const queue<T, Container>& x,const queue<T, Container>& y);
|
|
|
|
|
|
|
|
template <class T, class Container>
|
|
|
|
bool operator>=(const queue<T, Container>& x,const queue<T, Container>& y);
|
|
|
|
|
|
|
|
template <class T, class Container>
|
|
|
|
bool operator<=(const queue<T, Container>& x,const queue<T, Container>& y);
|
|
|
|
|
2023-03-14 16:32:15 +00:00
|
|
|
template<class T, three_way_comparable Container>
|
|
|
|
compare_three_way_result_t<Container>
|
|
|
|
operator<=>(const queue<T, Container>& x, const queue<T, Container>& y); // since C++20
|
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
template <class T, class Container>
|
2011-06-04 21:32:33 +00:00
|
|
|
void swap(queue<T, Container>& x, queue<T, Container>& y)
|
|
|
|
noexcept(noexcept(x.swap(y)));
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
template <class T, class Container = vector<T>,
|
|
|
|
class Compare = less<typename Container::value_type>>
|
|
|
|
class priority_queue
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef Container container_type;
|
|
|
|
typedef typename container_type::value_type value_type;
|
|
|
|
typedef typename container_type::reference reference;
|
|
|
|
typedef typename container_type::const_reference const_reference;
|
|
|
|
typedef typename container_type::size_type size_type;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
container_type c;
|
|
|
|
Compare comp;
|
|
|
|
|
|
|
|
public:
|
2021-01-19 07:21:09 +00:00
|
|
|
priority_queue() : priority_queue(Compare()) {} // C++20
|
|
|
|
explicit priority_queue(const Compare& x) : priority_queue(x, Container()) {}
|
|
|
|
priority_queue(const Compare& x, const Container&);
|
2021-03-02 05:23:21 +00:00
|
|
|
explicit priority_queue(const Compare& x = Compare(), Container&& = Container()); // before C++20
|
2021-01-19 07:21:09 +00:00
|
|
|
priority_queue(const Compare& x, Container&&); // C++20
|
2010-05-11 19:42:16 +00:00
|
|
|
template <class InputIterator>
|
|
|
|
priority_queue(InputIterator first, InputIterator last,
|
|
|
|
const Compare& comp = Compare());
|
|
|
|
template <class InputIterator>
|
|
|
|
priority_queue(InputIterator first, InputIterator last,
|
2021-03-02 05:23:21 +00:00
|
|
|
const Compare& comp, const Container& c);
|
2010-05-11 19:42:16 +00:00
|
|
|
template <class InputIterator>
|
|
|
|
priority_queue(InputIterator first, InputIterator last,
|
2021-03-02 05:23:21 +00:00
|
|
|
const Compare& comp, Container&& c);
|
2023-06-03 02:23:29 +00:00
|
|
|
template <container-compatible-range<T> R>
|
|
|
|
priority_queue(from_range_t, R&& rg, const Compare& x = Compare()); // since C++23
|
2010-05-11 19:42:16 +00:00
|
|
|
template <class Alloc>
|
|
|
|
explicit priority_queue(const Alloc& a);
|
|
|
|
template <class Alloc>
|
|
|
|
priority_queue(const Compare& comp, const Alloc& a);
|
|
|
|
template <class Alloc>
|
2021-03-02 05:23:21 +00:00
|
|
|
priority_queue(const Compare& comp, const Container& c,
|
2010-05-11 19:42:16 +00:00
|
|
|
const Alloc& a);
|
|
|
|
template <class Alloc>
|
2021-03-02 05:23:21 +00:00
|
|
|
priority_queue(const Compare& comp, Container&& c,
|
2010-05-11 19:42:16 +00:00
|
|
|
const Alloc& a);
|
2021-03-02 05:23:21 +00:00
|
|
|
template <class InputIterator>
|
|
|
|
priority_queue(InputIterator first, InputIterator last,
|
|
|
|
const Alloc& a);
|
|
|
|
template <class InputIterator>
|
|
|
|
priority_queue(InputIterator first, InputIterator last,
|
|
|
|
const Compare& comp, const Alloc& a);
|
|
|
|
template <class InputIterator>
|
|
|
|
priority_queue(InputIterator first, InputIterator last,
|
|
|
|
const Compare& comp, const Container& c, const Alloc& a);
|
|
|
|
template <class InputIterator>
|
|
|
|
priority_queue(InputIterator first, InputIterator last,
|
|
|
|
const Compare& comp, Container&& c, const Alloc& a);
|
2023-06-03 02:23:29 +00:00
|
|
|
template <container-compatible-range<T> R, class Alloc>
|
|
|
|
priority_queue(from_range_t, R&& rg, const Compare&, const Alloc&); // since C++23
|
|
|
|
template <container-compatible-range<T> R, class Alloc>
|
|
|
|
priority_queue(from_range_t, R&& rg, const Alloc&); // since C++23
|
2011-06-04 21:32:33 +00:00
|
|
|
template <class Alloc>
|
|
|
|
priority_queue(const priority_queue& q, const Alloc& a);
|
2010-05-11 19:42:16 +00:00
|
|
|
template <class Alloc>
|
|
|
|
priority_queue(priority_queue&& q, const Alloc& a);
|
|
|
|
|
|
|
|
bool empty() const;
|
|
|
|
size_type size() const;
|
|
|
|
const_reference top() const;
|
|
|
|
|
|
|
|
void push(const value_type& v);
|
|
|
|
void push(value_type&& v);
|
2023-06-03 02:23:29 +00:00
|
|
|
template<container-compatible-range<T> R>
|
|
|
|
void push_range(R&& rg); // C++23
|
2010-05-11 19:42:16 +00:00
|
|
|
template <class... Args> void emplace(Args&&... args);
|
|
|
|
void pop();
|
|
|
|
|
2011-06-04 21:32:33 +00:00
|
|
|
void swap(priority_queue& q)
|
2016-04-21 23:38:59 +00:00
|
|
|
noexcept(is_nothrow_swappable_v<Container> &&
|
|
|
|
is_nothrow_swappable_v<Comp>)
|
2010-05-11 19:42:16 +00:00
|
|
|
};
|
|
|
|
|
2018-05-22 01:57:53 +00:00
|
|
|
template <class Compare, class Container>
|
|
|
|
priority_queue(Compare, Container)
|
|
|
|
-> priority_queue<typename Container::value_type, Container, Compare>; // C++17
|
2019-05-29 16:01:36 +00:00
|
|
|
|
|
|
|
template<class InputIterator,
|
2021-03-02 05:23:21 +00:00
|
|
|
class Compare = less<iter-value-type<InputIterator>>,
|
|
|
|
class Container = vector<iter-value-type<InputIterator>>>
|
2018-05-22 01:57:53 +00:00
|
|
|
priority_queue(InputIterator, InputIterator, Compare = Compare(), Container = Container())
|
2021-03-02 05:23:21 +00:00
|
|
|
-> priority_queue<iter-value-type<InputIterator>, Container, Compare>; // C++17
|
2019-05-29 16:01:36 +00:00
|
|
|
|
2023-06-03 02:23:29 +00:00
|
|
|
template<ranges::input_range R, class Compare = less<ranges::range_value_t<R>>>
|
|
|
|
priority_queue(from_range_t, R&&, Compare = Compare())
|
|
|
|
-> priority_queue<ranges::range_value_t<R>, vector<ranges::range_value_t<R>>, Compare>; // C++23
|
|
|
|
|
2018-05-22 01:57:53 +00:00
|
|
|
template<class Compare, class Container, class Allocator>
|
|
|
|
priority_queue(Compare, Container, Allocator)
|
|
|
|
-> priority_queue<typename Container::value_type, Container, Compare>; // C++17
|
|
|
|
|
2021-03-02 05:23:21 +00:00
|
|
|
template<class InputIterator, class Allocator>
|
|
|
|
priority_queue(InputIterator, InputIterator, Allocator)
|
|
|
|
-> priority_queue<iter-value-type<InputIterator>,
|
|
|
|
vector<iter-value-type<InputIterator>, Allocator>,
|
2021-11-09 17:21:02 +00:00
|
|
|
less<iter-value-type<InputIterator>>>; // C++17
|
2021-03-02 05:23:21 +00:00
|
|
|
|
|
|
|
template<class InputIterator, class Compare, class Allocator>
|
|
|
|
priority_queue(InputIterator, InputIterator, Compare, Allocator)
|
|
|
|
-> priority_queue<iter-value-type<InputIterator>,
|
2021-11-09 17:21:02 +00:00
|
|
|
vector<iter-value-type<InputIterator>, Allocator>, Compare>; // C++17
|
2021-03-02 05:23:21 +00:00
|
|
|
|
|
|
|
template<class InputIterator, class Compare, class Container, class Allocator>
|
|
|
|
priority_queue(InputIterator, InputIterator, Compare, Container, Allocator)
|
2021-11-09 17:21:02 +00:00
|
|
|
-> priority_queue<typename Container::value_type, Container, Compare>; // C++17
|
2021-03-02 05:23:21 +00:00
|
|
|
|
2023-06-03 02:23:29 +00:00
|
|
|
template<ranges::input_range R, class Compare, class Allocator>
|
|
|
|
priority_queue(from_range_t, R&&, Compare, Allocator)
|
|
|
|
-> priority_queue<ranges::range_value_t<R>, vector<ranges::range_value_t<R>, Allocator>,
|
|
|
|
Compare>; // C++23
|
|
|
|
|
|
|
|
template<ranges::input_range R, class Allocator>
|
|
|
|
priority_queue(from_range_t, R&&, Allocator)
|
|
|
|
-> priority_queue<ranges::range_value_t<R>, vector<ranges::range_value_t<R>, Allocator>>; // C++23
|
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
template <class T, class Container, class Compare>
|
|
|
|
void swap(priority_queue<T, Container, Compare>& x,
|
2011-06-04 21:32:33 +00:00
|
|
|
priority_queue<T, Container, Compare>& y)
|
|
|
|
noexcept(noexcept(x.swap(y)));
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
} // std
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2022-02-15 17:18:08 +00:00
|
|
|
#include <__algorithm/make_heap.h>
|
|
|
|
#include <__algorithm/pop_heap.h>
|
|
|
|
#include <__algorithm/push_heap.h>
|
2023-06-03 02:23:29 +00:00
|
|
|
#include <__algorithm/ranges_copy.h>
|
2022-03-25 16:55:36 +00:00
|
|
|
#include <__assert> // all public C++ headers provide the assertion handler
|
2010-05-11 19:42:16 +00:00
|
|
|
#include <__config>
|
2022-05-20 22:45:51 +00:00
|
|
|
#include <__functional/operations.h>
|
2023-06-03 02:23:29 +00:00
|
|
|
#include <__iterator/back_insert_iterator.h>
|
2022-01-06 11:36:07 +00:00
|
|
|
#include <__iterator/iterator_traits.h>
|
2021-07-01 13:25:35 +00:00
|
|
|
#include <__memory/uses_allocator.h>
|
2023-06-03 02:23:29 +00:00
|
|
|
#include <__ranges/access.h>
|
|
|
|
#include <__ranges/concepts.h>
|
|
|
|
#include <__ranges/container_compatible_range.h>
|
|
|
|
#include <__ranges/from_range.h>
|
2021-06-05 02:47:47 +00:00
|
|
|
#include <__utility/forward.h>
|
2010-05-11 19:42:16 +00:00
|
|
|
#include <deque>
|
2021-05-19 15:57:04 +00:00
|
|
|
#include <vector>
|
2021-12-22 17:14:14 +00:00
|
|
|
#include <version>
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2022-06-16 20:43:46 +00:00
|
|
|
// standard-mandated includes
|
2022-09-22 16:05:08 +00:00
|
|
|
|
|
|
|
// [queue.syn]
|
2022-06-16 20:43:46 +00:00
|
|
|
#include <compare>
|
|
|
|
#include <initializer_list>
|
|
|
|
|
2011-10-17 20:05:10 +00:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
2022-02-02 01:16:40 +00:00
|
|
|
# pragma GCC system_header
|
2011-10-17 20:05:10 +00:00
|
|
|
#endif
|
2010-05-11 19:42:16 +00:00
|
|
|
|
[🍒][libc++] Fix missing and incorrect push/pop macros (#79204) (#79497)
We recently noticed that the unwrap_iter.h file was pushing macros, but
it was pushing them again instead of popping them at the end of the
file. This led to libc++ basically swallowing any custom definition of
these macros in user code:
#define min HELLO
#include <algorithm>
// min is not HELLO anymore, it's not defined
While investigating this issue, I noticed that our push/pop pragmas were
actually entirely wrong too. Indeed, instead of pushing macros like
`move`, we'd push `move(int, int)` in the pragma, which is not a valid
macro name. As a result, we would not actually push macros like `move`
-- instead we'd simply undefine them. This led to the following code not
working:
#define move HELLO
#include <algorithm>
// move is not HELLO anymore
Fixing the pragma push/pop incantations led to a cascade of issues
because we use identifiers like `move` in a large number of places, and
all of these headers would now need to do the push/pop dance.
This patch fixes all these issues. First, it adds a check that we don't
swallow important names like min, max, move or refresh as explained
above. This is done by augmenting the existing
system_reserved_names.gen.py test to also check that the macros are what
we expect after including each header.
Second, it fixes the push/pop pragmas to work properly and adds missing
pragmas to all the files I could detect a failure in via the newly added
test.
rdar://121365472
(cherry picked from commit 7b4622514d232ce5f7110dd8b20d90e81127c467)
2024-02-02 01:51:34 +00:00
|
|
|
_LIBCPP_PUSH_MACROS
|
|
|
|
#include <__undef_macros>
|
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
|
|
|
|
2017-01-04 23:56:00 +00:00
|
|
|
template <class _Tp, class _Container = deque<_Tp> >
|
|
|
|
class _LIBCPP_TEMPLATE_VIS queue;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
template <class _Tp, class _Container>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI bool operator==(const queue<_Tp, _Container>& __x, const queue<_Tp, _Container>& __y);
|
|
|
|
|
|
|
|
template <class _Tp, class _Container>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI bool operator<(const queue<_Tp, _Container>& __x, const queue<_Tp, _Container>& __y);
|
|
|
|
|
2015-02-18 17:51:56 +00:00
|
|
|
template <class _Tp, class _Container /*= deque<_Tp>*/>
|
2017-01-04 23:56:00 +00:00
|
|
|
class _LIBCPP_TEMPLATE_VIS queue {
|
2010-05-11 19:42:16 +00:00
|
|
|
public:
|
|
|
|
typedef _Container container_type;
|
|
|
|
typedef typename container_type::value_type value_type;
|
|
|
|
typedef typename container_type::reference reference;
|
|
|
|
typedef typename container_type::const_reference const_reference;
|
|
|
|
typedef typename container_type::size_type size_type;
|
2016-03-14 17:58:11 +00:00
|
|
|
static_assert((is_same<_Tp, value_type>::value), "");
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
container_type c;
|
|
|
|
|
|
|
|
public:
|
2011-06-04 21:32:33 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI queue() _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value) : c() {}
|
|
|
|
|
|
|
|
_LIBCPP_HIDE_FROM_ABI queue(const queue& __q) : c(__q.c) {}
|
|
|
|
|
2023-02-13 23:56:09 +00:00
|
|
|
#if _LIBCPP_STD_VER >= 23
|
2023-05-17 17:34:51 +00:00
|
|
|
template <class _InputIterator, class = __enable_if_t<__has_input_iterator_category<_InputIterator>::value>>
|
2022-01-06 11:36:07 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI queue(_InputIterator __first, _InputIterator __last) : c(__first, __last) {}
|
2023-12-18 19:01:33 +00:00
|
|
|
|
2023-06-03 02:23:29 +00:00
|
|
|
template <_ContainerCompatibleRange<_Tp> _Range>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI queue(from_range_t, _Range&& __range) : c(from_range, std::forward<_Range>(__range)) {}
|
2023-12-18 19:01:33 +00:00
|
|
|
|
2022-01-06 11:36:07 +00:00
|
|
|
template <class _InputIterator,
|
|
|
|
class _Alloc,
|
2023-05-17 17:34:51 +00:00
|
|
|
class = __enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
|
2022-01-06 11:36:07 +00:00
|
|
|
class = __enable_if_t<uses_allocator<container_type, _Alloc>::value>>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI queue(_InputIterator __first, _InputIterator __second, const _Alloc& __alloc)
|
|
|
|
: c(__first, __second, __alloc) {}
|
2023-12-18 19:01:33 +00:00
|
|
|
|
2023-06-03 02:23:29 +00:00
|
|
|
template <_ContainerCompatibleRange<_Tp> _Range,
|
|
|
|
class _Alloc,
|
|
|
|
class = __enable_if_t<uses_allocator<container_type, _Alloc>::value>>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI queue(from_range_t, _Range&& __range, const _Alloc& __alloc)
|
|
|
|
: c(from_range, std::forward<_Range>(__range), __alloc) {}
|
|
|
|
|
2022-01-06 11:36:07 +00:00
|
|
|
#endif
|
|
|
|
|
2017-04-18 21:23:18 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI queue& operator=(const queue& __q) {
|
|
|
|
c = __q.c;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2011-06-04 21:32:33 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI queue(queue&& __q) _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value)
|
2011-06-30 21:18:19 +00:00
|
|
|
: c(std::move(__q.c)) {}
|
2023-12-18 19:01:33 +00:00
|
|
|
|
2011-06-04 21:32:33 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI queue& operator=(queue&& __q) _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value) {
|
2011-06-30 21:18:19 +00:00
|
|
|
c = std::move(__q.c);
|
|
|
|
return *this;
|
|
|
|
}
|
2021-04-20 16:03:32 +00:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2011-06-04 21:32:33 +00:00
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI explicit queue(const container_type& __c) : c(__c) {}
|
2017-04-18 21:23:18 +00:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2011-06-30 21:18:19 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI explicit queue(container_type&& __c) : c(std::move(__c)) {}
|
2021-04-20 16:03:32 +00:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2010-05-11 19:42:16 +00:00
|
|
|
template <class _Alloc>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI explicit queue(const _Alloc& __a,
|
2021-09-08 13:14:43 +00:00
|
|
|
__enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
|
2010-05-11 19:42:16 +00:00
|
|
|
: c(__a) {}
|
|
|
|
template <class _Alloc>
|
2010-09-22 18:02:38 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI
|
2021-09-08 13:14:43 +00:00
|
|
|
queue(const queue& __q, const _Alloc& __a, __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
|
2010-05-11 19:42:16 +00:00
|
|
|
: c(__q.c, __a) {}
|
|
|
|
template <class _Alloc>
|
2010-09-22 18:02:38 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI
|
2021-09-08 13:14:43 +00:00
|
|
|
queue(const container_type& __c, const _Alloc& __a, __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
|
2010-05-11 19:42:16 +00:00
|
|
|
: c(__c, __a) {}
|
2017-04-18 21:23:18 +00:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2010-05-11 19:42:16 +00:00
|
|
|
template <class _Alloc>
|
2010-09-22 18:02:38 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI
|
2021-09-08 13:14:43 +00:00
|
|
|
queue(container_type&& __c, const _Alloc& __a, __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
|
2011-06-30 21:18:19 +00:00
|
|
|
: c(std::move(__c), __a) {}
|
2010-05-11 19:42:16 +00:00
|
|
|
template <class _Alloc>
|
2010-09-22 18:02:38 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI
|
2021-09-08 13:14:43 +00:00
|
|
|
queue(queue&& __q, const _Alloc& __a, __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
|
2011-06-30 21:18:19 +00:00
|
|
|
: c(std::move(__q.c), __a) {}
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2021-04-20 16:03:32 +00:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2017-11-15 05:51:26 +00:00
|
|
|
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI bool empty() const { return c.empty(); }
|
2010-05-11 19:42:16 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI size_type size() const { return c.size(); }
|
2023-06-03 02:23:29 +00:00
|
|
|
|
|
|
|
_LIBCPP_HIDE_FROM_ABI reference front() { return c.front(); }
|
|
|
|
_LIBCPP_HIDE_FROM_ABI const_reference front() const { return c.front(); }
|
|
|
|
_LIBCPP_HIDE_FROM_ABI reference back() { return c.back(); }
|
|
|
|
_LIBCPP_HIDE_FROM_ABI const_reference back() const { return c.back(); }
|
|
|
|
|
2010-09-22 18:02:38 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI void push(const value_type& __v) { c.push_back(__v); }
|
2021-04-20 16:03:32 +00:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2011-06-30 21:18:19 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI void push(value_type&& __v) { c.push_back(std::move(__v)); }
|
2023-12-18 19:01:33 +00:00
|
|
|
|
2023-02-13 23:56:09 +00:00
|
|
|
# if _LIBCPP_STD_VER >= 23
|
2023-06-03 02:23:29 +00:00
|
|
|
template <_ContainerCompatibleRange<_Tp> _Range>
|
2010-09-22 18:02:38 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI void push_range(_Range&& __range) {
|
2011-06-04 21:32:33 +00:00
|
|
|
if constexpr (requires(container_type& __c) { __c.append_range(std::forward<_Range>(__range)); }) {
|
2011-06-30 21:18:19 +00:00
|
|
|
c.append_range(std::forward<_Range>(__range));
|
2023-12-18 19:01:33 +00:00
|
|
|
} else {
|
2010-05-11 19:42:16 +00:00
|
|
|
ranges::copy(std::forward<_Range>(__range), std::back_inserter(c));
|
|
|
|
}
|
2023-12-18 19:01:33 +00:00
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
template <class... _Args>
|
2010-09-22 18:02:38 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI
|
2023-02-13 23:56:09 +00:00
|
|
|
# if _LIBCPP_STD_VER >= 17
|
2018-01-24 22:42:25 +00:00
|
|
|
decltype(auto)
|
|
|
|
emplace(_Args&&... __args) {
|
2016-07-21 03:20:17 +00:00
|
|
|
return c.emplace_back(std::forward<_Args>(__args)...);
|
2023-12-18 19:01:33 +00:00
|
|
|
}
|
|
|
|
# else
|
|
|
|
void
|
2018-01-24 22:42:25 +00:00
|
|
|
emplace(_Args&&... __args) {
|
2011-06-30 21:18:19 +00:00
|
|
|
c.emplace_back(std::forward<_Args>(__args)...);
|
2023-12-18 19:01:33 +00:00
|
|
|
}
|
|
|
|
# endif
|
2021-04-20 16:03:32 +00:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2022-05-05 16:57:32 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI void pop() { c.pop_front(); }
|
2023-12-18 19:01:33 +00:00
|
|
|
|
2011-06-04 21:32:33 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI void swap(queue& __q) _NOEXCEPT_(__is_nothrow_swappable<container_type>::value) {
|
2011-06-30 21:18:19 +00:00
|
|
|
using std::swap;
|
2010-05-11 19:42:16 +00:00
|
|
|
swap(c, __q.c);
|
2023-12-18 19:01:33 +00:00
|
|
|
}
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2022-05-05 16:57:32 +00:00
|
|
|
_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI const _Container& __get_container() const { return c; }
|
|
|
|
|
2023-07-25 02:53:39 +00:00
|
|
|
template <class _T1, class _OtherContainer>
|
2010-09-22 18:02:38 +00:00
|
|
|
friend _LIBCPP_HIDE_FROM_ABI bool
|
2023-07-25 02:53:39 +00:00
|
|
|
operator==(const queue<_T1, _OtherContainer>& __x, const queue<_T1, _OtherContainer>& __y);
|
2010-08-22 00:02:43 +00:00
|
|
|
|
2023-07-25 02:53:39 +00:00
|
|
|
template <class _T1, class _OtherContainer>
|
2010-09-22 18:02:38 +00:00
|
|
|
friend _LIBCPP_HIDE_FROM_ABI bool
|
2023-07-25 02:53:39 +00:00
|
|
|
operator<(const queue<_T1, _OtherContainer>& __x, const queue<_T1, _OtherContainer>& __y);
|
2010-05-11 19:42:16 +00:00
|
|
|
};
|
|
|
|
|
2023-02-13 23:56:09 +00:00
|
|
|
#if _LIBCPP_STD_VER >= 17
|
[libc++] Use enable_if_t instead of _EnableIf
I just ran into a compiler error involving __bind_back and some overloads
that were being disabled with _EnableIf. I noticed that the error message
was quite bad and did not mention the reason for the overload being
excluded. Specifically, the error looked like this:
candidate template ignored: substitution failure [with _Args =
<ContiguousView>]: no member named '_EnableIfImpl' in 'std::_MetaBase<false>'
Instead, when using enable_if or enable_if_t, the compiler is clever and
can produce better diagnostics, like so:
candidate template ignored: requirement 'is_invocable_v<
std::__bind_back_op<1, std::integer_sequence<unsigned long, 0>>,
std::ranges::views::__transform::__fn &, std::tuple<PlusOne> &,
ContiguousView>' was not satisfied [with _Args = <ContiguousView>]
Basically, it tries to do a poor man's implementation of concepts, which
is already a lot better than simply complaining about substitution failure.
Hence, this commit uses enable_if_t instead of _EnableIf whenever
possible. That is both more straightforward than using the internal
helper, and also leads to better error messages in those cases.
I understand the motivation for _EnableIf's implementation was to improve
compile-time performance, however I believe striving to improve error
messages is even more important for our QOI, hence this patch. Furthermore,
it is unclear that _EnableIf actually improved compile-time performance
in any noticeable way (see discussion in the review for details).
Differential Revision: https://reviews.llvm.org/D108216
2021-08-17 16:26:09 +00:00
|
|
|
template <class _Container, class = enable_if_t<!__is_allocator<_Container>::value> >
|
2018-05-22 01:57:53 +00:00
|
|
|
queue(_Container) -> queue<typename _Container::value_type, _Container>;
|
2023-12-18 19:01:33 +00:00
|
|
|
|
2018-05-22 01:57:53 +00:00
|
|
|
template <class _Container,
|
|
|
|
class _Alloc,
|
[libc++] Use enable_if_t instead of _EnableIf
I just ran into a compiler error involving __bind_back and some overloads
that were being disabled with _EnableIf. I noticed that the error message
was quite bad and did not mention the reason for the overload being
excluded. Specifically, the error looked like this:
candidate template ignored: substitution failure [with _Args =
<ContiguousView>]: no member named '_EnableIfImpl' in 'std::_MetaBase<false>'
Instead, when using enable_if or enable_if_t, the compiler is clever and
can produce better diagnostics, like so:
candidate template ignored: requirement 'is_invocable_v<
std::__bind_back_op<1, std::integer_sequence<unsigned long, 0>>,
std::ranges::views::__transform::__fn &, std::tuple<PlusOne> &,
ContiguousView>' was not satisfied [with _Args = <ContiguousView>]
Basically, it tries to do a poor man's implementation of concepts, which
is already a lot better than simply complaining about substitution failure.
Hence, this commit uses enable_if_t instead of _EnableIf whenever
possible. That is both more straightforward than using the internal
helper, and also leads to better error messages in those cases.
I understand the motivation for _EnableIf's implementation was to improve
compile-time performance, however I believe striving to improve error
messages is even more important for our QOI, hence this patch. Furthermore,
it is unclear that _EnableIf actually improved compile-time performance
in any noticeable way (see discussion in the review for details).
Differential Revision: https://reviews.llvm.org/D108216
2021-08-17 16:26:09 +00:00
|
|
|
class = enable_if_t<!__is_allocator<_Container>::value>,
|
|
|
|
class = enable_if_t<uses_allocator<_Container, _Alloc>::value> >
|
2018-05-22 01:57:53 +00:00
|
|
|
queue(_Container, _Alloc) -> queue<typename _Container::value_type, _Container>;
|
|
|
|
#endif
|
|
|
|
|
2023-02-13 23:56:09 +00:00
|
|
|
#if _LIBCPP_STD_VER >= 23
|
2023-05-17 17:34:51 +00:00
|
|
|
template <class _InputIterator, class = __enable_if_t<__has_input_iterator_category<_InputIterator>::value>>
|
2022-01-06 11:36:07 +00:00
|
|
|
queue(_InputIterator, _InputIterator) -> queue<__iter_value_type<_InputIterator>>;
|
|
|
|
|
2023-06-03 02:23:29 +00:00
|
|
|
template <ranges::input_range _Range>
|
|
|
|
queue(from_range_t, _Range&&) -> queue<ranges::range_value_t<_Range>>;
|
|
|
|
|
2022-01-06 11:36:07 +00:00
|
|
|
template <class _InputIterator,
|
|
|
|
class _Alloc,
|
2023-05-17 17:34:51 +00:00
|
|
|
class = __enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
|
2022-01-06 11:36:07 +00:00
|
|
|
class = __enable_if_t<__is_allocator<_Alloc>::value>>
|
|
|
|
queue(_InputIterator, _InputIterator, _Alloc)
|
|
|
|
-> queue<__iter_value_type<_InputIterator>, deque<__iter_value_type<_InputIterator>, _Alloc>>;
|
2023-06-03 02:23:29 +00:00
|
|
|
|
|
|
|
template <ranges::input_range _Range, class _Alloc, class = __enable_if_t<__is_allocator<_Alloc>::value>>
|
|
|
|
queue(from_range_t, _Range&&, _Alloc)
|
|
|
|
-> queue<ranges::range_value_t<_Range>, deque<ranges::range_value_t<_Range>, _Alloc>>;
|
2022-01-06 11:36:07 +00:00
|
|
|
#endif
|
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
template <class _Tp, class _Container>
|
|
|
|
inline _LIBCPP_HIDE_FROM_ABI bool operator==(const queue<_Tp, _Container>& __x, const queue<_Tp, _Container>& __y) {
|
|
|
|
return __x.c == __y.c;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Container>
|
|
|
|
inline _LIBCPP_HIDE_FROM_ABI bool operator<(const queue<_Tp, _Container>& __x, const queue<_Tp, _Container>& __y) {
|
|
|
|
return __x.c < __y.c;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Container>
|
|
|
|
inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const queue<_Tp, _Container>& __x, const queue<_Tp, _Container>& __y) {
|
|
|
|
return !(__x == __y);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Container>
|
|
|
|
inline _LIBCPP_HIDE_FROM_ABI bool operator>(const queue<_Tp, _Container>& __x, const queue<_Tp, _Container>& __y) {
|
|
|
|
return __y < __x;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Container>
|
|
|
|
inline _LIBCPP_HIDE_FROM_ABI bool operator>=(const queue<_Tp, _Container>& __x, const queue<_Tp, _Container>& __y) {
|
|
|
|
return !(__x < __y);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Container>
|
|
|
|
inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const queue<_Tp, _Container>& __x, const queue<_Tp, _Container>& __y) {
|
|
|
|
return !(__y < __x);
|
|
|
|
}
|
|
|
|
|
2023-03-14 16:32:15 +00:00
|
|
|
#if _LIBCPP_STD_VER >= 20
|
|
|
|
|
|
|
|
template <class _Tp, three_way_comparable _Container>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI compare_three_way_result_t<_Container>
|
|
|
|
operator<=>(const queue<_Tp, _Container>& __x, const queue<_Tp, _Container>& __y) {
|
|
|
|
// clang 16 bug: declaring `friend operator<=>` causes "use of overloaded operator '*' is ambiguous" errors
|
|
|
|
return __x.__get_container() <=> __y.__get_container();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2023-09-02 00:52:02 +00:00
|
|
|
template <class _Tp, class _Container, __enable_if_t<__is_swappable<_Container>::value, int> = 0>
|
2010-05-11 19:42:16 +00:00
|
|
|
inline _LIBCPP_HIDE_FROM_ABI void swap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y)
|
2011-06-04 21:32:33 +00:00
|
|
|
_NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
|
2010-05-11 19:42:16 +00:00
|
|
|
__x.swap(__y);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Container, class _Alloc>
|
2017-01-04 23:56:00 +00:00
|
|
|
struct _LIBCPP_TEMPLATE_VIS uses_allocator<queue<_Tp, _Container>, _Alloc> : public uses_allocator<_Container, _Alloc> {
|
2010-05-11 19:42:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Tp, class _Container = vector<_Tp>, class _Compare = less<typename _Container::value_type> >
|
2017-01-04 23:56:00 +00:00
|
|
|
class _LIBCPP_TEMPLATE_VIS priority_queue {
|
2010-05-11 19:42:16 +00:00
|
|
|
public:
|
|
|
|
typedef _Container container_type;
|
|
|
|
typedef _Compare value_compare;
|
|
|
|
typedef typename container_type::value_type value_type;
|
|
|
|
typedef typename container_type::reference reference;
|
|
|
|
typedef typename container_type::const_reference const_reference;
|
|
|
|
typedef typename container_type::size_type size_type;
|
2016-03-14 17:58:11 +00:00
|
|
|
static_assert((is_same<_Tp, value_type>::value), "");
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
container_type c;
|
|
|
|
value_compare comp;
|
|
|
|
|
|
|
|
public:
|
2010-09-22 18:02:38 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI priority_queue() _NOEXCEPT_(
|
2011-06-04 21:32:33 +00:00
|
|
|
is_nothrow_default_constructible<container_type>::value&& is_nothrow_default_constructible<value_compare>::value)
|
|
|
|
: c(), comp() {}
|
|
|
|
|
|
|
|
_LIBCPP_HIDE_FROM_ABI priority_queue(const priority_queue& __q) : c(__q.c), comp(__q.comp) {}
|
|
|
|
|
2017-04-18 21:23:18 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI priority_queue& operator=(const priority_queue& __q) {
|
|
|
|
c = __q.c;
|
|
|
|
comp = __q.comp;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2011-06-04 21:32:33 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI priority_queue(priority_queue&& __q) _NOEXCEPT_(
|
|
|
|
is_nothrow_move_constructible<container_type>::value&& is_nothrow_move_constructible<value_compare>::value)
|
2011-06-30 21:18:19 +00:00
|
|
|
: c(std::move(__q.c)), comp(std::move(__q.comp)) {}
|
2023-12-18 19:01:33 +00:00
|
|
|
|
2011-06-04 21:32:33 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI priority_queue& operator=(priority_queue&& __q)
|
|
|
|
_NOEXCEPT_(is_nothrow_move_assignable<container_type>::value&& is_nothrow_move_assignable<value_compare>::value) {
|
2011-06-30 21:18:19 +00:00
|
|
|
c = std::move(__q.c);
|
|
|
|
comp = std::move(__q.comp);
|
|
|
|
return *this;
|
|
|
|
}
|
2021-04-20 16:03:32 +00:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2011-06-04 21:32:33 +00:00
|
|
|
|
|
|
|
_LIBCPP_HIDE_FROM_ABI explicit priority_queue(const value_compare& __comp) : c(), comp(__comp) {}
|
2010-05-11 19:42:16 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI priority_queue(const value_compare& __comp, const container_type& __c);
|
2017-04-18 21:23:18 +00:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2021-01-19 07:21:09 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI priority_queue(const value_compare& __comp, container_type&& __c);
|
2010-05-11 19:42:16 +00:00
|
|
|
#endif
|
2023-05-17 17:34:51 +00:00
|
|
|
template <class _InputIter, class = __enable_if_t<__has_input_iterator_category<_InputIter>::value> >
|
2010-05-11 19:42:16 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI priority_queue(_InputIter __f, _InputIter __l, const value_compare& __comp = value_compare());
|
2023-05-17 17:34:51 +00:00
|
|
|
template <class _InputIter, class = __enable_if_t<__has_input_iterator_category<_InputIter>::value> >
|
2016-04-22 01:04:55 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI
|
2010-05-11 19:42:16 +00:00
|
|
|
priority_queue(_InputIter __f, _InputIter __l, const value_compare& __comp, const container_type& __c);
|
2017-04-18 21:23:18 +00:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2023-05-17 17:34:51 +00:00
|
|
|
template <class _InputIter, class = __enable_if_t<__has_input_iterator_category<_InputIter>::value> >
|
2016-04-22 01:04:55 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI
|
2010-05-11 19:42:16 +00:00
|
|
|
priority_queue(_InputIter __f, _InputIter __l, const value_compare& __comp, container_type&& __c);
|
2021-04-20 16:03:32 +00:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2023-06-03 02:23:29 +00:00
|
|
|
|
|
|
|
#if _LIBCPP_STD_VER >= 23
|
|
|
|
template <_ContainerCompatibleRange<_Tp> _Range>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI priority_queue(from_range_t, _Range&& __range, const value_compare& __comp = value_compare())
|
|
|
|
: c(from_range, std::forward<_Range>(__range)), comp(__comp) {
|
|
|
|
std::make_heap(c.begin(), c.end(), comp);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
template <class _Alloc>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI explicit priority_queue(const _Alloc& __a,
|
2021-09-08 13:14:43 +00:00
|
|
|
__enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
|
2010-05-11 19:42:16 +00:00
|
|
|
template <class _Alloc>
|
2016-04-22 01:04:55 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI
|
2010-05-11 19:42:16 +00:00
|
|
|
priority_queue(const value_compare& __comp,
|
|
|
|
const _Alloc& __a,
|
2021-09-08 13:14:43 +00:00
|
|
|
__enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
|
2010-05-11 19:42:16 +00:00
|
|
|
template <class _Alloc>
|
2016-04-22 01:04:55 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI
|
2010-05-11 19:42:16 +00:00
|
|
|
priority_queue(const value_compare& __comp,
|
|
|
|
const container_type& __c,
|
|
|
|
const _Alloc& __a,
|
2021-09-08 13:14:43 +00:00
|
|
|
__enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
|
2010-05-11 19:42:16 +00:00
|
|
|
template <class _Alloc>
|
2016-04-22 01:04:55 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI priority_queue(
|
2021-09-08 13:14:43 +00:00
|
|
|
const priority_queue& __q, const _Alloc& __a, __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
|
2017-04-18 21:23:18 +00:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2010-05-11 19:42:16 +00:00
|
|
|
template <class _Alloc>
|
2016-04-22 01:04:55 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI
|
2010-05-11 19:42:16 +00:00
|
|
|
priority_queue(const value_compare& __comp,
|
|
|
|
container_type&& __c,
|
|
|
|
const _Alloc& __a,
|
2021-09-08 13:14:43 +00:00
|
|
|
__enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
|
2010-05-11 19:42:16 +00:00
|
|
|
template <class _Alloc>
|
2016-04-22 01:04:55 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI priority_queue(
|
2021-09-08 13:14:43 +00:00
|
|
|
priority_queue&& __q, const _Alloc& __a, __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
|
2021-04-20 16:03:32 +00:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2023-05-17 17:34:51 +00:00
|
|
|
template <class _InputIter, class _Alloc, class = __enable_if_t<__has_input_iterator_category<_InputIter>::value> >
|
2021-03-02 05:23:21 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI
|
|
|
|
priority_queue(_InputIter __f,
|
|
|
|
_InputIter __l,
|
|
|
|
const _Alloc& __a,
|
2021-09-08 13:14:43 +00:00
|
|
|
__enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
|
2023-12-18 19:01:33 +00:00
|
|
|
|
2023-05-17 17:34:51 +00:00
|
|
|
template <class _InputIter, class _Alloc, class = __enable_if_t<__has_input_iterator_category<_InputIter>::value> >
|
2021-03-02 05:23:21 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI priority_queue(
|
|
|
|
_InputIter __f,
|
|
|
|
_InputIter __l,
|
|
|
|
const value_compare& __comp,
|
|
|
|
const _Alloc& __a,
|
2021-09-08 13:14:43 +00:00
|
|
|
__enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
|
2023-12-18 19:01:33 +00:00
|
|
|
|
2023-05-17 17:34:51 +00:00
|
|
|
template <class _InputIter, class _Alloc, class = __enable_if_t<__has_input_iterator_category<_InputIter>::value> >
|
2021-03-02 05:23:21 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI priority_queue(
|
|
|
|
_InputIter __f,
|
|
|
|
_InputIter __l,
|
|
|
|
const value_compare& __comp,
|
|
|
|
const container_type& __c,
|
|
|
|
const _Alloc& __a,
|
2021-09-08 13:14:43 +00:00
|
|
|
__enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
|
2021-03-02 05:23:21 +00:00
|
|
|
|
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2023-05-17 17:34:51 +00:00
|
|
|
template <class _InputIter, class _Alloc, class = __enable_if_t<__has_input_iterator_category<_InputIter>::value> >
|
2021-03-02 05:23:21 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI priority_queue(
|
|
|
|
_InputIter __f,
|
|
|
|
_InputIter __l,
|
|
|
|
const value_compare& __comp,
|
|
|
|
container_type&& __c,
|
|
|
|
const _Alloc& __a,
|
2021-09-08 13:14:43 +00:00
|
|
|
__enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
|
2021-03-02 05:23:21 +00:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
|
|
|
|
2023-06-03 02:23:29 +00:00
|
|
|
#if _LIBCPP_STD_VER >= 23
|
|
|
|
|
|
|
|
template <_ContainerCompatibleRange<_Tp> _Range,
|
|
|
|
class _Alloc,
|
|
|
|
class = enable_if_t<uses_allocator<_Container, _Alloc>::value>>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI priority_queue(from_range_t, _Range&& __range, const value_compare& __comp, const _Alloc& __a)
|
|
|
|
: c(from_range, std::forward<_Range>(__range), __a), comp(__comp) {
|
|
|
|
std::make_heap(c.begin(), c.end(), comp);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <_ContainerCompatibleRange<_Tp> _Range,
|
|
|
|
class _Alloc,
|
|
|
|
class = enable_if_t<uses_allocator<_Container, _Alloc>::value>>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI priority_queue(from_range_t, _Range&& __range, const _Alloc& __a)
|
|
|
|
: c(from_range, std::forward<_Range>(__range), __a), comp() {
|
|
|
|
std::make_heap(c.begin(), c.end(), comp);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2017-11-15 05:51:26 +00:00
|
|
|
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI bool empty() const { return c.empty(); }
|
2010-05-11 19:42:16 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI size_type size() const { return c.size(); }
|
|
|
|
_LIBCPP_HIDE_FROM_ABI const_reference top() const { return c.front(); }
|
|
|
|
|
|
|
|
_LIBCPP_HIDE_FROM_ABI void push(const value_type& __v);
|
2017-04-18 21:23:18 +00:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2010-05-11 19:42:16 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI void push(value_type&& __v);
|
2023-12-18 19:01:33 +00:00
|
|
|
|
2023-06-03 02:23:29 +00:00
|
|
|
# if _LIBCPP_STD_VER >= 23
|
|
|
|
template <_ContainerCompatibleRange<_Tp> _Range>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI void push_range(_Range&& __range) {
|
|
|
|
if constexpr (requires(container_type& __c) { __c.append_range(std::forward<_Range>(__range)); }) {
|
|
|
|
c.append_range(std::forward<_Range>(__range));
|
|
|
|
} else {
|
|
|
|
ranges::copy(std::forward<_Range>(__range), std::back_inserter(c));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::make_heap(c.begin(), c.end(), comp);
|
2023-12-18 19:01:33 +00:00
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
2017-04-18 21:23:18 +00:00
|
|
|
template <class... _Args>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI void emplace(_Args&&... __args);
|
2021-04-20 16:03:32 +00:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2016-04-22 01:04:55 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI void pop();
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2011-06-04 21:32:33 +00:00
|
|
|
_LIBCPP_HIDE_FROM_ABI void swap(priority_queue& __q)
|
|
|
|
_NOEXCEPT_(__is_nothrow_swappable<container_type>::value&& __is_nothrow_swappable<value_compare>::value);
|
2022-05-05 16:57:32 +00:00
|
|
|
|
|
|
|
_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI const _Container& __get_container() const { return c; }
|
2010-05-11 19:42:16 +00:00
|
|
|
};
|
|
|
|
|
2021-08-17 15:59:07 +00:00
|
|
|
#if _LIBCPP_STD_VER >= 17
|
2018-05-22 01:57:53 +00:00
|
|
|
template <class _Compare,
|
|
|
|
class _Container,
|
[libc++] Use enable_if_t instead of _EnableIf
I just ran into a compiler error involving __bind_back and some overloads
that were being disabled with _EnableIf. I noticed that the error message
was quite bad and did not mention the reason for the overload being
excluded. Specifically, the error looked like this:
candidate template ignored: substitution failure [with _Args =
<ContiguousView>]: no member named '_EnableIfImpl' in 'std::_MetaBase<false>'
Instead, when using enable_if or enable_if_t, the compiler is clever and
can produce better diagnostics, like so:
candidate template ignored: requirement 'is_invocable_v<
std::__bind_back_op<1, std::integer_sequence<unsigned long, 0>>,
std::ranges::views::__transform::__fn &, std::tuple<PlusOne> &,
ContiguousView>' was not satisfied [with _Args = <ContiguousView>]
Basically, it tries to do a poor man's implementation of concepts, which
is already a lot better than simply complaining about substitution failure.
Hence, this commit uses enable_if_t instead of _EnableIf whenever
possible. That is both more straightforward than using the internal
helper, and also leads to better error messages in those cases.
I understand the motivation for _EnableIf's implementation was to improve
compile-time performance, however I believe striving to improve error
messages is even more important for our QOI, hence this patch. Furthermore,
it is unclear that _EnableIf actually improved compile-time performance
in any noticeable way (see discussion in the review for details).
Differential Revision: https://reviews.llvm.org/D108216
2021-08-17 16:26:09 +00:00
|
|
|
class = enable_if_t<!__is_allocator<_Compare>::value>,
|
|
|
|
class = enable_if_t<!__is_allocator<_Container>::value> >
|
2018-05-22 01:57:53 +00:00
|
|
|
priority_queue(_Compare, _Container) -> priority_queue<typename _Container::value_type, _Container, _Compare>;
|
2019-05-29 16:01:36 +00:00
|
|
|
|
|
|
|
template <class _InputIterator,
|
2021-03-04 04:02:20 +00:00
|
|
|
class _Compare = less<__iter_value_type<_InputIterator>>,
|
|
|
|
class _Container = vector<__iter_value_type<_InputIterator>>,
|
2023-05-17 17:34:51 +00:00
|
|
|
class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
|
[libc++] Use enable_if_t instead of _EnableIf
I just ran into a compiler error involving __bind_back and some overloads
that were being disabled with _EnableIf. I noticed that the error message
was quite bad and did not mention the reason for the overload being
excluded. Specifically, the error looked like this:
candidate template ignored: substitution failure [with _Args =
<ContiguousView>]: no member named '_EnableIfImpl' in 'std::_MetaBase<false>'
Instead, when using enable_if or enable_if_t, the compiler is clever and
can produce better diagnostics, like so:
candidate template ignored: requirement 'is_invocable_v<
std::__bind_back_op<1, std::integer_sequence<unsigned long, 0>>,
std::ranges::views::__transform::__fn &, std::tuple<PlusOne> &,
ContiguousView>' was not satisfied [with _Args = <ContiguousView>]
Basically, it tries to do a poor man's implementation of concepts, which
is already a lot better than simply complaining about substitution failure.
Hence, this commit uses enable_if_t instead of _EnableIf whenever
possible. That is both more straightforward than using the internal
helper, and also leads to better error messages in those cases.
I understand the motivation for _EnableIf's implementation was to improve
compile-time performance, however I believe striving to improve error
messages is even more important for our QOI, hence this patch. Furthermore,
it is unclear that _EnableIf actually improved compile-time performance
in any noticeable way (see discussion in the review for details).
Differential Revision: https://reviews.llvm.org/D108216
2021-08-17 16:26:09 +00:00
|
|
|
class = enable_if_t<!__is_allocator<_Compare>::value>,
|
|
|
|
class = enable_if_t<!__is_allocator<_Container>::value> >
|
2018-05-22 01:57:53 +00:00
|
|
|
priority_queue(_InputIterator, _InputIterator, _Compare = _Compare(), _Container = _Container())
|
2021-03-04 04:02:20 +00:00
|
|
|
-> priority_queue<__iter_value_type<_InputIterator>, _Container, _Compare>;
|
2019-05-29 16:01:36 +00:00
|
|
|
|
|
|
|
template <class _Compare,
|
2018-05-22 01:57:53 +00:00
|
|
|
class _Container,
|
|
|
|
class _Alloc,
|
[libc++] Use enable_if_t instead of _EnableIf
I just ran into a compiler error involving __bind_back and some overloads
that were being disabled with _EnableIf. I noticed that the error message
was quite bad and did not mention the reason for the overload being
excluded. Specifically, the error looked like this:
candidate template ignored: substitution failure [with _Args =
<ContiguousView>]: no member named '_EnableIfImpl' in 'std::_MetaBase<false>'
Instead, when using enable_if or enable_if_t, the compiler is clever and
can produce better diagnostics, like so:
candidate template ignored: requirement 'is_invocable_v<
std::__bind_back_op<1, std::integer_sequence<unsigned long, 0>>,
std::ranges::views::__transform::__fn &, std::tuple<PlusOne> &,
ContiguousView>' was not satisfied [with _Args = <ContiguousView>]
Basically, it tries to do a poor man's implementation of concepts, which
is already a lot better than simply complaining about substitution failure.
Hence, this commit uses enable_if_t instead of _EnableIf whenever
possible. That is both more straightforward than using the internal
helper, and also leads to better error messages in those cases.
I understand the motivation for _EnableIf's implementation was to improve
compile-time performance, however I believe striving to improve error
messages is even more important for our QOI, hence this patch. Furthermore,
it is unclear that _EnableIf actually improved compile-time performance
in any noticeable way (see discussion in the review for details).
Differential Revision: https://reviews.llvm.org/D108216
2021-08-17 16:26:09 +00:00
|
|
|
class = enable_if_t<!__is_allocator<_Compare>::value>,
|
|
|
|
class = enable_if_t<!__is_allocator<_Container>::value>,
|
|
|
|
class = enable_if_t<uses_allocator<_Container, _Alloc>::value> >
|
2018-05-22 01:57:53 +00:00
|
|
|
priority_queue(_Compare, _Container, _Alloc) -> priority_queue<typename _Container::value_type, _Container, _Compare>;
|
2021-03-02 05:23:21 +00:00
|
|
|
|
|
|
|
template <class _InputIterator,
|
|
|
|
class _Allocator,
|
2023-05-17 17:34:51 +00:00
|
|
|
class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
|
[libc++] Use enable_if_t instead of _EnableIf
I just ran into a compiler error involving __bind_back and some overloads
that were being disabled with _EnableIf. I noticed that the error message
was quite bad and did not mention the reason for the overload being
excluded. Specifically, the error looked like this:
candidate template ignored: substitution failure [with _Args =
<ContiguousView>]: no member named '_EnableIfImpl' in 'std::_MetaBase<false>'
Instead, when using enable_if or enable_if_t, the compiler is clever and
can produce better diagnostics, like so:
candidate template ignored: requirement 'is_invocable_v<
std::__bind_back_op<1, std::integer_sequence<unsigned long, 0>>,
std::ranges::views::__transform::__fn &, std::tuple<PlusOne> &,
ContiguousView>' was not satisfied [with _Args = <ContiguousView>]
Basically, it tries to do a poor man's implementation of concepts, which
is already a lot better than simply complaining about substitution failure.
Hence, this commit uses enable_if_t instead of _EnableIf whenever
possible. That is both more straightforward than using the internal
helper, and also leads to better error messages in those cases.
I understand the motivation for _EnableIf's implementation was to improve
compile-time performance, however I believe striving to improve error
messages is even more important for our QOI, hence this patch. Furthermore,
it is unclear that _EnableIf actually improved compile-time performance
in any noticeable way (see discussion in the review for details).
Differential Revision: https://reviews.llvm.org/D108216
2021-08-17 16:26:09 +00:00
|
|
|
class = enable_if_t<__is_allocator<_Allocator>::value> >
|
2021-03-02 05:23:21 +00:00
|
|
|
priority_queue(_InputIterator, _InputIterator, _Allocator)
|
|
|
|
-> priority_queue<__iter_value_type<_InputIterator>,
|
|
|
|
vector<__iter_value_type<_InputIterator>, _Allocator>,
|
|
|
|
less<__iter_value_type<_InputIterator>>>;
|
|
|
|
|
|
|
|
template <class _InputIterator,
|
|
|
|
class _Compare,
|
|
|
|
class _Allocator,
|
2023-05-17 17:34:51 +00:00
|
|
|
class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
|
[libc++] Use enable_if_t instead of _EnableIf
I just ran into a compiler error involving __bind_back and some overloads
that were being disabled with _EnableIf. I noticed that the error message
was quite bad and did not mention the reason for the overload being
excluded. Specifically, the error looked like this:
candidate template ignored: substitution failure [with _Args =
<ContiguousView>]: no member named '_EnableIfImpl' in 'std::_MetaBase<false>'
Instead, when using enable_if or enable_if_t, the compiler is clever and
can produce better diagnostics, like so:
candidate template ignored: requirement 'is_invocable_v<
std::__bind_back_op<1, std::integer_sequence<unsigned long, 0>>,
std::ranges::views::__transform::__fn &, std::tuple<PlusOne> &,
ContiguousView>' was not satisfied [with _Args = <ContiguousView>]
Basically, it tries to do a poor man's implementation of concepts, which
is already a lot better than simply complaining about substitution failure.
Hence, this commit uses enable_if_t instead of _EnableIf whenever
possible. That is both more straightforward than using the internal
helper, and also leads to better error messages in those cases.
I understand the motivation for _EnableIf's implementation was to improve
compile-time performance, however I believe striving to improve error
messages is even more important for our QOI, hence this patch. Furthermore,
it is unclear that _EnableIf actually improved compile-time performance
in any noticeable way (see discussion in the review for details).
Differential Revision: https://reviews.llvm.org/D108216
2021-08-17 16:26:09 +00:00
|
|
|
class = enable_if_t<!__is_allocator<_Compare>::value>,
|
|
|
|
class = enable_if_t<__is_allocator<_Allocator>::value> >
|
2021-03-02 05:23:21 +00:00
|
|
|
priority_queue(_InputIterator, _InputIterator, _Compare, _Allocator)
|
|
|
|
-> priority_queue<__iter_value_type<_InputIterator>,
|
|
|
|
vector<__iter_value_type<_InputIterator>, _Allocator>,
|
|
|
|
_Compare>;
|
2023-12-18 19:01:33 +00:00
|
|
|
|
2021-03-02 05:23:21 +00:00
|
|
|
template <class _InputIterator,
|
|
|
|
class _Compare,
|
|
|
|
class _Container,
|
|
|
|
class _Alloc,
|
2023-05-17 17:34:51 +00:00
|
|
|
class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
|
[libc++] Use enable_if_t instead of _EnableIf
I just ran into a compiler error involving __bind_back and some overloads
that were being disabled with _EnableIf. I noticed that the error message
was quite bad and did not mention the reason for the overload being
excluded. Specifically, the error looked like this:
candidate template ignored: substitution failure [with _Args =
<ContiguousView>]: no member named '_EnableIfImpl' in 'std::_MetaBase<false>'
Instead, when using enable_if or enable_if_t, the compiler is clever and
can produce better diagnostics, like so:
candidate template ignored: requirement 'is_invocable_v<
std::__bind_back_op<1, std::integer_sequence<unsigned long, 0>>,
std::ranges::views::__transform::__fn &, std::tuple<PlusOne> &,
ContiguousView>' was not satisfied [with _Args = <ContiguousView>]
Basically, it tries to do a poor man's implementation of concepts, which
is already a lot better than simply complaining about substitution failure.
Hence, this commit uses enable_if_t instead of _EnableIf whenever
possible. That is both more straightforward than using the internal
helper, and also leads to better error messages in those cases.
I understand the motivation for _EnableIf's implementation was to improve
compile-time performance, however I believe striving to improve error
messages is even more important for our QOI, hence this patch. Furthermore,
it is unclear that _EnableIf actually improved compile-time performance
in any noticeable way (see discussion in the review for details).
Differential Revision: https://reviews.llvm.org/D108216
2021-08-17 16:26:09 +00:00
|
|
|
class = enable_if_t<!__is_allocator<_Compare>::value>,
|
|
|
|
class = enable_if_t<!__is_allocator<_Container>::value>,
|
|
|
|
class = enable_if_t<uses_allocator<_Container, _Alloc>::value> >
|
2021-03-02 05:23:21 +00:00
|
|
|
priority_queue(_InputIterator, _InputIterator, _Compare, _Container, _Alloc)
|
|
|
|
-> priority_queue<typename _Container::value_type, _Container, _Compare>;
|
2018-05-22 01:57:53 +00:00
|
|
|
#endif
|
|
|
|
|
2023-06-03 02:23:29 +00:00
|
|
|
#if _LIBCPP_STD_VER >= 23
|
|
|
|
|
|
|
|
template <ranges::input_range _Range,
|
|
|
|
class _Compare = less<ranges::range_value_t<_Range>>,
|
|
|
|
class = enable_if_t<!__is_allocator<_Compare>::value>>
|
|
|
|
priority_queue(from_range_t, _Range&&, _Compare = _Compare())
|
|
|
|
-> priority_queue<ranges::range_value_t<_Range>, vector<ranges::range_value_t<_Range>>, _Compare>;
|
|
|
|
|
|
|
|
template <ranges::input_range _Range,
|
|
|
|
class _Compare,
|
|
|
|
class _Alloc,
|
|
|
|
class = enable_if_t<!__is_allocator<_Compare>::value>,
|
|
|
|
class = enable_if_t<__is_allocator<_Alloc>::value>>
|
|
|
|
priority_queue(from_range_t, _Range&&, _Compare, _Alloc)
|
|
|
|
-> priority_queue<ranges::range_value_t<_Range>, vector<ranges::range_value_t<_Range>, _Alloc>, _Compare>;
|
|
|
|
|
|
|
|
template <ranges::input_range _Range, class _Alloc, class = enable_if_t<__is_allocator<_Alloc>::value>>
|
|
|
|
priority_queue(from_range_t, _Range&&, _Alloc)
|
|
|
|
-> priority_queue<ranges::range_value_t<_Range>, vector<ranges::range_value_t<_Range>, _Alloc>>;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
template <class _Tp, class _Container, class _Compare>
|
|
|
|
inline priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Compare& __comp, const container_type& __c)
|
|
|
|
: c(__c), comp(__comp) {
|
2011-06-30 21:18:19 +00:00
|
|
|
std::make_heap(c.begin(), c.end(), comp);
|
2010-05-11 19:42:16 +00:00
|
|
|
}
|
|
|
|
|
2017-04-18 21:23:18 +00:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
template <class _Tp, class _Container, class _Compare>
|
|
|
|
inline priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp, container_type&& __c)
|
2011-06-30 21:18:19 +00:00
|
|
|
: c(std::move(__c)), comp(__comp) {
|
|
|
|
std::make_heap(c.begin(), c.end(), comp);
|
2010-05-11 19:42:16 +00:00
|
|
|
}
|
|
|
|
|
2021-04-20 16:03:32 +00:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
template <class _Tp, class _Container, class _Compare>
|
2021-03-02 05:23:21 +00:00
|
|
|
template <class _InputIter, class>
|
2010-05-11 19:42:16 +00:00
|
|
|
inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
|
|
|
|
_InputIter __f, _InputIter __l, const value_compare& __comp)
|
|
|
|
: c(__f, __l), comp(__comp) {
|
2011-06-30 21:18:19 +00:00
|
|
|
std::make_heap(c.begin(), c.end(), comp);
|
2010-05-11 19:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Container, class _Compare>
|
2021-03-02 05:23:21 +00:00
|
|
|
template <class _InputIter, class>
|
2010-05-11 19:42:16 +00:00
|
|
|
inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
|
|
|
|
_InputIter __f, _InputIter __l, const value_compare& __comp, const container_type& __c)
|
|
|
|
: c(__c), comp(__comp) {
|
|
|
|
c.insert(c.end(), __f, __l);
|
2011-06-30 21:18:19 +00:00
|
|
|
std::make_heap(c.begin(), c.end(), comp);
|
2010-05-11 19:42:16 +00:00
|
|
|
}
|
|
|
|
|
2017-04-18 21:23:18 +00:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
template <class _Tp, class _Container, class _Compare>
|
2021-03-02 05:23:21 +00:00
|
|
|
template <class _InputIter, class>
|
2010-05-11 19:42:16 +00:00
|
|
|
inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
|
|
|
|
_InputIter __f, _InputIter __l, const value_compare& __comp, container_type&& __c)
|
2011-06-30 21:18:19 +00:00
|
|
|
: c(std::move(__c)), comp(__comp) {
|
2010-05-11 19:42:16 +00:00
|
|
|
c.insert(c.end(), __f, __l);
|
2011-06-30 21:18:19 +00:00
|
|
|
std::make_heap(c.begin(), c.end(), comp);
|
2010-05-11 19:42:16 +00:00
|
|
|
}
|
|
|
|
|
2021-04-20 16:03:32 +00:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
template <class _Tp, class _Container, class _Compare>
|
|
|
|
template <class _Alloc>
|
|
|
|
inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
|
2021-09-08 13:14:43 +00:00
|
|
|
const _Alloc& __a, __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
|
2010-05-11 19:42:16 +00:00
|
|
|
: c(__a) {}
|
|
|
|
|
|
|
|
template <class _Tp, class _Container, class _Compare>
|
|
|
|
template <class _Alloc>
|
|
|
|
inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
|
2021-09-08 13:14:43 +00:00
|
|
|
const value_compare& __comp, const _Alloc& __a, __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
|
2010-05-11 19:42:16 +00:00
|
|
|
: c(__a), comp(__comp) {}
|
|
|
|
|
|
|
|
template <class _Tp, class _Container, class _Compare>
|
|
|
|
template <class _Alloc>
|
|
|
|
inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
|
|
|
|
const value_compare& __comp,
|
|
|
|
const container_type& __c,
|
|
|
|
const _Alloc& __a,
|
2021-09-08 13:14:43 +00:00
|
|
|
__enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
|
2010-05-11 19:42:16 +00:00
|
|
|
: c(__c, __a), comp(__comp) {
|
2011-06-30 21:18:19 +00:00
|
|
|
std::make_heap(c.begin(), c.end(), comp);
|
2010-05-11 19:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Container, class _Compare>
|
|
|
|
template <class _Alloc>
|
|
|
|
inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
|
2021-09-08 13:14:43 +00:00
|
|
|
const priority_queue& __q, const _Alloc& __a, __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
|
2010-05-11 19:42:16 +00:00
|
|
|
: c(__q.c, __a), comp(__q.comp) {}
|
|
|
|
|
2017-04-18 21:23:18 +00:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
template <class _Tp, class _Container, class _Compare>
|
|
|
|
template <class _Alloc>
|
|
|
|
inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
|
|
|
|
const value_compare& __comp,
|
|
|
|
container_type&& __c,
|
|
|
|
const _Alloc& __a,
|
2021-09-08 13:14:43 +00:00
|
|
|
__enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
|
2011-06-30 21:18:19 +00:00
|
|
|
: c(std::move(__c), __a), comp(__comp) {
|
|
|
|
std::make_heap(c.begin(), c.end(), comp);
|
2010-05-11 19:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Container, class _Compare>
|
|
|
|
template <class _Alloc>
|
|
|
|
inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
|
2021-09-08 13:14:43 +00:00
|
|
|
priority_queue&& __q, const _Alloc& __a, __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
|
2011-06-30 21:18:19 +00:00
|
|
|
: c(std::move(__q.c), __a), comp(std::move(__q.comp)) {}
|
2021-03-02 05:23:21 +00:00
|
|
|
|
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
|
|
|
|
|
|
|
template <class _Tp, class _Container, class _Compare>
|
|
|
|
template <class _InputIter, class _Alloc, class>
|
|
|
|
inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
|
2021-09-08 13:14:43 +00:00
|
|
|
_InputIter __f, _InputIter __l, const _Alloc& __a, __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
|
2021-03-02 05:23:21 +00:00
|
|
|
: c(__f, __l, __a), comp() {
|
2011-06-30 21:18:19 +00:00
|
|
|
std::make_heap(c.begin(), c.end(), comp);
|
2010-05-11 19:42:16 +00:00
|
|
|
}
|
|
|
|
|
2021-03-02 05:23:21 +00:00
|
|
|
template <class _Tp, class _Container, class _Compare>
|
|
|
|
template <class _InputIter, class _Alloc, class>
|
|
|
|
inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
|
|
|
|
_InputIter __f,
|
|
|
|
_InputIter __l,
|
|
|
|
const value_compare& __comp,
|
|
|
|
const _Alloc& __a,
|
2021-09-08 13:14:43 +00:00
|
|
|
__enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
|
2021-03-02 05:23:21 +00:00
|
|
|
: c(__f, __l, __a), comp(__comp) {
|
|
|
|
std::make_heap(c.begin(), c.end(), comp);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Container, class _Compare>
|
|
|
|
template <class _InputIter, class _Alloc, class>
|
|
|
|
inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
|
|
|
|
_InputIter __f,
|
|
|
|
_InputIter __l,
|
|
|
|
const value_compare& __comp,
|
|
|
|
const container_type& __c,
|
|
|
|
const _Alloc& __a,
|
2021-09-08 13:14:43 +00:00
|
|
|
__enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
|
2021-03-02 05:23:21 +00:00
|
|
|
: c(__c, __a), comp(__comp) {
|
|
|
|
c.insert(c.end(), __f, __l);
|
|
|
|
std::make_heap(c.begin(), c.end(), comp);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
|
|
|
template <class _Tp, class _Container, class _Compare>
|
|
|
|
template <class _InputIter, class _Alloc, class>
|
|
|
|
inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
|
|
|
|
_InputIter __f,
|
|
|
|
_InputIter __l,
|
|
|
|
const value_compare& __comp,
|
|
|
|
container_type&& __c,
|
|
|
|
const _Alloc& __a,
|
2021-09-08 13:14:43 +00:00
|
|
|
__enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
|
2021-03-02 05:23:21 +00:00
|
|
|
: c(std::move(__c), __a), comp(__comp) {
|
|
|
|
c.insert(c.end(), __f, __l);
|
|
|
|
std::make_heap(c.begin(), c.end(), comp);
|
|
|
|
}
|
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
template <class _Tp, class _Container, class _Compare>
|
|
|
|
inline void priority_queue<_Tp, _Container, _Compare>::push(const value_type& __v) {
|
|
|
|
c.push_back(__v);
|
2011-06-30 21:18:19 +00:00
|
|
|
std::push_heap(c.begin(), c.end(), comp);
|
2010-05-11 19:42:16 +00:00
|
|
|
}
|
|
|
|
|
2017-04-18 21:23:18 +00:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
template <class _Tp, class _Container, class _Compare>
|
|
|
|
inline void priority_queue<_Tp, _Container, _Compare>::push(value_type&& __v) {
|
2011-06-30 21:18:19 +00:00
|
|
|
c.push_back(std::move(__v));
|
|
|
|
std::push_heap(c.begin(), c.end(), comp);
|
2010-05-11 19:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Container, class _Compare>
|
|
|
|
template <class... _Args>
|
|
|
|
inline void priority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args) {
|
2011-06-30 21:18:19 +00:00
|
|
|
c.emplace_back(std::forward<_Args>(__args)...);
|
|
|
|
std::push_heap(c.begin(), c.end(), comp);
|
2010-05-11 19:42:16 +00:00
|
|
|
}
|
|
|
|
|
2021-04-20 16:03:32 +00:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
template <class _Tp, class _Container, class _Compare>
|
|
|
|
inline void priority_queue<_Tp, _Container, _Compare>::pop() {
|
2011-06-30 21:18:19 +00:00
|
|
|
std::pop_heap(c.begin(), c.end(), comp);
|
2010-05-11 19:42:16 +00:00
|
|
|
c.pop_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Container, class _Compare>
|
|
|
|
inline void priority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q)
|
2011-06-04 21:32:33 +00:00
|
|
|
_NOEXCEPT_(__is_nothrow_swappable<container_type>::value&& __is_nothrow_swappable<value_compare>::value) {
|
2011-06-30 21:18:19 +00:00
|
|
|
using std::swap;
|
2010-05-11 19:42:16 +00:00
|
|
|
swap(c, __q.c);
|
|
|
|
swap(comp, __q.comp);
|
|
|
|
}
|
|
|
|
|
2023-09-02 00:52:02 +00:00
|
|
|
template <class _Tp,
|
|
|
|
class _Container,
|
|
|
|
class _Compare,
|
|
|
|
__enable_if_t<__is_swappable<_Container>::value && __is_swappable<_Compare>::value, int> = 0>
|
2010-09-22 18:02:38 +00:00
|
|
|
inline _LIBCPP_HIDE_FROM_ABI void
|
2010-05-11 19:42:16 +00:00
|
|
|
swap(priority_queue<_Tp, _Container, _Compare>& __x, priority_queue<_Tp, _Container, _Compare>& __y)
|
2011-06-04 21:32:33 +00:00
|
|
|
_NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
|
2010-05-11 19:42:16 +00:00
|
|
|
__x.swap(__y);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Container, class _Compare, class _Alloc>
|
2017-01-04 23:56:00 +00:00
|
|
|
struct _LIBCPP_TEMPLATE_VIS uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc>
|
2010-05-11 19:42:16 +00:00
|
|
|
: public uses_allocator<_Container, _Alloc> {};
|
|
|
|
|
|
|
|
_LIBCPP_END_NAMESPACE_STD
|
|
|
|
|
[🍒][libc++] Fix missing and incorrect push/pop macros (#79204) (#79497)
We recently noticed that the unwrap_iter.h file was pushing macros, but
it was pushing them again instead of popping them at the end of the
file. This led to libc++ basically swallowing any custom definition of
these macros in user code:
#define min HELLO
#include <algorithm>
// min is not HELLO anymore, it's not defined
While investigating this issue, I noticed that our push/pop pragmas were
actually entirely wrong too. Indeed, instead of pushing macros like
`move`, we'd push `move(int, int)` in the pragma, which is not a valid
macro name. As a result, we would not actually push macros like `move`
-- instead we'd simply undefine them. This led to the following code not
working:
#define move HELLO
#include <algorithm>
// move is not HELLO anymore
Fixing the pragma push/pop incantations led to a cascade of issues
because we use identifiers like `move` in a large number of places, and
all of these headers would now need to do the push/pop dance.
This patch fixes all these issues. First, it adds a check that we don't
swallow important names like min, max, move or refresh as explained
above. This is done by augmenting the existing
system_reserved_names.gen.py test to also check that the macros are what
we expect after including each header.
Second, it fixes the push/pop pragmas to work properly and adds missing
pragmas to all the files I could detect a failure in via the newly added
test.
rdar://121365472
(cherry picked from commit 7b4622514d232ce5f7110dd8b20d90e81127c467)
2024-02-02 01:51:34 +00:00
|
|
|
_LIBCPP_POP_MACROS
|
|
|
|
|
2022-09-04 22:01:15 +00:00
|
|
|
#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
|
2022-11-02 19:27:42 +00:00
|
|
|
# include <concepts>
|
2023-01-08 15:47:53 +00:00
|
|
|
# include <cstdlib>
|
2022-09-02 15:53:28 +00:00
|
|
|
# include <functional>
|
2023-02-12 11:32:36 +00:00
|
|
|
# include <type_traits>
|
2022-09-02 15:53:28 +00:00
|
|
|
#endif
|
|
|
|
|
2021-04-20 16:03:32 +00:00
|
|
|
#endif // _LIBCPP_QUEUE
|