Skip to content

Commit bb9e48d

Browse files
committed
[libc+][stack] P3372R3: constexpr <stack>
Implements `<stack>` as per P3372R3: `constexpr` containers and adaptors - https://wg21.link/P3372R3 Closes #128672 This should be a fairly straightforward implementation, as `std::stack` is a container adaptor, and most of the work is done in the underlying container. Depends on #128656 Part of #127876 - https://wg21.link/P3372R3 - https://eel.is/c++draft/#containers - https://eel.is/c++draft/container.adaptors#stack.syn - https://eel.is/c++draft/stack.syn - https://eel.is/c++draft/stack
1 parent f49e3d1 commit bb9e48d

File tree

17 files changed

+248
-93
lines changed

17 files changed

+248
-93
lines changed

libcxx/.clang-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ AttributeMacros: [
2525
'_LIBCPP_CONSTEXPR_SINCE_CXX17',
2626
'_LIBCPP_CONSTEXPR_SINCE_CXX20',
2727
'_LIBCPP_CONSTEXPR_SINCE_CXX23',
28+
'_LIBCPP_CONSTEXPR_SINCE_CXX26',
2829
'_LIBCPP_CONSTEXPR',
2930
'_LIBCPP_CONSTINIT',
3031
'_LIBCPP_DEPRECATED_IN_CXX11',

libcxx/include/stack

Lines changed: 92 additions & 73 deletions
Large diffs are not rendered by default.

libcxx/test/std/containers/container.adaptors/stack/compare.three_way.pass.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,21 @@
2424
#include "nasty_containers.h"
2525
#include "test_container_comparisons.h"
2626

27-
int main(int, char**) {
27+
TEST_CONSTEXPR_CXX26 bool test() {
2828
assert((test_sequence_container_adaptor_spaceship<std::stack, std::deque>()));
2929
assert((test_sequence_container_adaptor_spaceship<std::stack, std::list>()));
3030
assert((test_sequence_container_adaptor_spaceship<std::stack, std::vector>()));
3131
assert((test_sequence_container_adaptor_spaceship<std::stack, nasty_list>()));
3232
assert((test_sequence_container_adaptor_spaceship<std::stack, nasty_vector>()));
33-
// `std::stack` is not constexpr, so no `static_assert` test here.
33+
34+
return true;
35+
}
36+
37+
int main(int, char**) {
38+
test();
39+
#if TEST_STD_VER >= 26
40+
static_assert(test());
41+
#endif
42+
3443
return 0;
3544
}

libcxx/test/std/containers/container.adaptors/stack/stack.cons/ctor_default.pass.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# include "test_convertible.h"
2323
#endif
2424

25-
int main(int, char**) {
25+
TEST_CONSTEXPR_CXX26 bool test() {
2626
typedef std::vector<int, limited_allocator<int, 10> > Container;
2727
typedef std::stack<int, Container> Q;
2828
Q q;
@@ -37,5 +37,14 @@ int main(int, char**) {
3737
static_assert(test_convertible<Q>(), "");
3838
#endif
3939

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

libcxx/test/std/containers/container.adaptors/stack/stack.defn/emplace.pass.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void test_return_type() {
3636
#endif
3737
}
3838

39-
int main(int, char**) {
39+
TEST_CONSTEXPR_CXX26 bool test() {
4040
test_return_type<std::stack<int> >();
4141
test_return_type<std::stack<int, std::vector<int> > >();
4242

@@ -57,5 +57,14 @@ int main(int, char**) {
5757
assert(q.size() == 3);
5858
assert(q.top() == Emplaceable(3, 4.5));
5959

60+
return true;
61+
}
62+
63+
int main(int, char**) {
64+
test();
65+
#if TEST_STD_VER >= 26
66+
static_assert(test());
67+
#endif
68+
6069
return 0;
6170
}

libcxx/test/std/containers/container.adaptors/stack/stack.defn/empty.pass.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,22 @@
1515

1616
#include "test_macros.h"
1717

18-
int main(int, char**) {
18+
TEST_CONSTEXPR_CXX26 bool test() {
1919
std::stack<int> q;
2020
assert(q.empty());
2121
q.push(1);
2222
assert(!q.empty());
2323
q.pop();
2424
assert(q.empty());
2525

26+
return true;
27+
}
28+
29+
int main(int, char**) {
30+
test();
31+
#if TEST_STD_VER >= 26
32+
static_assert(test());
33+
#endif
34+
2635
return 0;
2736
}

libcxx/test/std/containers/container.adaptors/stack/stack.defn/pop.pass.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#include "test_macros.h"
1717

18-
int main(int, char**) {
18+
TEST_CONSTEXPR_CXX26 bool test() {
1919
std::stack<int> q;
2020
assert(q.size() == 0);
2121
q.push(1);
@@ -32,5 +32,14 @@ int main(int, char**) {
3232
q.pop();
3333
assert(q.size() == 0);
3434

35+
return true;
36+
}
37+
38+
int main(int, char**) {
39+
test();
40+
#if TEST_STD_VER >= 26
41+
static_assert(test());
42+
#endif
43+
3544
return 0;
3645
}

libcxx/test/std/containers/container.adaptors/stack/stack.defn/push.pass.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#include "test_macros.h"
1717

18-
int main(int, char**) {
18+
TEST_CONSTEXPR_CXX26 bool test() {
1919
std::stack<int> q;
2020
q.push(1);
2121
assert(q.size() == 1);
@@ -29,3 +29,12 @@ int main(int, char**) {
2929

3030
return 0;
3131
}
32+
33+
int main(int, char**) {
34+
test();
35+
#if TEST_STD_VER >= 26
36+
static_assert(test());
37+
#endif
38+
39+
return 0;
40+
}

libcxx/test/std/containers/container.adaptors/stack/stack.defn/push_range.pass.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "../../push_range_container_adaptors.h"
1818
#include "test_macros.h"
1919

20-
int main(int, char**) {
20+
TEST_CONSTEXPR_CXX26 bool test() {
2121
for_all_iterators_and_allocators<int, const int*>([]<class Iter, class Sent, class Alloc>() {
2222
test_push_range<std::stack<int, std::deque<int, Alloc>>, Iter, Sent>();
2323
});
@@ -29,5 +29,14 @@ int main(int, char**) {
2929
test_push_range_exception_safety_throwing_copy<std::stack>();
3030
test_push_range_exception_safety_throwing_allocator<std::stack, std::deque, int>();
3131

32+
return true;
33+
}
34+
35+
int main(int, char**) {
36+
test();
37+
#if TEST_STD_VER >= 26
38+
static_assert(test());
39+
#endif
40+
3241
return 0;
3342
}

libcxx/test/std/containers/container.adaptors/stack/stack.defn/push_rv.pass.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "test_macros.h"
1919
#include "MoveOnly.h"
2020

21-
int main(int, char**) {
21+
TEST_CONSTEXPR_CXX26 bool test() {
2222
std::stack<MoveOnly> q;
2323
q.push(MoveOnly(1));
2424
assert(q.size() == 1);
@@ -30,5 +30,14 @@ int main(int, char**) {
3030
assert(q.size() == 3);
3131
assert(q.top() == MoveOnly(3));
3232

33+
return true;
34+
}
35+
36+
int main(int, char**) {
37+
test();
38+
#if TEST_STD_VER >= 26
39+
static_assert(test());
40+
#endif
41+
3342
return 0;
3443
}

0 commit comments

Comments
 (0)