Skip to content

Commit 665148d

Browse files
authored
[libc++][test] Fix test not relying on MinSequenceContainer (llvm#140372)
The affected tests are relying on the fact that `MinSequenceContainer` does not have `insert_range`. This prevents landing of llvm#140287. This PR creates a new helper class to allow the change in MinSequenceContainer.
1 parent c87edaf commit 665148d

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

libcxx/test/libcxx/containers/container.adaptors/flat.multiset/insert_range.pass.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,27 @@
1616
// out there are in that situation.
1717
// https://github.com/llvm/llvm-project/issues/136656
1818

19+
#include <algorithm>
20+
#include <cassert>
1921
#include <flat_set>
2022
#include <ranges>
2123
#include <sstream>
2224
#include <vector>
2325

24-
#include "MinSequenceContainer.h"
26+
#include "../flat_helpers.h"
2527
#include "test_macros.h"
2628

2729
void test() {
28-
MinSequenceContainer<int> v;
30+
NotQuiteSequenceContainer<int> v;
2931
std::flat_multiset s(v);
3032
std::istringstream ints("0 1 1 0");
3133
auto r = std::ranges::subrange(std::istream_iterator<int>(ints), std::istream_iterator<int>()) |
3234
std::views::transform([](int i) { return i * i; });
3335
static_assert(
34-
![](auto& t) { return requires { t.insert_range(r); }; }(v),
36+
![](auto& t) { return requires { t.insert_range(t.end(), r); }; }(v),
3537
"This test is to test the case where the underlying container does not provide insert_range");
3638
s.insert_range(r);
39+
assert(std::ranges::equal(s, std::vector<int>{0, 0, 1, 1}));
3740
}
3841

3942
int main(int, char**) {

libcxx/test/libcxx/containers/container.adaptors/flat.set/insert_range.pass.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,27 @@
1616
// out there are in that situation.
1717
// https://github.com/llvm/llvm-project/issues/136656
1818

19+
#include <algorithm>
20+
#include <cassert>
1921
#include <flat_set>
2022
#include <ranges>
2123
#include <sstream>
2224
#include <vector>
2325

24-
#include "MinSequenceContainer.h"
26+
#include "../flat_helpers.h"
2527
#include "test_macros.h"
2628

2729
void test() {
28-
MinSequenceContainer<int> v;
30+
NotQuiteSequenceContainer<int> v;
2931
std::flat_set s(v);
3032
std::istringstream ints("0 1 1 0");
3133
auto r = std::ranges::subrange(std::istream_iterator<int>(ints), std::istream_iterator<int>()) |
3234
std::views::transform([](int i) { return i * i; });
3335
static_assert(
34-
![](auto& t) { return requires { t.insert_range(r); }; }(v),
36+
![](auto& t) { return requires { t.insert_range(t.end(), r); }; }(v),
3537
"This test is to test the case where the underlying container does not provide insert_range");
3638
s.insert_range(r);
39+
assert(std::ranges::equal(s, std::vector<int>{0, 1}));
3740
}
3841

3942
int main(int, char**) {

libcxx/test/libcxx/containers/container.adaptors/flat_helpers.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#ifndef TEST_LIBCXX_CONTAINERS_CONTAINER_ADAPTORS_FLAT_HELPERS_H
1010
#define TEST_LIBCXX_CONTAINERS_CONTAINER_ADAPTORS_FLAT_HELPERS_H
1111

12+
#include <vector>
13+
1214
struct TrackCopyMove {
1315
mutable int copy_count = 0;
1416
int move_count = 0;
@@ -37,4 +39,10 @@ struct TrackCopyMove {
3739
constexpr bool operator<(const TrackCopyMove&) const { return false; }
3840
};
3941

42+
template <class T>
43+
struct NotQuiteSequenceContainer : std::vector<T> {
44+
// hide the name insert_range
45+
void insert_range() = delete;
46+
};
47+
4048
#endif // TEST_LIBCXX_CONTAINERS_CONTAINER_ADAPTORS_FLAT_HELPERS_H

0 commit comments

Comments
 (0)