-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[libc++] Implement part of P2562R1: constexpr std::stable_partition
#128868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e70a02f
81986a6
b9b392a
cc7878b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
// template<BidirectionalIterator Iter, Predicate<auto, Iter::value_type> Pred> | ||
// requires ShuffleIterator<Iter> | ||
// && CopyConstructible<Pred> | ||
// Iter | ||
// constexpr Iter // constexpr since C++26 | ||
// stable_partition(Iter first, Iter last, Pred pred); | ||
|
||
#include <algorithm> | ||
|
@@ -23,21 +23,16 @@ | |
#include "test_iterators.h" | ||
#include "test_macros.h" | ||
|
||
struct is_odd | ||
{ | ||
bool operator()(const int& i) const {return i & 1;} | ||
struct is_odd { | ||
TEST_CONSTEXPR_CXX26 bool operator()(const int& i) const { return i & 1; } | ||
}; | ||
|
||
struct odd_first | ||
{ | ||
bool operator()(const std::pair<int,int>& p) const | ||
{return p.first & 1;} | ||
struct odd_first { | ||
TEST_CONSTEXPR_CXX26 bool operator()(const std::pair<int, int>& p) const { return p.first & 1; } | ||
}; | ||
|
||
template <class Iter> | ||
void | ||
test() | ||
{ | ||
TEST_CONSTEXPR_CXX26 void test() { | ||
{ // check mixed | ||
typedef std::pair<int,int> P; | ||
P array[] = | ||
|
@@ -282,10 +277,10 @@ test() | |
assert(array[9] == P(0, 2)); | ||
} | ||
#if TEST_STD_VER >= 11 && !defined(TEST_HAS_NO_EXCEPTIONS) | ||
// TODO: Re-enable this test once we get recursive inlining fixed. | ||
// TODO: Re-enable this test for GCC once we get recursive inlining fixed. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you know whether there is a GCC bug report? If there is it would be great to add a link here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that this is not a GCC bug. When compiling with GCC, our https://reviews.llvm.org/D154161 is related. |
||
// For now it trips up GCC due to the use of always_inline. | ||
# if 0 | ||
{ // check that the algorithm still works when no memory is available | ||
# if !defined(TEST_COMPILER_GCC) | ||
frederick-vs-ja marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (!TEST_IS_CONSTANT_EVALUATED) { // check that the algorithm still works when no memory is available | ||
std::vector<int> vec(150, 3); | ||
vec[5] = 6; | ||
getGlobalMemCounter()->throw_after = 0; | ||
|
@@ -300,38 +295,45 @@ test() | |
assert(std::is_partitioned(vec.begin(), vec.end(), [](int i) { return i < 5; })); | ||
getGlobalMemCounter()->reset(); | ||
} | ||
# endif | ||
#endif // TEST_STD_VER >= 11 && !defined(TEST_HAS_NO_EXCEPTIONS) | ||
# endif // !defined(TEST_COMPILER_GCC) | ||
#endif // TEST_STD_VER >= 11 && !defined(TEST_HAS_NO_EXCEPTIONS) | ||
} | ||
|
||
#if TEST_STD_VER >= 11 | ||
|
||
struct is_null | ||
{ | ||
template <class P> | ||
bool operator()(const P& p) {return p == 0;} | ||
struct is_null { | ||
template <class P> | ||
TEST_CONSTEXPR_CXX26 bool operator()(const P& p) { | ||
return p == 0; | ||
} | ||
}; | ||
|
||
template <class Iter> | ||
void | ||
test1() | ||
{ | ||
const unsigned size = 5; | ||
std::unique_ptr<int> array[size]; | ||
Iter r = std::stable_partition(Iter(array), Iter(array+size), is_null()); | ||
assert(r == Iter(array+size)); | ||
TEST_CONSTEXPR_CXX26 void test1() { | ||
const unsigned size = 5; | ||
std::unique_ptr<int> array[size]; | ||
Iter r = std::stable_partition(Iter(array), Iter(array + size), is_null()); | ||
assert(r == Iter(array + size)); | ||
} | ||
|
||
#endif // TEST_STD_VER >= 11 | ||
|
||
int main(int, char**) | ||
{ | ||
test<bidirectional_iterator<std::pair<int,int>*> >(); | ||
test<random_access_iterator<std::pair<int,int>*> >(); | ||
test<std::pair<int,int>*>(); | ||
TEST_CONSTEXPR_CXX26 bool test() { | ||
test<bidirectional_iterator<std::pair<int, int>*> >(); | ||
test<random_access_iterator<std::pair<int, int>*> >(); | ||
test<std::pair<int, int>*>(); | ||
|
||
#if TEST_STD_VER >= 11 | ||
test1<bidirectional_iterator<std::unique_ptr<int>*> >(); | ||
test1<bidirectional_iterator<std::unique_ptr<int>*> >(); | ||
#endif | ||
|
||
return true; | ||
} | ||
|
||
int main(int, char**) { | ||
test(); | ||
#if TEST_STD_VER >= 26 | ||
static_assert(test()); | ||
#endif | ||
|
||
return 0; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,9 +240,14 @@ TEST_CONSTEXPR_CXX20 bool all_the_algorithms() | |
(void)std::sort(first, last, std::less<void*>()); | ||
(void)std::sort_heap(first, last); | ||
(void)std::sort_heap(first, last, std::less<void*>()); | ||
if (!TEST_IS_CONSTANT_EVALUATED) (void)std::stable_partition(first, last, UnaryTrue()); | ||
if (!TEST_IS_CONSTANT_EVALUATED) (void)std::stable_sort(first, last); | ||
if (!TEST_IS_CONSTANT_EVALUATED) (void)std::stable_sort(first, last, std::less<void*>()); | ||
#if TEST_STD_VER < 26 | ||
if (!TEST_IS_CONSTANT_EVALUATED) | ||
#endif | ||
{ | ||
(void)std::stable_partition(first, last, UnaryTrue()); | ||
(void)std::stable_sort(first, last); | ||
(void)std::stable_sort(first, last, std::less<void*>()); | ||
Comment on lines
+248
to
+249
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part was drive-by. I changed the lines because they were adjacent to the line for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I saw an open |
||
} | ||
(void)std::swap_ranges(first, last, first2); | ||
(void)std::transform(first, last, first2, UnaryTransform()); | ||
(void)std::transform(first, mid, mid, first2, BinaryTransform()); | ||
|
Uh oh!
There was an error while loading. Please reload this page.