Initial commit

This commit is contained in:
Yervant7
2024-01-16 19:28:29 -03:00
commit 8c0524dc0f
9054 changed files with 1081727 additions and 0 deletions
@@ -0,0 +1,207 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <algorithm>
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: libcpp-has-no-incomplete-ranges
// template<permutable I, sentinel_for<I> S, class T, class Proj = identity>
// requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
// constexpr subrange<I> ranges::remove(I first, S last, const T& value, Proj proj = {});
// template<forward_range R, class T, class Proj = identity>
// requires permutable<iterator_t<R>> &&
// indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
// constexpr borrowed_subrange_t<R>
// ranges::remove(R&& r, const T& value, Proj proj = {});
#include <algorithm>
#include <array>
#include <cassert>
#include <ranges>
#include "almost_satisfies_types.h"
#include "boolean_testable.h"
#include "test_iterators.h"
template <class Iter, class Sent = sentinel_wrapper<Iter>>
concept HasRemoveIt = requires(Iter first, Sent last) { std::ranges::remove(first, last, 0); };
static_assert(HasRemoveIt<int*>);
static_assert(!HasRemoveIt<PermutableNotForwardIterator>);
static_assert(!HasRemoveIt<PermutableNotSwappable>);
static_assert(!HasRemoveIt<int*, SentinelForNotSemiregular>);
static_assert(!HasRemoveIt<int*, SentinelForNotWeaklyEqualityComparableWith>);
static_assert(!HasRemoveIt<int**>); // not indirect_binary_prediacte
template <class Range>
concept HasRemoveR = requires(Range range) { std::ranges::remove(range, 0); };
static_assert(HasRemoveR<UncheckedRange<int*>>);
static_assert(!HasRemoveR<PermutableRangeNotForwardIterator>);
static_assert(!HasRemoveR<PermutableRangeNotSwappable>);
static_assert(!HasRemoveR<SentinelForNotSemiregular>);
static_assert(!HasRemoveR<SentinelForNotWeaklyEqualityComparableWith>);
static_assert(!HasRemoveR<UncheckedRange<int**>>); // not indirect_binary_prediacte
template <int N, int M>
struct Data {
std::array<int, N> input;
std::array<int, M> expected;
int val;
};
template <class Iter, class Sent, int N, int M>
constexpr void test(Data<N, M> d) {
{ // iterator overload
auto input = d.input;
std::same_as<std::ranges::subrange<Iter>> decltype(auto) ret =
std::ranges::remove(Iter(input.data()), Sent(Iter(input.data() + input.size())), d.val);
assert(base(ret.begin()) == input.data() + M);
assert(base(ret.end()) == input.data() + N);
assert(std::ranges::equal(input.begin(), base(ret.begin()), d.expected.begin(), d.expected.end()));
}
{ // range overload
auto input = d.input;
auto range = std::ranges::subrange(Iter(input.data()), Sent(Iter(input.data() + input.size())));
std::same_as<std::ranges::subrange<Iter>> decltype(auto) ret = std::ranges::remove(range, d.val);
assert(base(ret.begin()) == input.data() + M);
assert(base(ret.end()) == input.data() + N);
assert(std::ranges::equal(base(input.begin()), base(ret.begin()), d.expected.begin(), d.expected.end()));
}
}
template <class Iter, class Sent>
constexpr void tests() {
// simple test
test<Iter, Sent, 6, 5>({.input = {1, 2, 3, 4, 5, 6}, .expected = {1, 2, 3, 4, 6}, .val = 5});
// empty range
test<Iter, Sent, 0, 0>({});
// single element range - match
test<Iter, Sent, 1, 0>({.input = {1}, .expected = {}, .val = 1});
// single element range - no match
test<Iter, Sent, 1, 1>({.input = {1}, .expected = {1}, .val = 2});
// two element range - same order
test<Iter, Sent, 2, 1>({.input = {1, 2}, .expected = {1}, .val = 2});
// two element range - reversed order
test<Iter, Sent, 2, 1>({.input = {1, 2}, .expected = {2}, .val = 1});
// all elements match
test<Iter, Sent, 5, 0>({.input = {1, 1, 1, 1, 1}, .expected = {}, .val = 1});
// the relative order of elements isn't changed
test<Iter, Sent, 8, 5>({.input = {1, 2, 3, 2, 3, 4, 2, 5}, .expected = {1, 3, 3, 4, 5}, .val = 2});
}
template <class Iter>
constexpr void test_sentinels() {
tests<Iter, Iter>();
tests<Iter, sentinel_wrapper<Iter>>();
tests<Iter, sized_sentinel<Iter>>();
}
constexpr void test_iterators() {
test_sentinels<forward_iterator<int*>>();
test_sentinels<bidirectional_iterator<int*>>();
test_sentinels<random_access_iterator<int*>>();
test_sentinels<contiguous_iterator<int*>>();
test_sentinels<int*>();
}
constexpr bool test() {
test_iterators();
{ // check that ranges::dangling is returned
[[maybe_unused]] std::same_as<std::ranges::dangling> decltype(auto) ret =
std::ranges::remove(std::array{1, 2, 3, 4}, 1);
}
{ // check complexity requirements
struct CompCounter {
int* comp_count;
constexpr bool operator==(const CompCounter&) const {
++*comp_count;
return false;
}
};
{
int proj_count = 0;
auto proj = [&](CompCounter i) {
++proj_count;
return i;
};
int comp_count = 0;
CompCounter a[] = {{&comp_count}, {&comp_count}, {&comp_count}, {&comp_count}};
auto ret = std::ranges::remove(std::begin(a), std::end(a), CompCounter{&comp_count}, proj);
assert(ret.begin() == std::end(a) && ret.end() == std::end(a));
assert(comp_count == 4);
assert(proj_count == 4);
}
{
int proj_count = 0;
auto proj = [&](CompCounter i) {
++proj_count;
return i;
};
int comp_count = 0;
CompCounter a[] = {{&comp_count}, {&comp_count}, {&comp_count}, {&comp_count}};
auto ret = std::ranges::remove(a, CompCounter{&comp_count}, proj);
assert(ret.begin() == std::end(a) && ret.end() == std::end(a));
assert(comp_count == 4);
assert(proj_count == 4);
}
}
{ // check that std::invoke is used
struct S {
constexpr S& identity() { return *this; }
bool operator==(const S&) const = default;
};
{
S a[4] = {};
auto ret = std::ranges::remove(std::begin(a), std::end(a), S{}, &S::identity);
assert(ret.begin() == std::begin(a));
assert(ret.end() == std::end(a));
}
{
S a[4] = {};
auto ret = std::ranges::remove(a, S{}, &S::identity);
assert(ret.begin() == std::begin(a));
assert(ret.end() == std::end(a));
}
}
{
// check that the implicit conversion to bool works
{
StrictComparable<int> a[] = {1, 2, 3, 4};
auto ret = std::ranges::remove(a, a + 4, StrictComparable<int>{2});
assert(ret.begin() == a + 3);
}
{
StrictComparable<int> a[] = {1, 2, 3, 4};
auto ret = std::ranges::remove(a, StrictComparable<int>{2});
assert(ret.begin() == a + 3);
}
}
return true;
}
int main(int, char**) {
test();
static_assert(test());
return 0;
}
@@ -0,0 +1,224 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <algorithm>
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: libcpp-has-no-incomplete-ranges
// template<permutable I, sentinel_for<I> S, class Proj = identity,
// indirect_unary_predicate<projected<I, Proj>> Pred>
// constexpr subrange<I> ranges::remove_if(I first, S last, Pred pred, Proj proj = {});
// template<forward_range R, class Proj = identity,
// indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
// requires permutable<iterator_t<R>>
// constexpr borrowed_subrange_t<R>
// ranges::remove_if(R&& r, Pred pred, Proj proj = {});
#include <algorithm>
#include <array>
#include <cassert>
#include <ranges>
#include "almost_satisfies_types.h"
#include "boolean_testable.h"
#include "test_iterators.h"
struct FalsePredicate {
bool operator()(int) { return false; }
};
template <class Iter, class Sent = sentinel_wrapper<Iter>>
concept HasRemoveIfIt = requires(Iter first, Sent last) { std::ranges::remove_if(first, last, FalsePredicate{}); };
static_assert(HasRemoveIfIt<int*>);
static_assert(!HasRemoveIfIt<PermutableNotForwardIterator>);
static_assert(!HasRemoveIfIt<PermutableNotSwappable>);
static_assert(!HasRemoveIfIt<int*, SentinelForNotSemiregular>);
static_assert(!HasRemoveIfIt<int*, SentinelForNotWeaklyEqualityComparableWith>);
static_assert(!HasRemoveIfIt<int**>); // not indirect_unary_predicate
template <class Range>
concept HasRemoveIfR = requires(Range range) { std::ranges::remove_if(range, FalsePredicate{}); };
static_assert(HasRemoveIfR<UncheckedRange<int*>>);
static_assert(!HasRemoveIfR<PermutableRangeNotForwardIterator>);
static_assert(!HasRemoveIfR<PermutableRangeNotSwappable>);
static_assert(!HasRemoveIfR<SentinelForNotSemiregular>);
static_assert(!HasRemoveIfR<SentinelForNotWeaklyEqualityComparableWith>);
static_assert(!HasRemoveIfR<UncheckedRange<int**>>); // not indirect_unary_predicate
template <int N, int M>
struct Data {
std::array<int, N> input;
std::array<int, M> expected;
int cutoff;
};
template <class Iter, class Sent, int N, int M>
constexpr void test(Data<N, M> d) {
{ // iterator overload
auto input = d.input;
auto first = Iter(input.data());
auto last = Sent(Iter(input.data() + input.size()));
std::same_as<std::ranges::subrange<Iter>> decltype(auto) ret =
std::ranges::remove_if(std::move(first), std::move(last), [&](int i) { return i < d.cutoff; });
assert(base(ret.begin()) == input.data() + M);
assert(base(ret.end()) == input.data() + N);
assert(std::ranges::equal(input.data(), base(ret.begin()), d.expected.begin(), d.expected.end()));
}
{ // range overload
auto input = d.input;
auto range = std::ranges::subrange(Iter(input.data()), Sent(Iter(input.data() + input.size())));
std::same_as<std::ranges::subrange<Iter>> decltype(auto) ret = std::ranges::remove_if(range, [&](int i) {
return i < d.cutoff;
});
assert(base(ret.begin()) == input.data() + M);
assert(base(ret.end()) == input.data() + N);
assert(std::ranges::equal(base(input.begin()), base(ret.begin()), d.expected.begin(), d.expected.end()));
}
}
template <class Iter, class Sent>
constexpr void tests() {
// simple test
test<Iter, Sent, 6, 2>({.input = {1, 2, 3, 4, 5, 6}, .expected = {5, 6}, .cutoff = 5});
// empty range
test<Iter, Sent, 0, 0>({});
// single element range - no match
test<Iter, Sent, 1, 1>({.input = {1}, .expected = {1}, .cutoff = 1});
// single element range - match
test<Iter, Sent, 1, 0>({.input = {1}, .expected = {}, .cutoff = 2});
// two element range
test<Iter, Sent, 2, 1>({.input = {1, 2}, .expected = {2}, .cutoff = 2});
// all elements match
test<Iter, Sent, 5, 0>({.input = {1, 1, 1, 1, 1}, .expected = {}, .cutoff = 2});
// no elements match
test<Iter, Sent, 5, 5>({.input = {1, 1, 1, 1, 1}, .expected = {1, 1, 1, 1, 1}, .cutoff = 0});
// the relative order of elements isn't changed
test<Iter, Sent, 8, 7>({.input = {1, 2, 3, 2, 3, 4, 2, 5}, .expected = {2, 3, 2, 3, 4, 2, 5}, .cutoff = 2});
// multiple matches in a row
test<Iter, Sent, 5, 3>({.input = {1, 2, 2, 2, 1}, .expected = {2, 2, 2}, .cutoff = 2});
// only the last element matches
test<Iter, Sent, 3, 2>({.input = {2, 2, 1}, .expected = {2, 2}, .cutoff = 2});
// only the last element doesn't match
test<Iter, Sent, 3, 1>({.input = {1, 1, 2}, .expected = {2}, .cutoff = 2});
}
template <class Iter>
constexpr void test_sentinels() {
tests<Iter, Iter>();
tests<Iter, sentinel_wrapper<Iter>>();
tests<Iter, sized_sentinel<Iter>>();
}
constexpr void test_iterators() {
test_sentinels<forward_iterator<int*>>();
test_sentinels<bidirectional_iterator<int*>>();
test_sentinels<random_access_iterator<int*>>();
test_sentinels<contiguous_iterator<int*>>();
test_sentinels<int*>();
}
constexpr bool test() {
test_iterators();
{ // check that ranges::dangling is returned
[[maybe_unused]] std::same_as<std::ranges::dangling> decltype(auto) ret =
std::ranges::remove_if(std::array{1, 2, 3, 4}, [](int i) { return i < 0; });
}
{// check complexity requirements
// This is https://llvm.org/PR56382 - clang-format behaves weird if function-local structs are used
// clang-format off
{
int comp_count = 0;
auto comp = [&](int i) {
++comp_count;
return i == 0;
};
int proj_count = 0;
auto proj = [&](int i) {
++proj_count;
return i;
};
int a[] = {1, 2, 3, 4};
auto ret = std::ranges::remove_if(std::begin(a), std::end(a), comp, proj);
assert(ret.begin() == std::end(a) && ret.end() == std::end(a));
assert(comp_count == 4);
assert(proj_count == 4);
}
{
int comp_count = 0;
auto comp = [&](int i) {
++comp_count;
return i == 0;
};
int proj_count = 0;
auto proj = [&](int i) {
++proj_count;
return i;
};
int a[] = {1, 2, 3, 4};
auto ret = std::ranges::remove_if(a, comp, proj);
assert(ret.begin() == std::end(a) && ret.end() == std::end(a));
assert(comp_count == 4);
assert(proj_count == 4);
}
}
{ // check that std::invoke is used
struct S {
constexpr S& identity() { return *this; }
constexpr bool predicate() const { return true; }
};
{
S a[4] = {};
auto ret = std::ranges::remove_if(std::begin(a), std::end(a), &S::predicate, &S::identity);
assert(ret.begin() == std::begin(a));
assert(ret.end() == std::end(a));
}
{
S a[4] = {};
auto ret = std::ranges::remove_if(a, &S::predicate, &S::identity);
assert(ret.begin() == std::begin(a));
assert(ret.end() == std::end(a));
}
}
{
// check that the implicit conversion to bool works
{
int a[] = {1, 2, 3, 4};
auto ret = std::ranges::remove_if(a, a + 4, [](const int& i) { return BooleanTestable{i == 3}; });
assert(ret.begin() == a + 3);
}
{
int a[] = {1, 2, 3, 4};
auto ret = std::ranges::remove_if(a, [](const int& b) { return BooleanTestable{b == 3}; });
assert(ret.begin() == a + 3);
}
}
return true;
}
// clang-format on
int main(int, char**) {
test();
static_assert(test());
return 0;
}
@@ -0,0 +1,259 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: libcpp-has-no-incomplete-ranges
// <algorithm>
// template<input_iterator I, sentinel_for<I> S, weakly_incrementable O, class T,
// class Proj = identity>
// requires indirectly_copyable<I, O> &&
// indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
// constexpr remove_copy_result<I, O>
// remove_copy(I first, S last, O result, const T& value, Proj proj = {}); // Since C++20
//
// template<input_range R, weakly_incrementable O, class T, class Proj = identity>
// requires indirectly_copyable<iterator_t<R>, O> &&
// indirect_binary_predicate<ranges::equal_to,
// projected<iterator_t<R>, Proj>, const T*>
// constexpr remove_copy_result<borrowed_iterator_t<R>, O>
// remove_copy(R&& r, O result, const T& value, Proj proj = {}); // Since C++20
#include <algorithm>
#include <array>
#include <concepts>
#include <functional>
#include <ranges>
#include <utility>
#include "almost_satisfies_types.h"
#include "counting_projection.h"
#include "test_iterators.h"
struct ToPtr {
int* operator()(int) const;
};
template <class Iter = int*, class Sent = int*, class OutIter = int*, class Proj = std::identity>
concept HasRemoveCopyIter =
requires(Iter&& iter, Sent&& sent, OutIter&& out, Proj&& proj) {
std::ranges::remove_copy(
std::forward<Iter>(iter), std::forward<Sent>(sent), std::forward<OutIter>(out), 0, std::forward<Proj>(proj));
};
static_assert(HasRemoveCopyIter<int*>);
// !input_iterator<I>
static_assert(!HasRemoveCopyIter<InputIteratorNotDerivedFrom>);
static_assert(!HasRemoveCopyIter<cpp20_output_iterator<int*>>);
// !sentinel_for<S, I>
static_assert(!HasRemoveCopyIter<int*, SentinelForNotWeaklyEqualityComparableWith>);
static_assert(!HasRemoveCopyIter<int*, SentinelForNotSemiregular>);
// !weakly_incrementable<O>
static_assert(!HasRemoveCopyIter<int*, int*, WeaklyIncrementableNotMovable>);
// !indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
static_assert(!HasRemoveCopyIter<int*, int*, int*, ToPtr>);
// !indirectly_copyable<I, O>
static_assert(!HasRemoveCopyIter<int*, int*, OutputIteratorNotIndirectlyWritable>);
static_assert(!HasRemoveCopyIter<const int*, const int*, const int*>);
template <class Range, class OutIter = int*, class Proj = std::identity>
concept HasRemoveCopyRange =
requires(Range&& range, OutIter&& out, Proj&& proj) {
std::ranges::remove_copy(
std::forward<Range>(range), std::forward<OutIter>(out), 0, std::forward<Proj>(proj));
};
template <class T>
using R = UncheckedRange<T>;
static_assert(HasRemoveCopyRange<R<int*>>);
// !input_range<R>
static_assert(!HasRemoveCopyRange<InputRangeNotDerivedFrom>);
static_assert(!HasRemoveCopyRange<InputRangeNotIndirectlyReadable>);
static_assert(!HasRemoveCopyRange<InputRangeNotInputOrOutputIterator>);
static_assert(!HasRemoveCopyRange<InputRangeNotSentinelSemiregular>);
static_assert(!HasRemoveCopyRange<InputRangeNotSentinelEqualityComparableWith>);
// !weakly_incrementable<O>
static_assert(!HasRemoveCopyRange<R<int*>, WeaklyIncrementableNotMovable>);
// !indirect_binary_predicate<ranges::equal_to, projected<iterator_t<I>, Proj>, const T*>
static_assert(!HasRemoveCopyRange<R<int*>, int*, ToPtr>);
// !indirectly_copyable<I, O>
static_assert(!HasRemoveCopyRange<R<int*>, int*, OutputIteratorNotIndirectlyWritable>);
static_assert(!HasRemoveCopyRange<const int*, const int*, const int*>);
template <int N, int M>
struct Data {
std::array<int, N> input;
std::array<int, M> expected;
int val;
};
template <class InIter, class Sent, class OutIter, int N, int M>
constexpr void test(Data<N, M> d) {
using Result = std::ranges::remove_copy_result<InIter, OutIter>;
{ // iterator overload
std::array<int, M> output;
std::same_as<Result> decltype(auto) ret = std::ranges::remove_copy(
InIter(d.input.data()), Sent(InIter(d.input.data() + d.input.size())), OutIter(output.data()), d.val);
assert(base(ret.in) == d.input.data() + N);
assert(base(ret.out) == output.data() + M);
assert(d.expected == output);
}
{ // range overload
std::array<int, M> output;
auto range = std::ranges::subrange(InIter(d.input.data()), Sent(InIter(d.input.data() + d.input.size())));
std::same_as<Result> decltype(auto) ret =
std::ranges::remove_copy(range, OutIter(output.data()), d.val);
assert(base(ret.in) == d.input.data() + N);
assert(base(ret.out) == output.data() + M);
assert(d.expected == output);
}
}
template <class Iter, class Sent, class OutIter>
constexpr void tests() {
// simple test
test<Iter, Sent, OutIter, 6, 5>({.input = {1, 2, 3, 4, 5, 6}, .expected = {1, 2, 3, 4, 6}, .val = 5});
// empty range
test<Iter, Sent, OutIter, 0, 0>({});
// single element range - match
test<Iter, Sent, OutIter, 1, 0>({.input = {1}, .expected = {}, .val = 1});
// single element range - no match
test<Iter, Sent, OutIter, 1, 1>({.input = {1}, .expected = {1}, .val = 2});
// two element range - same order
test<Iter, Sent, OutIter, 2, 1>({.input = {1, 2}, .expected = {1}, .val = 2});
// two element range - reversed order
test<Iter, Sent, OutIter, 2, 1>({.input = {1, 2}, .expected = {2}, .val = 1});
// all elements match
test<Iter, Sent, OutIter, 5, 0>({.input = {1, 1, 1, 1, 1}, .expected = {}, .val = 1});
// the relative order of elements isn't changed
test<Iter, Sent, OutIter, 8, 5>({.input = {1, 2, 3, 2, 3, 4, 2, 5}, .expected = {1, 3, 3, 4, 5}, .val = 2});
}
template <class InIter, class Sent>
constexpr void test_output_iterators() {
tests<InIter, Sent, cpp17_output_iterator<int*>>();
tests<InIter, Sent, forward_iterator<int*>>();
tests<InIter, Sent, bidirectional_iterator<int*>>();
tests<InIter, Sent, random_access_iterator<int*>>();
tests<InIter, Sent, contiguous_iterator<int*>>();
tests<InIter, Sent, int*>();
}
template <class Iter>
constexpr void test_sentinels() {
test_output_iterators<Iter, Iter>();
test_output_iterators<Iter, sentinel_wrapper<Iter>>();
test_output_iterators<Iter, sized_sentinel<Iter>>();
}
constexpr bool test() {
test_output_iterators<cpp17_input_iterator<int*>, sentinel_wrapper<cpp17_input_iterator<int*>>>();
test_output_iterators<cpp17_input_iterator<int*>, sized_sentinel<cpp17_input_iterator<int*>>>();
test_output_iterators<cpp20_input_iterator<int*>, sentinel_wrapper<cpp20_input_iterator<int*>>>();
test_output_iterators<cpp20_input_iterator<int*>, sized_sentinel<cpp20_input_iterator<int*>>>();
test_sentinels<forward_iterator<int*>>();
test_sentinels<bidirectional_iterator<int*>>();
test_sentinels<random_access_iterator<int*>>();
test_sentinels<contiguous_iterator<int*>>();
test_sentinels<int*>();
{ // check that passing a different type works
struct S {
constexpr operator int() const { return 3; }
};
{ // iterator overload
int a[] = {1, 2, 3, 4};
int b[3];
std::ranges::remove_copy(std::begin(a), std::end(a), std::begin(b), S{});
}
{ // range overload
int a[] = {1, 2, 3, 4};
int b[3];
std::ranges::remove_copy(a, std::begin(b), S{});
}
}
{ // check that a custom projection works
struct S {
constexpr operator int() const { return 3; }
};
{ // iterator overload
int a[] = {1, 2, 3, 4};
int b[3];
std::ranges::remove_copy(std::begin(a), std::end(a), std::begin(b), S{});
}
{ // range overload
int a[] = {1, 2, 3, 4};
int b[3];
std::ranges::remove_copy(a, std::begin(b), S{});
}
}
// Complexity: Exactly last - first applications of the corresponding predicate and any projection.
{
std::array in{4, 4, 5, 6};
std::array expected{5, 6};
// iterator overload
{
int numberOfProj = 0;
std::array<int, 2> out;
std::ranges::remove_copy(
in.begin(),
in.end(),
out.begin(),
4,
counting_projection(numberOfProj));
assert(numberOfProj == static_cast<int>(in.size()));
assert(std::ranges::equal(out, expected));
}
// range overload
{
int numberOfProj = 0;
std::array<int, 2> out;
std::ranges::remove_copy(
in, out.begin(), 4, counting_projection(numberOfProj));
assert(numberOfProj == static_cast<int>(in.size()));
assert(std::ranges::equal(out, expected));
}
}
return true;
}
int main(int, char**) {
test();
static_assert(test());
return 0;
}
@@ -0,0 +1,298 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: libcpp-has-no-incomplete-ranges
// <algorithm>
// template<input_iterator I, sentinel_for<I> S, weakly_incrementable O,
// class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred>
// requires indirectly_copyable<I, O>
// constexpr remove_copy_if_result<I, O>
// remove_copy_if(I first, S last, O result, Pred pred, Proj proj = {}); // Since C++20
//
// template<input_range R, weakly_incrementable O, class Proj = identity,
// indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
// requires indirectly_copyable<iterator_t<R>, O>
// constexpr remove_copy_if_result<borrowed_iterator_t<R>, O>
// remove_copy_if(R&& r, O result, Pred pred, Proj proj = {}); // Since C++20
#include <algorithm>
#include <array>
#include <concepts>
#include <functional>
#include <ranges>
#include <type_traits>
#include <utility>
#include "almost_satisfies_types.h"
#include "counting_predicates.h"
#include "counting_projection.h"
#include "test_iterators.h"
struct AlwaysTrue {
constexpr bool operator()(auto&&...) const { return true; }
};
template <
class I,
class S = sentinel_wrapper<std::decay_t<I>>,
class O = int*,
class Pred = AlwaysTrue>
concept HasRemoveCopyIfIter =
requires(I&& iter, S&& sent, O&& out, Pred&& pred) {
std::ranges::remove_copy_if(std::forward<I>(iter), std::forward<S>(sent),
std::forward<O>(out), std::forward<Pred>(pred));
};
static_assert(HasRemoveCopyIfIter<int*, int*, int*>);
// !input_iterator<I>
static_assert(!HasRemoveCopyIfIter<InputIteratorNotDerivedFrom>);
static_assert(!HasRemoveCopyIfIter<cpp20_output_iterator<int*>>);
// !sentinel_for<S, I>
static_assert(!HasRemoveCopyIfIter<int*, SentinelForNotWeaklyEqualityComparableWith>);
static_assert(!HasRemoveCopyIfIter<int*, SentinelForNotSemiregular>);
// !weakly_incrementable<O>
static_assert(!HasRemoveCopyIfIter<int*, int*, WeaklyIncrementableNotMovable>);
// !indirect_unary_predicate<Pred, projected<I, Proj>>
static_assert(!HasRemoveCopyIfIter<int*, int*, int*, IndirectUnaryPredicateNotPredicate>);
static_assert(!HasRemoveCopyIfIter<int*, int*, int*, IndirectUnaryPredicateNotCopyConstructible>);
// !indirectly_copyable<I, O>
static_assert(!HasRemoveCopyIfIter<int*, int*, OutputIteratorNotIndirectlyWritable>);
static_assert(!HasRemoveCopyIfIter<const int*, const int*, const int*>);
template < class R, class O = int*, class Pred = AlwaysTrue, class Proj = std::identity>
concept HasRemoveCopyIfRange =
requires(R&& r, O&& out, Pred&& pred, Proj&& proj) {
std::ranges::remove_copy_if(
std::forward<R>(r), std::forward<O>(out), std::forward<Pred>(pred), std::forward<Proj>(proj));
};
template <class T>
using R = UncheckedRange<T>;
static_assert(HasRemoveCopyIfRange<R<int*>>);
// !input_range<R>
static_assert(!HasRemoveCopyIfRange<R<InputIteratorNotDerivedFrom>>);
static_assert(!HasRemoveCopyIfRange<R<cpp20_output_iterator<int*>>>);
// !weakly_incrementable<O>
static_assert(!HasRemoveCopyIfRange<R<int*>, WeaklyIncrementableNotMovable>);
// !indirect_unary_predicate<Pred, projected<iterator_t<R>, Proj>>
static_assert(!HasRemoveCopyIfRange<R<int*>, int*, IndirectUnaryPredicateNotPredicate>);
static_assert(!HasRemoveCopyIfRange<R<int*>, int*, IndirectUnaryPredicateNotCopyConstructible>);
// !indirectly_copyable<iterator_t<R>, O>
static_assert(!HasRemoveCopyIfRange<R<int*>, OutputIteratorNotIndirectlyWritable>);
static_assert(!HasRemoveCopyIfRange<R<const int*>, const int*>);
template <class InIter, class OutIter, template <class> class SentWrapper, std::size_t N1, std::size_t N2, class Pred>
constexpr void testRemoveCopyIfImpl(std::array<int, N1> in, std::array<int, N2> expected, Pred pred) {
using Sent = SentWrapper<InIter>;
using Result = std::ranges::remove_copy_if_result<InIter, OutIter>;
// iterator overload
{
std::array<int, N2> out;
std::same_as<Result> decltype(auto) result =
std::ranges::remove_copy_if(InIter{in.data()}, Sent{InIter{in.data() + in.size()}}, OutIter{out.data()}, pred);
assert(std::ranges::equal(out, expected));
assert(base(result.in) == in.data() + in.size());
assert(base(result.out) == out.data() + out.size());
}
// range overload
{
std::array<int, N2> out;
std::ranges::subrange r{InIter{in.data()}, Sent{InIter{in.data() + in.size()}}};
std::same_as<Result> decltype(auto) result =
std::ranges::remove_copy_if(r, OutIter{out.data()}, pred);
assert(std::ranges::equal(out, expected));
assert(base(result.in) == in.data() + in.size());
assert(base(result.out) == out.data() + out.size());
}
}
template <class InIter, class OutIter, template <class> class SentWrapper>
constexpr void testImpl() {
// remove multiple elements
{
std::array in{1, 2, 3, 2, 1};
std::array expected{1, 3, 1};
auto pred = [](int i) { return i == 2; };
testRemoveCopyIfImpl<InIter, OutIter, SentWrapper>(in, expected, pred);
}
// remove single elements
{
std::array in{1, 2, 3, 2, 1};
std::array expected{1, 2, 2, 1};
auto pred = [](int i) { return i == 3; };
testRemoveCopyIfImpl<InIter, OutIter, SentWrapper>(in, expected, pred);
}
// nothing removed
{
std::array in{1, 2, 3, 2, 1};
std::array expected{1, 2, 3, 2, 1};
auto pred = [](int) { return false; };
testRemoveCopyIfImpl<InIter, OutIter, SentWrapper>(in, expected, pred);
}
// all removed
{
std::array in{1, 2, 3, 2, 1};
std::array<int, 0> expected{};
auto pred = [](int) { return true; };
testRemoveCopyIfImpl<InIter, OutIter, SentWrapper>(in, expected, pred);
}
// remove first
{
std::array in{1, 2, 3, 2};
std::array expected{2, 3, 2};
auto pred = [](int i) { return i < 2; };
testRemoveCopyIfImpl<InIter, OutIter, SentWrapper>(in, expected, pred);
}
// remove last
{
std::array in{1, 2, 3, 2, 5};
std::array expected{1, 2, 3, 2};
auto pred = [](int i) { return i > 3; };
testRemoveCopyIfImpl<InIter, OutIter, SentWrapper>(in, expected, pred);
}
// stable
{
std::array in{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
std::array expected{6, 7, 8, 9, 10};
auto pred = [](int i) { return i < 6; };
testRemoveCopyIfImpl<InIter, OutIter, SentWrapper>(in, expected, pred);
}
// empty range
{
std::array<int, 0> in{};
std::array<int, 0> expected{};
auto pred = [](int) { return false; };
testRemoveCopyIfImpl<InIter, OutIter, SentWrapper>(in, expected, pred);
}
// one element range
{
std::array in{1};
std::array<int, 0> expected{};
auto pred = [](int i) { return i == 1; };
testRemoveCopyIfImpl<InIter, OutIter, SentWrapper>(in, expected, pred);
}
}
template <class OutIter, template <class> class SentWrapper>
constexpr void withAllPermutationsOfInIter() {
testImpl<cpp20_input_iterator<int*>, OutIter, sentinel_wrapper>();
testImpl<forward_iterator<int*>, OutIter, SentWrapper>();
testImpl<bidirectional_iterator<int*>, OutIter, SentWrapper>();
testImpl<random_access_iterator<int*>, OutIter, SentWrapper>();
testImpl<contiguous_iterator<int*>, OutIter, SentWrapper>();
testImpl<int*, OutIter, SentWrapper>();
}
template <template <class> class SentWrapper>
constexpr void withAllPermutationsOfInIterOutIter() {
withAllPermutationsOfInIter<cpp20_output_iterator<int*>, SentWrapper>();
withAllPermutationsOfInIter<int*, SentWrapper>();
}
constexpr bool test() {
withAllPermutationsOfInIterOutIter<std::type_identity_t>();
withAllPermutationsOfInIterOutIter<sentinel_wrapper>();
// Test custom projection
{
struct Data {
int data;
};
std::array in{Data{4}, Data{8}, Data{12}, Data{12}};
std::array expected{Data{4}, Data{12}, Data{12}};
const auto proj = &Data::data;
const auto pred = [](int i) { return i == 8; };
const auto equals = [](const Data& x, const Data& y) { return x.data == y.data; };
// iterator overload
{
std::array<Data, 3> out;
auto result = std::ranges::remove_copy_if(in.begin(), in.end(), out.begin(), pred, proj);
assert(std::ranges::equal(out, expected, equals));
assert(result.in == in.end());
assert(result.out == out.end());
}
// range overload
{
std::array<Data, 3> out;
auto result = std::ranges::remove_copy_if(in, out.begin(), pred, proj);
assert(std::ranges::equal(out, expected, equals));
assert(result.in == in.end());
assert(result.out == out.end());
}
}
// Complexity: Exactly last - first applications of the corresponding predicate and any projection.
{
std::array in{4, 4, 5, 6};
std::array expected{5, 6};
const auto pred = [](int i) { return i == 4; };
// iterator overload
{
int numberOfPred = 0;
int numberOfProj = 0;
std::array<int, 2> out;
std::ranges::remove_copy_if(
in.begin(), in.end(), out.begin(), counting_predicate(pred, numberOfPred), counting_projection(numberOfProj));
assert(numberOfPred == static_cast<int>(in.size()));
assert(numberOfProj == static_cast<int>(in.size()));
assert(std::ranges::equal(out, expected));
}
// range overload
{
int numberOfPred = 0;
int numberOfProj = 0;
std::array<int, 2> out;
std::ranges::remove_copy_if(
in, out.begin(), counting_predicate(pred, numberOfPred), counting_projection(numberOfProj));
assert(numberOfPred == static_cast<int>(in.size()));
assert(numberOfProj == static_cast<int>(in.size()));
assert(std::ranges::equal(out, expected));
}
}
return true;
}
int main(int, char**) {
test();
static_assert(test());
return 0;
}
@@ -0,0 +1,95 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <algorithm>
// template<ForwardIterator Iter, class T>
// requires OutputIterator<Iter, RvalueOf<Iter::reference>::type>
// && HasEqualTo<Iter::value_type, T>
// constexpr Iter // constexpr after C++17
// remove(Iter first, Iter last, const T& value);
#include <algorithm>
#include <cassert>
#include <memory>
#include "test_macros.h"
#include "test_iterators.h"
#if TEST_STD_VER > 17
TEST_CONSTEXPR bool test_constexpr() {
int ia[] = {1, 3, 5, 2, 5, 6};
auto it = std::remove(std::begin(ia), std::end(ia), 5);
return (std::begin(ia) + std::size(ia) - 2) == it // we removed two elements
&& std::none_of(std::begin(ia), it, [](int a) {return a == 5; })
;
}
#endif
template <class Iter>
void
test()
{
int ia[] = {0, 1, 2, 3, 4, 2, 3, 4, 2};
const unsigned sa = sizeof(ia)/sizeof(ia[0]);
Iter r = std::remove(Iter(ia), Iter(ia+sa), 2);
assert(base(r) == ia + sa-3);
assert(ia[0] == 0);
assert(ia[1] == 1);
assert(ia[2] == 3);
assert(ia[3] == 4);
assert(ia[4] == 3);
assert(ia[5] == 4);
}
#if TEST_STD_VER >= 11
template <class Iter>
void
test1()
{
const unsigned sa = 9;
std::unique_ptr<int> ia[sa];
ia[0].reset(new int(0));
ia[1].reset(new int(1));
ia[3].reset(new int(3));
ia[4].reset(new int(4));
ia[6].reset(new int(3));
ia[7].reset(new int(4));
Iter r = std::remove(Iter(ia), Iter(ia+sa), std::unique_ptr<int>());
assert(base(r) == ia + sa-3);
assert(*ia[0] == 0);
assert(*ia[1] == 1);
assert(*ia[2] == 3);
assert(*ia[3] == 4);
assert(*ia[4] == 3);
assert(*ia[5] == 4);
}
#endif // TEST_STD_VER >= 11
int main(int, char**)
{
test<forward_iterator<int*> >();
test<bidirectional_iterator<int*> >();
test<random_access_iterator<int*> >();
test<int*>();
#if TEST_STD_VER >= 11
test1<forward_iterator<std::unique_ptr<int>*> >();
test1<bidirectional_iterator<std::unique_ptr<int>*> >();
test1<random_access_iterator<std::unique_ptr<int>*> >();
test1<std::unique_ptr<int>*>();
#endif // TEST_STD_VER >= 11
#if TEST_STD_VER > 17
static_assert(test_constexpr());
#endif
return 0;
}
@@ -0,0 +1,90 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <algorithm>
// template<InputIterator InIter, OutputIterator<auto, InIter::reference> OutIter, class T>
// requires HasEqualTo<InIter::value_type, T>
// constexpr OutIter // constexpr after C++17
// remove_copy(InIter first, InIter last, OutIter result, const T& value);
#include <algorithm>
#include <cassert>
#include "test_macros.h"
#include "test_iterators.h"
#if TEST_STD_VER > 17
TEST_CONSTEXPR bool test_constexpr() {
int ia[] = {1, 3, 5, 2, 5, 6};
int ib[std::size(ia)] = {0};
auto it = std::remove_copy(std::begin(ia), std::end(ia), std::begin(ib), 5);
return std::distance(std::begin(ib), it) == static_cast<int>(std::size(ia) - 2) // we removed two elements
&& std::none_of(std::begin(ib), it, [](int a) {return a == 5;})
&& std::all_of (it, std::end(ib), [](int a) {return a == 0;})
;
}
#endif
template <class InIter, class OutIter>
void
test()
{
int ia[] = {0, 1, 2, 3, 4, 2, 3, 4, 2};
const unsigned sa = sizeof(ia)/sizeof(ia[0]);
int ib[sa];
OutIter r = std::remove_copy(InIter(ia), InIter(ia+sa), OutIter(ib), 2);
assert(base(r) == ib + sa-3);
assert(ib[0] == 0);
assert(ib[1] == 1);
assert(ib[2] == 3);
assert(ib[3] == 4);
assert(ib[4] == 3);
assert(ib[5] == 4);
}
int main(int, char**)
{
test<cpp17_input_iterator<const int*>, cpp17_output_iterator<int*> >();
test<cpp17_input_iterator<const int*>, forward_iterator<int*> >();
test<cpp17_input_iterator<const int*>, bidirectional_iterator<int*> >();
test<cpp17_input_iterator<const int*>, random_access_iterator<int*> >();
test<cpp17_input_iterator<const int*>, int*>();
test<forward_iterator<const int*>, cpp17_output_iterator<int*> >();
test<forward_iterator<const int*>, forward_iterator<int*> >();
test<forward_iterator<const int*>, bidirectional_iterator<int*> >();
test<forward_iterator<const int*>, random_access_iterator<int*> >();
test<forward_iterator<const int*>, int*>();
test<bidirectional_iterator<const int*>, cpp17_output_iterator<int*> >();
test<bidirectional_iterator<const int*>, forward_iterator<int*> >();
test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
test<bidirectional_iterator<const int*>, random_access_iterator<int*> >();
test<bidirectional_iterator<const int*>, int*>();
test<random_access_iterator<const int*>, cpp17_output_iterator<int*> >();
test<random_access_iterator<const int*>, forward_iterator<int*> >();
test<random_access_iterator<const int*>, bidirectional_iterator<int*> >();
test<random_access_iterator<const int*>, random_access_iterator<int*> >();
test<random_access_iterator<const int*>, int*>();
test<const int*, cpp17_output_iterator<int*> >();
test<const int*, forward_iterator<int*> >();
test<const int*, bidirectional_iterator<int*> >();
test<const int*, random_access_iterator<int*> >();
test<const int*, int*>();
#if TEST_STD_VER > 17
static_assert(test_constexpr());
#endif
return 0;
}
@@ -0,0 +1,95 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <algorithm>
// template<InputIterator InIter, OutputIterator<auto, InIter::reference> OutIter,
// Predicate<auto, InIter::value_type> Pred>
// requires CopyConstructible<Pred>
// constexpr OutIter // constexpr after C++17
// remove_copy_if(InIter first, InIter last, OutIter result, Pred pred);
#include <algorithm>
#include <functional>
#include <cassert>
#include "test_macros.h"
#include "test_iterators.h"
TEST_CONSTEXPR bool equalToTwo(int v) { return v == 2; }
#if TEST_STD_VER > 17
TEST_CONSTEXPR bool test_constexpr() {
int ia[] = {1, 3, 5, 2, 5, 6};
int ib[std::size(ia)] = {0};
auto it = std::remove_copy_if(std::begin(ia), std::end(ia), std::begin(ib), equalToTwo);
return std::distance(std::begin(ib), it) == static_cast<int>(std::size(ia) - 1) // we removed one element
&& std::none_of(std::begin(ib), it, equalToTwo)
&& std::all_of (it, std::end(ib), [](int a) {return a == 0;})
;
}
#endif
template <class InIter, class OutIter>
void
test()
{
int ia[] = {0, 1, 2, 3, 4, 2, 3, 4, 2};
const unsigned sa = sizeof(ia)/sizeof(ia[0]);
int ib[sa];
OutIter r = std::remove_copy_if(InIter(ia), InIter(ia+sa),
OutIter(ib), equalToTwo);
assert(base(r) == ib + sa-3);
assert(ib[0] == 0);
assert(ib[1] == 1);
assert(ib[2] == 3);
assert(ib[3] == 4);
assert(ib[4] == 3);
assert(ib[5] == 4);
}
int main(int, char**)
{
test<cpp17_input_iterator<const int*>, cpp17_output_iterator<int*> >();
test<cpp17_input_iterator<const int*>, forward_iterator<int*> >();
test<cpp17_input_iterator<const int*>, bidirectional_iterator<int*> >();
test<cpp17_input_iterator<const int*>, random_access_iterator<int*> >();
test<cpp17_input_iterator<const int*>, int*>();
test<forward_iterator<const int*>, cpp17_output_iterator<int*> >();
test<forward_iterator<const int*>, forward_iterator<int*> >();
test<forward_iterator<const int*>, bidirectional_iterator<int*> >();
test<forward_iterator<const int*>, random_access_iterator<int*> >();
test<forward_iterator<const int*>, int*>();
test<bidirectional_iterator<const int*>, cpp17_output_iterator<int*> >();
test<bidirectional_iterator<const int*>, forward_iterator<int*> >();
test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
test<bidirectional_iterator<const int*>, random_access_iterator<int*> >();
test<bidirectional_iterator<const int*>, int*>();
test<random_access_iterator<const int*>, cpp17_output_iterator<int*> >();
test<random_access_iterator<const int*>, forward_iterator<int*> >();
test<random_access_iterator<const int*>, bidirectional_iterator<int*> >();
test<random_access_iterator<const int*>, random_access_iterator<int*> >();
test<random_access_iterator<const int*>, int*>();
test<const int*, cpp17_output_iterator<int*> >();
test<const int*, forward_iterator<int*> >();
test<const int*, bidirectional_iterator<int*> >();
test<const int*, random_access_iterator<int*> >();
test<const int*, int*>();
#if TEST_STD_VER > 17
static_assert(test_constexpr());
#endif
return 0;
}
@@ -0,0 +1,110 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <algorithm>
// template<ForwardIterator Iter, Predicate<auto, Iter::value_type> Pred>
// requires OutputIterator<Iter, RvalueOf<Iter::reference>::type>
// && CopyConstructible<Pred>
// constexpr Iter // constexpr after C++17
// remove_if(Iter first, Iter last, Pred pred);
#include <algorithm>
#include <functional>
#include <cassert>
#include <memory>
#include "test_macros.h"
#include "test_iterators.h"
#include "counting_predicates.h"
TEST_CONSTEXPR bool equal2 ( int i ) { return i == 2; }
#if TEST_STD_VER > 17
TEST_CONSTEXPR bool test_constexpr() {
int ia[] = {1, 3, 5, 2, 5, 6};
auto it = std::remove_if(std::begin(ia), std::end(ia), equal2);
return (std::begin(ia) + std::size(ia) - 1) == it // we removed one element
&& std::none_of(std::begin(ia), it, equal2)
;
}
#endif
template <class Iter>
void
test()
{
int ia[] = {0, 1, 2, 3, 4, 2, 3, 4, 2};
const unsigned sa = sizeof(ia)/sizeof(ia[0]);
// int* r = std::remove_if(ia, ia+sa, std::bind2nd(std::equal_to<int>(), 2));
unary_counting_predicate<bool(*)(int), int> cp(equal2);
int* r = std::remove_if(ia, ia+sa, std::ref(cp));
assert(r == ia + sa-3);
assert(ia[0] == 0);
assert(ia[1] == 1);
assert(ia[2] == 3);
assert(ia[3] == 4);
assert(ia[4] == 3);
assert(ia[5] == 4);
assert(cp.count() == sa);
}
#if TEST_STD_VER >= 11
struct pred
{
bool operator()(const std::unique_ptr<int>& i) {return *i == 2;}
};
template <class Iter>
void
test1()
{
const unsigned sa = 9;
std::unique_ptr<int> ia[sa];
ia[0].reset(new int(0));
ia[1].reset(new int(1));
ia[2].reset(new int(2));
ia[3].reset(new int(3));
ia[4].reset(new int(4));
ia[5].reset(new int(2));
ia[6].reset(new int(3));
ia[7].reset(new int(4));
ia[8].reset(new int(2));
Iter r = std::remove_if(Iter(ia), Iter(ia+sa), pred());
assert(base(r) == ia + sa-3);
assert(*ia[0] == 0);
assert(*ia[1] == 1);
assert(*ia[2] == 3);
assert(*ia[3] == 4);
assert(*ia[4] == 3);
assert(*ia[5] == 4);
}
#endif // TEST_STD_VER >= 11
int main(int, char**)
{
test<forward_iterator<int*> >();
test<bidirectional_iterator<int*> >();
test<random_access_iterator<int*> >();
test<int*>();
#if TEST_STD_VER >= 11
test1<forward_iterator<std::unique_ptr<int>*> >();
test1<bidirectional_iterator<std::unique_ptr<int>*> >();
test1<random_access_iterator<std::unique_ptr<int>*> >();
test1<std::unique_ptr<int>*>();
#endif // TEST_STD_VER >= 11
#if TEST_STD_VER > 17
static_assert(test_constexpr());
#endif
return 0;
}