Skip to content

Commit feb2591

Browse files
committed
constexpr priority_queue
1 parent dbfd0fd commit feb2591

38 files changed

+532
-170
lines changed

libcxx/docs/FeatureTestMacroTable.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,8 @@ Status
422422
---------------------------------------------------------- -----------------
423423
``__cpp_lib_constexpr_new`` ``202406L``
424424
---------------------------------------------------------- -----------------
425+
``__cpp_lib_constexpr_queue`` ``202502L``
426+
---------------------------------------------------------- -----------------
425427
``__cpp_lib_constrained_equality`` *unimplemented*
426428
---------------------------------------------------------- -----------------
427429
``__cpp_lib_copyable_function`` *unimplemented*

libcxx/include/queue

Lines changed: 77 additions & 61 deletions
Large diffs are not rendered by default.

libcxx/include/version

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ __cpp_lib_constexpr_memory 202202L <memory>
7474
201811L // C++20
7575
__cpp_lib_constexpr_new 202406L <new>
7676
__cpp_lib_constexpr_numeric 201911L <numeric>
77+
__cpp_lib_constexpr_queue 202502L <queue>
7778
__cpp_lib_constexpr_string 201907L <string>
7879
__cpp_lib_constexpr_string_view 201811L <string_view>
7980
__cpp_lib_constexpr_tuple 201811L <tuple>
@@ -545,6 +546,7 @@ __cpp_lib_void_t 201411L <type_traits>
545546
# if !defined(_LIBCPP_ABI_VCRUNTIME)
546547
# define __cpp_lib_constexpr_new 202406L
547548
# endif
549+
# define __cpp_lib_constexpr_queue 202502L
548550
// # define __cpp_lib_constrained_equality 202403L
549551
// # define __cpp_lib_copyable_function 202306L
550552
// # define __cpp_lib_debugging 202311L

libcxx/test/std/containers/Emplaceable.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,41 @@
1515
#if TEST_STD_VER >= 11
1616

1717
class Emplaceable {
18-
Emplaceable(const Emplaceable&);
19-
Emplaceable& operator=(const Emplaceable&);
18+
TEST_CONSTEXPR Emplaceable(const Emplaceable&);
19+
TEST_CONSTEXPR_CXX14 Emplaceable& operator=(const Emplaceable&);
2020

2121
int int_;
2222
double double_;
2323

2424
public:
25-
Emplaceable() : int_(0), double_(0) {}
26-
Emplaceable(int i, double d) : int_(i), double_(d) {}
27-
Emplaceable(Emplaceable&& x) : int_(x.int_), double_(x.double_) {
25+
TEST_CONSTEXPR Emplaceable() : int_(0), double_(0) {}
26+
TEST_CONSTEXPR Emplaceable(int i, double d) : int_(i), double_(d) {}
27+
TEST_CONSTEXPR_CXX14 Emplaceable(Emplaceable&& x) : int_(x.int_), double_(x.double_) {
2828
x.int_ = 0;
2929
x.double_ = 0;
3030
}
31-
Emplaceable& operator=(Emplaceable&& x) {
31+
TEST_CONSTEXPR_CXX14 Emplaceable& operator=(Emplaceable&& x) {
3232
int_ = x.int_;
3333
x.int_ = 0;
3434
double_ = x.double_;
3535
x.double_ = 0;
3636
return *this;
3737
}
3838

39-
bool operator==(const Emplaceable& x) const { return int_ == x.int_ && double_ == x.double_; }
40-
bool operator<(const Emplaceable& x) const { return int_ < x.int_ || (int_ == x.int_ && double_ < x.double_); }
39+
TEST_CONSTEXPR bool operator==(const Emplaceable& x) const { return int_ == x.int_ && double_ == x.double_; }
40+
TEST_CONSTEXPR bool operator<(const Emplaceable& x) const {
41+
return int_ < x.int_ || (int_ == x.int_ && double_ < x.double_);
42+
}
4143

42-
int get() const { return int_; }
44+
TEST_CONSTEXPR int get() const { return int_; }
4345
};
4446

4547
template <>
4648
struct std::hash<Emplaceable> {
4749
typedef Emplaceable argument_type;
4850
typedef std::size_t result_type;
4951

50-
std::size_t operator()(const Emplaceable& x) const { return static_cast<std::size_t>(x.get()); }
52+
TEST_CONSTEXPR std::size_t operator()(const Emplaceable& x) const { return static_cast<std::size_t>(x.get()); }
5153
};
5254

5355
#endif // TEST_STD_VER >= 11

libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_alloc.pass.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,38 @@
1818
#include "test_allocator.h"
1919

2020
template <class T>
21-
struct test : public std::priority_queue<T, std::vector<T, test_allocator<T> > > {
21+
struct Test : public std::priority_queue<T, std::vector<T, test_allocator<T> > > {
2222
typedef std::priority_queue<T, std::vector<T, test_allocator<T> > > base;
2323
typedef typename base::container_type container_type;
2424
typedef typename base::value_compare value_compare;
2525

26-
explicit test(const test_allocator<int>& a) : base(a) {}
27-
test(const value_compare& comp, const test_allocator<int>& a) : base(comp, c, a) {}
28-
test(const value_compare& comp, const container_type& container, const test_allocator<int>& a)
26+
TEST_CONSTEXPR_CXX26 explicit Test(const test_allocator<int>& a) : base(a) {}
27+
TEST_CONSTEXPR_CXX26 Test(const value_compare& comp, const test_allocator<int>& a) : base(comp, c, a) {}
28+
TEST_CONSTEXPR_CXX26 Test(const value_compare& comp, const container_type& container, const test_allocator<int>& a)
2929
: base(comp, container, a) {}
3030
#if TEST_STD_VER >= 11
31-
test(const value_compare& comp, container_type&& container, const test_allocator<int>& a)
31+
TEST_CONSTEXPR_CXX26 Test(const value_compare& comp, container_type&& container, const test_allocator<int>& a)
3232
: base(comp, std::move(container), a) {}
33-
test(test&& q, const test_allocator<int>& a) : base(std::move(q), a) {}
33+
TEST_CONSTEXPR_CXX26 Test(Test&& q, const test_allocator<int>& a) : base(std::move(q), a) {}
3434
#endif
35-
test_allocator<int> get_allocator() { return c.get_allocator(); }
35+
TEST_CONSTEXPR_CXX26 test_allocator<int> get_allocator() { return c.get_allocator(); }
3636

3737
using base::c;
3838
};
3939

40-
int main(int, char**) {
41-
test<int> q((test_allocator<int>(3)));
40+
TEST_CONSTEXPR_CXX26 bool test() {
41+
Test<int> q((test_allocator<int>(3)));
4242
assert(q.c.get_allocator() == test_allocator<int>(3));
4343
assert(q.c.size() == 0);
4444

45+
return true;
46+
}
47+
48+
int main(int, char**) {
49+
assert(test());
50+
#if TEST_STD_VER >= 26
51+
static_assert(test());
52+
#endif
53+
4554
return 0;
4655
}

libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_comp_alloc.pass.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,38 @@
1818
#include "test_allocator.h"
1919

2020
template <class T>
21-
struct test : public std::priority_queue<T, std::vector<T, test_allocator<T> > > {
21+
struct Test : public std::priority_queue<T, std::vector<T, test_allocator<T> > > {
2222
typedef std::priority_queue<T, std::vector<T, test_allocator<T> > > base;
2323
typedef typename base::container_type container_type;
2424
typedef typename base::value_compare value_compare;
2525

26-
explicit test(const test_allocator<int>& a) : base(a) {}
27-
test(const value_compare& compare, const test_allocator<int>& a) : base(compare, a) {}
28-
test(const value_compare& compare, const container_type& container, const test_allocator<int>& a)
26+
TEST_CONSTEXPR_CXX26 explicit Test(const test_allocator<int>& a) : base(a) {}
27+
TEST_CONSTEXPR_CXX26 Test(const value_compare& compare, const test_allocator<int>& a) : base(compare, a) {}
28+
TEST_CONSTEXPR_CXX26 Test(const value_compare& compare, const container_type& container, const test_allocator<int>& a)
2929
: base(compare, container, a) {}
3030
#if TEST_STD_VER >= 11
31-
test(const value_compare& compare, container_type&& container, const test_allocator<int>& a)
31+
TEST_CONSTEXPR_CXX26 Test(const value_compare& compare, container_type&& container, const test_allocator<int>& a)
3232
: base(compare, std::move(container), a) {}
33-
test(test&& q, const test_allocator<int>& a) : base(std::move(q), a) {}
33+
TEST_CONSTEXPR_CXX26 Test(Test&& q, const test_allocator<int>& a) : base(std::move(q), a) {}
3434
#endif
35-
test_allocator<int> get_allocator() { return c.get_allocator(); }
35+
TEST_CONSTEXPR_CXX26 test_allocator<int> get_allocator() { return c.get_allocator(); }
3636

3737
using base::c;
3838
};
3939

40-
int main(int, char**) {
41-
test<int> q(std::less<int>(), test_allocator<int>(3));
40+
TEST_CONSTEXPR_CXX26 bool test() {
41+
Test<int> q(std::less<int>(), test_allocator<int>(3));
4242
assert(q.c.get_allocator() == test_allocator<int>(3));
4343
assert(q.c.size() == 0);
4444

45-
return 0;
45+
return true;
4646
}
47+
48+
int main(int, char**) {
49+
assert(test());
50+
#if TEST_STD_VER >= 26
51+
static_assert(test());
52+
#endif
53+
54+
return 0;
55+
}

libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_comp_cont_alloc.pass.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,40 +19,49 @@
1919
#include "test_allocator.h"
2020

2121
template <class C>
22-
C make(int n) {
22+
TEST_CONSTEXPR_CXX26 C make(int n) {
2323
C c;
2424
for (int i = 0; i < n; ++i)
2525
c.push_back(i);
2626
return c;
2727
}
2828

2929
template <class T>
30-
struct test : public std::priority_queue<T, std::vector<T, test_allocator<T> > > {
30+
struct Test : public std::priority_queue<T, std::vector<T, test_allocator<T> > > {
3131
typedef std::priority_queue<T, std::vector<T, test_allocator<T> > > base;
3232
typedef typename base::container_type container_type;
3333
typedef typename base::value_compare value_compare;
3434

35-
explicit test(const test_allocator<int>& a) : base(a) {}
36-
test(const value_compare& compare, const test_allocator<int>& a) : base(compare, a) {}
37-
test(const value_compare& compare, const container_type& container, const test_allocator<int>& a)
35+
TEST_CONSTEXPR_CXX26 explicit Test(const test_allocator<int>& a) : base(a) {}
36+
TEST_CONSTEXPR_CXX26 Test(const value_compare& compare, const test_allocator<int>& a) : base(compare, a) {}
37+
TEST_CONSTEXPR_CXX26 Test(const value_compare& compare, const container_type& container, const test_allocator<int>& a)
3838
: base(compare, container, a) {}
3939
#if TEST_STD_VER >= 11 // testing rvalue constructor
40-
test(const value_compare& compare, container_type&& container, const test_allocator<int>& a)
40+
TEST_CONSTEXPR_CXX26 Test(const value_compare& compare, container_type&& container, const test_allocator<int>& a)
4141
: base(compare, std::move(container), a) {}
42-
test(test&& q, const test_allocator<int>& a) : base(std::move(q), a) {}
42+
TEST_CONSTEXPR_CXX26 Test(Test&& q, const test_allocator<int>& a) : base(std::move(q), a) {}
4343
#endif
44-
test_allocator<int> get_allocator() { return c.get_allocator(); }
44+
TEST_CONSTEXPR_CXX26 test_allocator<int> get_allocator() { return c.get_allocator(); }
4545

4646
using base::c;
4747
};
4848

49-
int main(int, char**) {
49+
TEST_CONSTEXPR_CXX26 bool test() {
5050
typedef std::vector<int, test_allocator<int> > C;
5151
C v = make<C>(5);
52-
test<int> q(std::less<int>(), v, test_allocator<int>(3));
52+
Test<int> q(std::less<int>(), v, test_allocator<int>(3));
5353
assert(q.c.get_allocator() == test_allocator<int>(3));
5454
assert(q.size() == 5);
5555
assert(q.top() == 4);
5656

57-
return 0;
57+
return true;
5858
}
59+
60+
int main(int, char**) {
61+
assert(test());
62+
#if TEST_STD_VER >= 26
63+
static_assert(test());
64+
#endif
65+
66+
return 0;
67+
}

libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_comp_rcont_alloc.pass.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,48 @@
1919
#include "test_allocator.h"
2020

2121
template <class C>
22-
C make(int n) {
22+
TEST_CONSTEXPR_CXX26 C make(int n) {
2323
C c;
2424
for (int i = 0; i < n; ++i)
2525
c.push_back(i);
2626
return c;
2727
}
2828

2929
template <class T>
30-
struct test : public std::priority_queue<T, std::vector<T, test_allocator<T> > > {
30+
struct Test : public std::priority_queue<T, std::vector<T, test_allocator<T> > > {
3131
typedef std::priority_queue<T, std::vector<T, test_allocator<T> > > base;
3232
typedef typename base::container_type container_type;
3333
typedef typename base::value_compare value_compare;
3434

35-
explicit test(const test_allocator<int>& a) : base(a) {}
36-
test(const value_compare& compare, const test_allocator<int>& a) : base(compare, a) {}
37-
test(const value_compare& compare, const container_type& container, const test_allocator<int>& a)
35+
TEST_CONSTEXPR_CXX26 explicit Test(const test_allocator<int>& a) : base(a) {}
36+
TEST_CONSTEXPR_CXX26 Test(const value_compare& compare, const test_allocator<int>& a) : base(compare, a) {}
37+
TEST_CONSTEXPR_CXX26 Test(const value_compare& compare, const container_type& container, const test_allocator<int>& a)
3838
: base(compare, container, a) {}
3939
#if TEST_STD_VER >= 11 // testing rvalue ctor
40-
test(const value_compare& compare, container_type&& container, const test_allocator<int>& a)
40+
TEST_CONSTEXPR_CXX26 Test(const value_compare& compare, container_type&& container, const test_allocator<int>& a)
4141
: base(compare, std::move(container), a) {}
42-
test(test&& q, const test_allocator<int>& a) : base(std::move(q), a) {}
42+
TEST_CONSTEXPR_CXX26 Test(Test&& q, const test_allocator<int>& a) : base(std::move(q), a) {}
4343
#endif
44-
test_allocator<int> get_allocator() { return c.get_allocator(); }
44+
TEST_CONSTEXPR_CXX26 test_allocator<int> get_allocator() { return c.get_allocator(); }
4545

4646
using base::c;
4747
};
4848

49-
int main(int, char**) {
49+
TEST_CONSTEXPR_CXX26 bool test() {
5050
typedef std::vector<int, test_allocator<int> > C;
51-
test<int> q(std::less<int>(), make<C>(5), test_allocator<int>(3));
51+
Test<int> q(std::less<int>(), make<C>(5), test_allocator<int>(3));
5252
assert(q.c.get_allocator() == test_allocator<int>(3));
5353
assert(q.size() == 5);
5454
assert(q.top() == 4);
5555

56+
return true;
57+
}
58+
59+
int main(int, char**) {
60+
assert(test());
61+
#if TEST_STD_VER >= 26
62+
static_assert(test());
63+
#endif
64+
5665
return 0;
5766
}

libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_copy_alloc.pass.cpp

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
#include <queue>
1515
#include <cassert>
1616

17+
#include "test_macros.h"
18+
1719
template <class C>
18-
C make(int n) {
20+
TEST_CONSTEXPR_CXX26 C make(int n) {
1921
C c;
2022
for (int i = 0; i < n; ++i)
2123
c.push_back(i);
@@ -26,27 +28,36 @@ C make(int n) {
2628
#include "test_allocator.h"
2729

2830
template <class T>
29-
struct test : public std::priority_queue<T, std::vector<T, test_allocator<T> > > {
31+
struct Test : public std::priority_queue<T, std::vector<T, test_allocator<T> > > {
3032
typedef std::priority_queue<T, std::vector<T, test_allocator<T> > > base;
3133
typedef typename base::container_type container_type;
3234
typedef typename base::value_compare value_compare;
3335

34-
explicit test(const test_allocator<int>& a) : base(a) {}
35-
test(const value_compare& compare, const test_allocator<int>& a) : base(compare, c, a) {}
36-
test(const value_compare& compare, const container_type& container, const test_allocator<int>& a)
36+
TEST_CONSTEXPR_CXX26 explicit Test(const test_allocator<int>& a) : base(a) {}
37+
TEST_CONSTEXPR_CXX26 Test(const value_compare& compare, const test_allocator<int>& a) : base(compare, c, a) {}
38+
TEST_CONSTEXPR_CXX26 Test(const value_compare& compare, const container_type& container, const test_allocator<int>& a)
3739
: base(compare, container, a) {}
38-
test(const test& q, const test_allocator<int>& a) : base(q, a) {}
39-
test_allocator<int> get_allocator() { return c.get_allocator(); }
40+
TEST_CONSTEXPR_CXX26 Test(const Test& q, const test_allocator<int>& a) : base(q, a) {}
41+
TEST_CONSTEXPR_CXX26 test_allocator<int> get_allocator() { return c.get_allocator(); }
4042

4143
using base::c;
4244
};
4345

44-
int main(int, char**) {
45-
test<int> qo(std::less<int>(), make<std::vector<int, test_allocator<int> > >(5), test_allocator<int>(2));
46-
test<int> q(qo, test_allocator<int>(6));
46+
TEST_CONSTEXPR_CXX26 bool test() {
47+
Test<int> qo(std::less<int>(), make<std::vector<int, test_allocator<int> > >(5), test_allocator<int>(2));
48+
Test<int> q(qo, test_allocator<int>(6));
4749
assert(q.size() == 5);
4850
assert(q.c.get_allocator() == test_allocator<int>(6));
4951
assert(q.top() == int(4));
5052

53+
return true;
54+
}
55+
56+
int main(int, char**) {
57+
assert(test());
58+
#if TEST_STD_VER >= 26
59+
static_assert(test());
60+
#endif
61+
5162
return 0;
5263
}

libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_iter_iter_alloc.pass.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,27 @@ struct PQ : std::priority_queue<T, Cont, Comp> {
2323
typedef std::priority_queue<T, Cont, Comp> base;
2424

2525
template <class It, class Alloc>
26-
explicit PQ(It first, It last, const Alloc& a) : base(first, last, a) {}
26+
TEST_CONSTEXPR_CXX26 explicit PQ(It first, It last, const Alloc& a) : base(first, last, a) {}
2727

2828
using base::c;
2929
};
3030

31-
int main(int, char**) {
31+
TEST_CONSTEXPR_CXX26 bool test() {
3232
int a[] = {3, 5, 2, 0, 6, 8, 1};
3333
typedef test_allocator<int> Alloc;
3434
PQ<int, std::vector<int, Alloc> > q(a, a + 7, Alloc(2));
3535
assert(q.size() == 7);
3636
assert(q.top() == 8);
3737
assert(q.c.get_allocator() == Alloc(2));
3838

39+
return true;
40+
}
41+
42+
int main(int, char**) {
43+
assert(test());
44+
#if TEST_STD_VER >= 26
45+
static_assert(test());
46+
#endif
47+
3948
return 0;
4049
}

0 commit comments

Comments
 (0)