Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,27 @@
// out there are in that situation.
// https://github.com/llvm/llvm-project/issues/136656

#include <algorithm>
#include <cassert>
#include <flat_set>
#include <ranges>
#include <sstream>
#include <vector>

#include "MinSequenceContainer.h"
#include "../flat_helpers.h"
#include "test_macros.h"

void test() {
MinSequenceContainer<int> v;
NotQuiteSequenceContainer<int> v;
std::flat_multiset s(v);
std::istringstream ints("0 1 1 0");
auto r = std::ranges::subrange(std::istream_iterator<int>(ints), std::istream_iterator<int>()) |
std::views::transform([](int i) { return i * i; });
static_assert(
![](auto& t) { return requires { t.insert_range(r); }; }(v),
![](auto& t) { return requires { t.insert_range(t.end(), r); }; }(v),
"This test is to test the case where the underlying container does not provide insert_range");
s.insert_range(r);
assert(std::ranges::equal(s, std::vector<int>{0, 0, 1, 1}));
}

int main(int, char**) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,27 @@
// out there are in that situation.
// https://github.com/llvm/llvm-project/issues/136656

#include <algorithm>
#include <cassert>
#include <flat_set>
#include <ranges>
#include <sstream>
#include <vector>

#include "MinSequenceContainer.h"
#include "../flat_helpers.h"
#include "test_macros.h"

void test() {
MinSequenceContainer<int> v;
NotQuiteSequenceContainer<int> v;
std::flat_set s(v);
std::istringstream ints("0 1 1 0");
auto r = std::ranges::subrange(std::istream_iterator<int>(ints), std::istream_iterator<int>()) |
std::views::transform([](int i) { return i * i; });
static_assert(
![](auto& t) { return requires { t.insert_range(r); }; }(v),
![](auto& t) { return requires { t.insert_range(t.end(), r); }; }(v),
"This test is to test the case where the underlying container does not provide insert_range");
s.insert_range(r);
assert(std::ranges::equal(s, std::vector<int>{0, 1}));
}

int main(int, char**) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#ifndef TEST_LIBCXX_CONTAINERS_CONTAINER_ADAPTORS_FLAT_HELPERS_H
#define TEST_LIBCXX_CONTAINERS_CONTAINER_ADAPTORS_FLAT_HELPERS_H

#include <vector>

struct TrackCopyMove {
mutable int copy_count = 0;
int move_count = 0;
Expand Down Expand Up @@ -37,4 +39,10 @@ struct TrackCopyMove {
constexpr bool operator<(const TrackCopyMove&) const { return false; }
};

template <class T>
struct NotQuiteSequenceContainer : std::vector<T> {
// hide the name insert_range
void insert_range() = delete;
};

#endif // TEST_LIBCXX_CONTAINERS_CONTAINER_ADAPTORS_FLAT_HELPERS_H
Loading