Unnamed: 0
int64 0
0
| repo_id
stringlengths 5
186
| file_path
stringlengths 15
223
| content
stringlengths 1
32.8M
⌀ |
---|---|---|---|
0 | repos/range-v3/test | repos/range-v3/test/action/join.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <vector>
#include <string>
#include <range/v3/core.hpp>
#include <range/v3/action/join.hpp>
#include <range/v3/algorithm/move.hpp>
#include <range/v3/algorithm/equal.hpp>
#include <range/v3/view/transform.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
int main()
{
using namespace ranges;
std::vector<std::string> v {"hello"," ","world"};
auto s = v | move | actions::join;
static_assert(std::is_same<decltype(s), std::string>::value, "");
CHECK(s == "hello world");
auto s2 = v | views::transform(views::all) | actions::join;
static_assert(std::is_same<decltype(s2), std::vector<char>>::value, "");
CHECK(std::string(s2.begin(), s2.end()) == "hello world");
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/action/push_front.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <list>
#include <vector>
#include <range/v3/core.hpp>
#include <range/v3/view/iota.hpp>
#include <range/v3/view/take.hpp>
#include <range/v3/view/for_each.hpp>
#include <range/v3/action/push_front.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
int main()
{
using namespace ranges;
{
std::vector<int> v;
push_front(v, {1,2,3});
::check_equal(v, {1,2,3});
push_front(v, views::iota(10) | views::take(3));
::check_equal(v, {10,11,12,1,2,3});
push_front(v, views::iota(10) | views::take(3));
::check_equal(v, {10,11,12,10,11,12,1,2,3});
int rg[] = {9,8,7};
push_front(v, rg);
::check_equal(v, {9,8,7,10,11,12,10,11,12,1,2,3});
push_front(v, rg);
::check_equal(v, {9,8,7,9,8,7,10,11,12,10,11,12,1,2,3});
std::list<int> s;
push_front(s,
views::ints|views::take(10)|views::for_each([](int i){return yield_if(i%2==0,i);}));
::check_equal(s, {0,2,4,6,8});
push_front(s, -2);
::check_equal(s, {-2,0,2,4,6,8});
}
{
std::vector<int> v;
v = std::move(v) | push_front({1,2,3});
::check_equal(v, {1,2,3});
v = std::move(v) | push_front(views::iota(10) | views::take(3));
::check_equal(v, {10,11,12,1,2,3});
v = std::move(v) | push_front(views::iota(10) | views::take(3));
::check_equal(v, {10,11,12,10,11,12,1,2,3});
int rg[] = {9,8,7};
v = std::move(v) | push_front(rg);
::check_equal(v, {9,8,7,10,11,12,10,11,12,1,2,3});
v = std::move(v) | push_front(rg);
::check_equal(v, {9,8,7,9,8,7,10,11,12,10,11,12,1,2,3});
std::list<int> s;
s = std::move(s) | push_front(
views::ints|views::take(10)|views::for_each([](int i){return yield_if(i%2==0,i);}));
::check_equal(s, {0,2,4,6,8});
s = std::move(s) | push_front(-2);
::check_equal(s, {-2,0,2,4,6,8});
}
{
std::vector<int> v;
v |= push_front({1,2,3});
::check_equal(v, {1,2,3});
v |= push_front(views::iota(10) | views::take(3));
::check_equal(v, {10,11,12,1,2,3});
v |= push_front(views::iota(10) | views::take(3));
::check_equal(v, {10,11,12,10,11,12,1,2,3});
int rg[] = {9,8,7};
v |= push_front(rg);
::check_equal(v, {9,8,7,10,11,12,10,11,12,1,2,3});
v |= push_front(rg);
::check_equal(v, {9,8,7,9,8,7,10,11,12,10,11,12,1,2,3});
std::list<int> s;
s |= push_front(
views::ints|views::take(10)|views::for_each([](int i){return yield_if(i%2==0,i);}));
::check_equal(s, {0,2,4,6,8});
s |= push_front(-2);
::check_equal(s, {-2,0,2,4,6,8});
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/action/insert.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <set>
#include <vector>
#include <range/v3/core.hpp>
#include <range/v3/view/iota.hpp>
#include <range/v3/view/take.hpp>
#include <range/v3/view/for_each.hpp>
#include <range/v3/view/ref.hpp>
#include <range/v3/action/insert.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
template<typename T>
struct vector_like : std::vector<T> {
using std::vector<T>::vector;
using typename std::vector<T>::size_type;
size_type last_reservation{};
size_type reservation_count{};
void reserve(size_type n) {
std::vector<T>::reserve(n);
last_reservation = n;
++reservation_count;
}
};
int main()
{
using namespace ranges;
{
std::vector<int> v;
auto i = insert(v, v.begin(), 42);
CHECK(i == v.begin());
::check_equal(v, {42});
insert(v, v.end(), {1,2,3});
::check_equal(v, {42,1,2,3});
insert(v, v.begin(), views::ints | views::take(3));
::check_equal(v, {0,1,2,42,1,2,3});
int rg[] = {9,8,7};
insert(v, v.begin()+3, rg);
::check_equal(v, {0,1,2,9,8,7,42,1,2,3});
insert(v, v.begin()+1, rg);
::check_equal(v, {0,9,8,7,1,2,9,8,7,42,1,2,3});
}
{
std::set<int> s;
insert(s,
views::ints|views::take(10)|views::for_each([](int i){return yield_if(i%2==0,i);}));
::check_equal(s, {0,2,4,6,8});
auto j = insert(s, 10);
CHECK(j.first == prev(s.end()));
CHECK(j.second == true);
::check_equal(s, {0,2,4,6,8,10});
insert(views::ref(s), 12);
::check_equal(s, {0,2,4,6,8,10,12});
}
{
const std::size_t N = 1024;
vector_like<int> vl;
insert(vl, vl.end(), views::iota(0, int{N}));
CHECK(vl.reservation_count == 1u);
CHECK(vl.last_reservation == N);
auto r = views::iota(0, int{2 * N});
insert(vl, vl.begin() + 42, begin(r), end(r));
CHECK(vl.reservation_count == 2u);
CHECK(vl.last_reservation == 3 * N);
int i = 42;
insert(vl, vl.end(), &i, &i + 1);
CHECK(vl.reservation_count == 3u);
CHECK(vl.last_reservation > 3 * N + 1);
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/experimental/CMakeLists.txt | set(CMAKE_FOLDER "${CMAKE_FOLDER}/experimental")
add_subdirectory(utility)
add_subdirectory(view)
|
0 | repos/range-v3/test/experimental | repos/range-v3/test/experimental/utility/generator.cpp | // Range v3 library
//
// Copyright Casey Carter 2017
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#include <range/v3/detail/config.hpp>
#include <iostream>
#include <vector>
#include <range/v3/range/access.hpp>
#include <range/v3/range_for.hpp>
#include <range/v3/algorithm/copy.hpp>
#include <range/v3/algorithm/count.hpp>
#include <range/v3/algorithm/equal.hpp>
#include <range/v3/experimental/utility/generator.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/utility/swap.hpp>
#include <range/v3/view/filter.hpp>
#include <range/v3/view/iota.hpp>
#include <range/v3/view/move.hpp>
#include <range/v3/view/take_exactly.hpp>
#include <range/v3/view/transform.hpp>
#include "../../simple_test.hpp"
#include "../../test_utils.hpp"
#ifdef __clang__
#pragma GCC diagnostic ignored "-Wunused-const-variable"
#endif
#if RANGES_CXX_COROUTINES < RANGES_CXX_COROUTINES_TS1
#error This test uses coroutines.
#endif
template<bool Condition>
using maybe_sized_generator = meta::if_c<Condition,
meta::quote<ranges::experimental::sized_generator>,
meta::quote<ranges::experimental::generator>>;
template<typename T>
constexpr bool is_copy_constructible_or_ref() noexcept
{
return std::is_reference<T>::value ||(bool) ranges::copy_constructible<T>;
}
struct coro_fn
{
private:
template<typename V>
using generator_for = meta::invoke<
maybe_sized_generator<(bool) ranges::sized_range<V>>,
ranges::range_reference_t<V>,
ranges::range_value_t<V>>;
CPP_template(typename V)(
requires ranges::input_range<V> && ranges::view_<V> &&
(is_copy_constructible_or_ref<ranges::range_reference_t<V>>()))
static generator_for<V> impl(V v)
{
if(RANGES_CONSTEXPR_IF(ranges::sized_range<V>))
co_await static_cast<ranges::experimental::generator_size>((std::size_t)ranges::distance(v));
auto first = ranges::begin(v);
auto const last = ranges::end(v);
for (; first != last; ++first)
co_yield *first;
}
public:
CPP_template(typename Rng)(
requires (
!meta::is<ranges::uncvref_t<Rng>, ranges::experimental::generator>::value &&
!meta::is<ranges::uncvref_t<Rng>, ranges::experimental::sized_generator>::value &&
ranges::input_range<Rng> &&
is_copy_constructible_or_ref<ranges::range_reference_t<Rng>>()))
generator_for<ranges::views::all_t<Rng>> operator()(Rng &&rng) const
{
return impl(ranges::views::all(static_cast<Rng &&>(rng)));
}
template<typename R, typename V>
ranges::experimental::generator<R, V>
operator()(ranges::experimental::generator<R, V> g) const noexcept
{
return g;
}
template<typename R, typename V>
ranges::experimental::sized_generator<R, V>
operator()(ranges::experimental::sized_generator<R, V> g) const noexcept
{
return g;
}
};
inline namespace function_objects
{
RANGES_INLINE_VARIABLE(coro_fn, coro)
}
auto f(int const n)
{
return ::coro(ranges::views::iota(0, n));
}
ranges::experimental::sized_generator<int> g(int const n)
{
co_await static_cast<ranges::experimental::generator_size>((std::size_t) (n > 0 ? n : 0));
for (int i = 0; i < n; ++i)
co_yield i;
}
ranges::experimental::sized_generator<int &> h(int const n)
{
co_await static_cast<ranges::experimental::generator_size>((std::size_t) (n > 0 ? n : 0));
for (int i = 0; i < n; ++i)
co_yield i;
}
CPP_template(class T)(
requires ranges::weakly_incrementable<T>)
ranges::experimental::generator<T> iota_generator(T t)
{
for (;; ++t)
co_yield t;
}
CPP_template(class T, class S)(
requires (ranges::weakly_incrementable<T> &&
ranges::detail::weakly_equality_comparable_with_<T, S> &&
!ranges::sized_sentinel_for<S, T> && !(ranges::integral<T> && ranges::integral<S>)))
ranges::experimental::generator<T> iota_generator(T t, S const s)
{
for (; t != s; ++t)
co_yield t;
}
CPP_template(class T, class S)(
requires ranges::sized_sentinel_for<S, T> || (ranges::integral<T> && ranges::integral<S>))
ranges::experimental::sized_generator<T> iota_generator(T t, S const s)
{
co_await static_cast<ranges::experimental::generator_size>((std::size_t) (s - t));
for (; t != s; ++t)
co_yield t;
}
CPP_template(class V, class F)(
requires ranges::input_range<V> && ranges::view_<V> &&
ranges::indirect_unary_predicate<F, ranges::iterator_t<V>>)
ranges::experimental::generator<ranges::range_reference_t<V>, ranges::range_value_t<V>>
filter(V view, F f)
{
RANGES_FOR(auto &&i, view)
{
if (ranges::invoke(f, i))
co_yield i;
}
}
CPP_template(class V, class F)(
requires ranges::input_range<V> && ranges::view_<V> &&
ranges::indirectly_unary_invocable<F, ranges::iterator_t<V>>)
meta::invoke<
maybe_sized_generator<(bool) ranges::sized_range<V>>,
ranges::indirect_result_t<F &, ranges::iterator_t<V>>>
transform(V view, F f)
{
if(RANGES_CONSTEXPR_IF(ranges::sized_range<V>))
co_await static_cast<ranges::experimental::generator_size>((std::size_t) ranges::distance(view));
RANGES_FOR(auto &&i, view)
co_yield ranges::invoke(f, i);
}
struct MoveInt
{
int i_;
MoveInt(int i = 42) : i_{i}
{}
MoveInt(MoveInt &&that) noexcept
: i_{ranges::exchange(that.i_, 0)}
{}
MoveInt &operator=(MoveInt &&that) noexcept
{
i_ = ranges::exchange(that.i_, 0);
return *this;
}
friend bool operator==(MoveInt const &x, MoveInt const &y)
{
return x.i_ == y.i_;
}
friend bool operator!=(MoveInt const &x, MoveInt const &y)
{
return !(x == y);
}
friend std::ostream &operator<<(std::ostream &os, MoveInt const &mi)
{
return os << mi.i_;
}
};
int main()
{
using namespace ranges;
auto even = [](int i){ return i % 2 == 0; };
#ifndef RANGES_WORKAROUND_MSVC_835948
{
auto rng = ::iota_generator(0, 10);
CPP_assert(sized_range<decltype(rng)>);
CHECK(size(rng) == 10u);
::check_equal(rng, {0,1,2,3,4,5,6,7,8,9});
}
{
auto rng = ::coro(::coro(::coro(::iota_generator(0, 10))));
::has_type<decltype(::iota_generator(0, 10)) &>(rng);
CPP_assert(sized_range<decltype(rng)>);
CHECK(size(rng) == 10u);
::check_equal(rng, {0,1,2,3,4,5,6,7,8,9});
}
{
auto rng = ::coro(views::ints | views::filter(even) | views::take_exactly(10));
CPP_assert(sized_range<decltype(rng)>);
CHECK(size(rng) == 10u);
::check_equal(rng, {0,2,4,6,8,10,12,14,16,18});
}
{
auto const control = {1, 2, 3};
MoveInt a[] = {{1}, {2}, {3}};
MoveInt b[3];
CHECK(equal(a, control, std::equal_to<int>{}, &MoveInt::i_));
CHECK(count(b, 42, &MoveInt::i_) == 3);
auto rng = ::coro(views::move(a));
CPP_assert(sized_range<decltype(rng)>);
CHECK(size(rng) == 3u);
copy(rng, b);
CHECK(equal(b, control, std::equal_to<int>{}, &MoveInt::i_));
CHECK(count(a, 0, &MoveInt::i_) == 3);
}
{
int some_ints[] = {0,1,2};
auto rng = ::coro(some_ints);
CPP_assert(sized_range<decltype(rng)>);
CHECK(size(rng) == 3u);
auto i = begin(rng);
auto e = end(rng);
CHECK(i != e);
CHECK(&*i == &some_ints[0]);
++i;
CHECK(i != e);
CHECK(&*i == &some_ints[1]);
++i;
CHECK(i != e);
CHECK(&*i == &some_ints[2]);
++i;
CHECK(i == e);
}
{
std::vector<bool> vec(3, false);
auto rng = ::coro(vec);
CPP_assert(sized_range<decltype(rng)>);
CHECK(size(rng) == 3u);
::check_equal(rng, {false,false,false});
}
::check_equal(f(42), g(42));
::check_equal(f(42), h(42));
{
auto rng = h(20) | views::transform([](int &x) { return ++x; });
::check_equal(rng, {1,3,5,7,9,11,13,15,17,19});
}
{
auto rng = f(20) | views::filter(even);
::check_equal(rng, {0,2,4,6,8,10,12,14,16,18});
}
#endif // RANGES_WORKAROUND_MSVC_835948
{
auto square = [](int i) { return i * i; };
int const some_ints[] = {0,1,2,3,4,5,6,7};
auto rng = ::transform(::filter(debug_input_view<int const>{some_ints}, even), square);
::check_equal(rng, {0,4,16,36});
}
return ::test_result();
}
|
0 | repos/range-v3/test/experimental | repos/range-v3/test/experimental/utility/CMakeLists.txt | set(CMAKE_FOLDER "${CMAKE_FOLDER}/utility")
if (RANGE_V3_COROUTINE_FLAGS)
rv3_add_test(test.generator generator generator.cpp)
endif()
|
0 | repos/range-v3/test/experimental | repos/range-v3/test/experimental/view/shared.cpp | // Range v3 library
//
// Copyright Filip Matzner 2017
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#include <list>
#include <memory>
#include <tuple>
#include <vector>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/for_each.hpp>
#include <range/v3/view/cycle.hpp>
#include <range/v3/view/for_each.hpp>
#include <range/v3/view/iota.hpp>
#include <range/v3/view/join.hpp>
#include <range/v3/view/remove_if.hpp>
#include <range/v3/view/repeat.hpp>
#include <range/v3/view/reverse.hpp>
#include <range/v3/experimental/view/shared.hpp>
#include <range/v3/view/take.hpp>
#include "../../simple_test.hpp"
#include "../../test_utils.hpp"
using namespace ranges;
template<typename T>
void check_shared_contents()
{
// build two instances sharing the same range
experimental::shared_view<T> view1 = experimental::views::shared(T{1, 1, 1, 2, 3, 4, 4});
experimental::shared_view<T> view2 = view1;
// check the length of the views
CHECK(view1.size() == 7u);
CHECK(view2.size() == 7u);
// check the stored numbers
auto check_values = [](experimental::shared_view<T> & rng) {
::check_equal(views::cycle(rng) | views::take(10), {1, 1, 1, 2, 3, 4, 4, 1, 1, 1});
::check_equal(views::all(rng) | views::take(5), {1, 1, 1, 2, 3});
::check_equal(rng | views::take(5), {1, 1, 1, 2, 3});
::check_equal(rng, {1, 1, 1, 2, 3, 4, 4});
};
check_values(view1);
check_values(view2);
// check that changes are shared
*(++begin(view1)) = 7;
CHECK(*(++begin(view2)) == 7);
*begin(view2) = 3;
CHECK(*begin(view1) == 3);
}
int main()
{
// check shared random access range
check_shared_contents<std::vector<int>>();
// check shared bidirectional range
check_shared_contents<std::list<int>>();
{
// check the piped construction from an rvalue
std::vector<int> base_vec = {1, 2, 2, 8, 2, 7};
auto vec_view = std::move(base_vec) | experimental::views::shared;
CHECK(vec_view.size() == 6u);
::check_equal(vec_view, {1, 2, 2, 8, 2, 7});
}
{
// test bidirectional range
auto list_view = std::list<int>{1, 2, 3} | experimental::views::shared;
CHECK(list_view.size() == 3u);
has_type<int &>(*begin(list_view));
CPP_assert(sized_range<decltype(list_view)>);
CPP_assert(common_range<decltype(list_view)>);
CPP_assert(bidirectional_range<decltype(list_view)>);
CPP_assert(!random_access_range<decltype(list_view)>);
// test bidirectional range iterator
CHECK(*begin(list_view) == 1);
CHECK(*prev(end(list_view)) == 3);
}
{
// test random access range
auto vec_view = std::vector<int>{1, 2, 3} | experimental::views::shared;
CHECK(vec_view.size() == 3u);
has_type<int &>(*begin(vec_view));
CPP_assert(sized_range<decltype(vec_view)>);
CPP_assert(common_range<decltype(vec_view)>);
CPP_assert(random_access_range<decltype(vec_view)>);
CHECK(vec_view[0] == 1);
CHECK(vec_view[1] == 2);
CHECK(vec_view[2] == 3);
}
{
// check temporary value in views::transform
auto f = [](unsigned a){ return std::vector<unsigned>(a, a); };
auto vec_view =
views::iota(1u)
| views::transform(f)
| views::transform(experimental::views::shared)
| views::join
| views::take(10);
::check_equal(vec_view, {1u, 2u, 2u, 3u, 3u, 3u, 4u, 4u, 4u, 4u});
}
{
// check temporary value in views::for_each
std::vector<int> base_vec{1, 2, 3};
auto vec_view =
views::repeat(base_vec)
| views::for_each([](std::vector<int> tmp) {
return yield_from(std::move(tmp) | experimental::views::shared | views::reverse);
})
| views::take(7);
::check_equal(vec_view, {3, 2, 1, 3, 2, 1, 3});
}
{
// check temporary value in views::for_each without the yield_from
std::vector<int> base_vec{1, 2, 3};
auto vec_view =
views::repeat(base_vec)
| views::for_each([](std::vector<int> tmp) {
return std::move(tmp) | experimental::views::shared | views::reverse;
})
| views::take(7);
::check_equal(vec_view, {3, 2, 1, 3, 2, 1, 3});
}
return test_result();
}
|
0 | repos/range-v3/test/experimental | repos/range-v3/test/experimental/view/CMakeLists.txt | set(CMAKE_FOLDER "${CMAKE_FOLDER}/view")
rv3_add_test(test.view.shared view.shared shared.cpp)
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/is_heap_until1.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#define IS_HEAP_UNTIL_1
#include "./is_heap_until.hpp"
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/set_difference3.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#define SET_DIFFERENCE_3
#include "./set_difference.hpp"
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/replace.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright 2005 - 2007 Adobe Systems Incorporated
// Distributed under the MIT License(see accompanying file LICENSE_1_0_0.txt
// or a copy at http://stlab.adobe.com/licenses.html)
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <utility>
#include <vector>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/replace.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
template<typename Iter, typename Sent = Iter>
void test_iter()
{
int ia[] = {0, 1, 2, 3, 4};
const unsigned sa = sizeof(ia)/sizeof(ia[0]);
Iter i = ranges::replace(Iter(ia), Sent(ia+sa), 2, 5);
CHECK(ia[0] == 0);
CHECK(ia[1] == 1);
CHECK(ia[2] == 5);
CHECK(ia[3] == 3);
CHECK(ia[4] == 4);
CHECK(base(i) == ia + sa);
}
template<typename Iter, typename Sent = Iter>
void test_rng()
{
int ia[] = {0, 1, 2, 3, 4};
const unsigned sa = sizeof(ia)/sizeof(ia[0]);
auto rng = ranges::make_subrange(Iter(ia), Sent(ia+sa));
Iter i = ranges::replace(rng, 2, 5);
CHECK(ia[0] == 0);
CHECK(ia[1] == 1);
CHECK(ia[2] == 5);
CHECK(ia[3] == 3);
CHECK(ia[4] == 4);
CHECK(base(i) == ia + sa);
}
constexpr bool test_constexpr()
{
using namespace ranges;
int ia[] = {0, 1, 2, 3, 4};
constexpr auto sa = ranges::size(ia);
auto r = ranges::replace(ia, 2, 42);
STATIC_CHECK_RETURN(r == ia + sa);
STATIC_CHECK_RETURN(ia[0] == 0);
STATIC_CHECK_RETURN(ia[1] == 1);
STATIC_CHECK_RETURN(ia[2] == 42);
STATIC_CHECK_RETURN(ia[3] == 3);
STATIC_CHECK_RETURN(ia[4] == 4);
return true;
}
int main()
{
test_iter<ForwardIterator<int*> >();
test_iter<BidirectionalIterator<int*> >();
test_iter<RandomAccessIterator<int*> >();
test_iter<int*>();
test_iter<ForwardIterator<int*>, Sentinel<int*> >();
test_iter<BidirectionalIterator<int*>, Sentinel<int*> >();
test_iter<RandomAccessIterator<int*>, Sentinel<int*> >();
test_rng<ForwardIterator<int*> >();
test_rng<BidirectionalIterator<int*> >();
test_rng<RandomAccessIterator<int*> >();
test_rng<int*>();
test_rng<ForwardIterator<int*>, Sentinel<int*> >();
test_rng<BidirectionalIterator<int*>, Sentinel<int*> >();
test_rng<RandomAccessIterator<int*>, Sentinel<int*> >();
// test projection
{
using P = std::pair<int,std::string>;
P ia[] = {{0,"0"}, {1,"1"}, {2,"2"}, {3,"3"}, {4,"4"}};
P *i = ranges::replace(ia, 2, std::make_pair(42,"42"), &std::pair<int,std::string>::first);
CHECK(ia[0] == P{0,"0"});
CHECK(ia[1] == P{1,"1"});
CHECK(ia[2] == P{42,"42"});
CHECK(ia[3] == P{3,"3"});
CHECK(ia[4] == P{4,"4"});
CHECK(i == ranges::end(ia));
}
// test rvalue ranges
{
using P = std::pair<int,std::string>;
P ia[] = {{0,"0"}, {1,"1"}, {2,"2"}, {3,"3"}, {4,"4"}};
auto i = ranges::replace(std::move(ia), 2, std::make_pair(42,"42"), &std::pair<int,std::string>::first);
#ifndef RANGES_WORKAROUND_MSVC_573728
CHECK(::is_dangling(i));
#endif // RANGES_WORKAROUND_MSVC_573728
CHECK(ia[0] == P{0,"0"});
CHECK(ia[1] == P{1,"1"});
CHECK(ia[2] == P{42,"42"});
CHECK(ia[3] == P{3,"3"});
CHECK(ia[4] == P{4,"4"});
}
{
using P = std::pair<int,std::string>;
std::vector<P> ia{{0,"0"}, {1,"1"}, {2,"2"}, {3,"3"}, {4,"4"}};
auto i = ranges::replace(std::move(ia), 2, std::make_pair(42,"42"), &std::pair<int,std::string>::first);
CHECK(::is_dangling(i));
CHECK(ia[0] == P{0,"0"});
CHECK(ia[1] == P{1,"1"});
CHECK(ia[2] == P{42,"42"});
CHECK(ia[3] == P{3,"3"});
CHECK(ia[4] == P{4,"4"});
}
{
STATIC_CHECK(test_constexpr());
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/reverse_copy.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright 2005 - 2007 Adobe Systems Incorporated
// Distributed under the MIT License(see accompanying file LICENSE_1_0_0.txt
// or a copy at http://stlab.adobe.com/licenses.html)
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <cstring>
#include <utility>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/reverse_copy.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
template<class Iter, class OutIter, class Sent = Iter>
void test()
{
using P = ranges::reverse_copy_result<Iter, OutIter>;
// iterators
{
const int ia[] = {0};
const unsigned sa = sizeof(ia)/sizeof(ia[0]);
int ja[sa] = {-1};
P p0 = ranges::reverse_copy(Iter(ia), Sent(ia), OutIter(ja));
::check_equal(ja, {-1});
CHECK(p0.in == Iter(ia));
CHECK(base(p0.out) == ja);
P p1 = ranges::reverse_copy(Iter(ia), Sent(ia+sa), OutIter(ja));
::check_equal(ja, {0});
CHECK(p1.in == Iter(ia+sa));
CHECK(base(p1.out) == ja+sa);
const int ib[] = {0, 1};
const unsigned sb = sizeof(ib)/sizeof(ib[0]);
int jb[sb] = {-1};
P p2 = ranges::reverse_copy(Iter(ib), Sent(ib+sb), OutIter(jb));
::check_equal(jb, {1, 0});
CHECK(p2.in == Iter(ib+sb));
CHECK(base(p2.out) == jb+sb);
const int ic[] = {0, 1, 2};
const unsigned sc = sizeof(ic)/sizeof(ic[0]);
int jc[sc] = {-1};
P p3 = ranges::reverse_copy(Iter(ic), Sent(ic+sc), OutIter(jc));
::check_equal(jc, {2, 1, 0});
CHECK(p3.in == Iter(ic+sc));
CHECK(base(p3.out) == jc+sc);
const int id[] = {0, 1, 2, 3};
const unsigned sd = sizeof(id)/sizeof(id[0]);
int jd[sd] = {-1};
P p4 = ranges::reverse_copy(Iter(id), Sent(id+sd), OutIter(jd));
::check_equal(jd, {3, 2, 1, 0});
CHECK(p4.in == Iter(id+sd));
CHECK(base(p4.out) == jd+sd);
}
// ranges
{
const int ia[] = {0};
const unsigned sa = sizeof(ia)/sizeof(ia[0]);
int ja[sa] = {-1};
P p0 = ranges::reverse_copy(ranges::make_subrange(Iter(ia), Sent(ia)), OutIter(ja));
::check_equal(ja, {-1});
CHECK(p0.in == Iter(ia));
CHECK(base(p0.out) == ja);
P p1 = ranges::reverse_copy(ranges::make_subrange(Iter(ia), Sent(ia+sa)), OutIter(ja));
::check_equal(ja, {0});
CHECK(p1.in == Iter(ia+sa));
CHECK(base(p1.out) == ja+sa);
const int ib[] = {0, 1};
const unsigned sb = sizeof(ib)/sizeof(ib[0]);
int jb[sb] = {-1};
P p2 = ranges::reverse_copy(ranges::make_subrange(Iter(ib), Sent(ib+sb)), OutIter(jb));
::check_equal(jb, {1, 0});
CHECK(p2.in == Iter(ib+sb));
CHECK(base(p2.out) == jb+sb);
const int ic[] = {0, 1, 2};
const unsigned sc = sizeof(ic)/sizeof(ic[0]);
int jc[sc] = {-1};
P p3 = ranges::reverse_copy(ranges::make_subrange(Iter(ic), Sent(ic+sc)), OutIter(jc));
::check_equal(jc, {2, 1, 0});
CHECK(p3.in == Iter(ic+sc));
CHECK(base(p3.out) == jc+sc);
const int id[] = {0, 1, 2, 3};
const unsigned sd = sizeof(id)/sizeof(id[0]);
int jd[sd] = {-1};
P p4 = ranges::reverse_copy(ranges::make_subrange(Iter(id), Sent(id+sd)), OutIter(jd));
::check_equal(jd, {3, 2, 1, 0});
CHECK(p4.in == Iter(id+sd));
CHECK(base(p4.out) == jd+sd);
// test rvalue ranges
std::memset(jd, 0, sizeof(jd));
auto p5 = ranges::reverse_copy(::MakeTestRange(Iter(id), Sent(id+sd)), OutIter(jd));
::check_equal(jd, {3, 2, 1, 0});
CHECK(::is_dangling(p5.in));
CHECK(base(p4.out) == jd+sd);
}
}
constexpr bool test_constexpr()
{
using namespace ranges;
int ia[] = {0, 1, 2, 3, 4};
int ib[5] = {0};
constexpr auto sa = ranges::size(ia);
const auto r = ranges::reverse_copy(ia, ib);
STATIC_CHECK_RETURN(r.in == ia + sa);
STATIC_CHECK_RETURN(r.out == ib + sa);
STATIC_CHECK_RETURN(ia[0] == 0);
STATIC_CHECK_RETURN(ia[1] == 1);
STATIC_CHECK_RETURN(ia[2] == 2);
STATIC_CHECK_RETURN(ia[3] == 3);
STATIC_CHECK_RETURN(ia[4] == 4);
STATIC_CHECK_RETURN(ib[0] == 4);
STATIC_CHECK_RETURN(ib[1] == 3);
STATIC_CHECK_RETURN(ib[2] == 2);
STATIC_CHECK_RETURN(ib[3] == 1);
STATIC_CHECK_RETURN(ib[4] == 0);
return true;
}
int main()
{
test<BidirectionalIterator<const int*>, OutputIterator<int*> >();
test<BidirectionalIterator<const int*>, ForwardIterator<int*> >();
test<BidirectionalIterator<const int*>, BidirectionalIterator<int*> >();
test<BidirectionalIterator<const int*>, RandomAccessIterator<int*> >();
test<BidirectionalIterator<const int*>, int*>();
test<RandomAccessIterator<const int*>, OutputIterator<int*> >();
test<RandomAccessIterator<const int*>, ForwardIterator<int*> >();
test<RandomAccessIterator<const int*>, BidirectionalIterator<int*> >();
test<RandomAccessIterator<const int*>, RandomAccessIterator<int*> >();
test<RandomAccessIterator<const int*>, int*>();
test<const int*, OutputIterator<int*> >();
test<const int*, ForwardIterator<int*> >();
test<const int*, BidirectionalIterator<int*> >();
test<const int*, RandomAccessIterator<int*> >();
test<const int*, int*>();
test<BidirectionalIterator<const int*>, OutputIterator<int*>, Sentinel<const int *> >();
test<BidirectionalIterator<const int*>, ForwardIterator<int*>, Sentinel<const int *> >();
test<BidirectionalIterator<const int*>, BidirectionalIterator<int*>, Sentinel<const int *> >();
test<BidirectionalIterator<const int*>, RandomAccessIterator<int*>, Sentinel<const int *> >();
test<BidirectionalIterator<const int*>, int*>();
test<RandomAccessIterator<const int*>, OutputIterator<int*>, Sentinel<const int *> >();
test<RandomAccessIterator<const int*>, ForwardIterator<int*>, Sentinel<const int *> >();
test<RandomAccessIterator<const int*>, BidirectionalIterator<int*>, Sentinel<const int *> >();
test<RandomAccessIterator<const int*>, RandomAccessIterator<int*>, Sentinel<const int *> >();
test<RandomAccessIterator<const int*>, int*>();
test<const int*, OutputIterator<int*>, Sentinel<const int *> >();
test<const int*, ForwardIterator<int*>, Sentinel<const int *> >();
test<const int*, BidirectionalIterator<int*>, Sentinel<const int *> >();
test<const int*, RandomAccessIterator<int*>, Sentinel<const int *> >();
test<const int*, int*>();
{
STATIC_CHECK(test_constexpr());
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/starts_with.cpp | // Range v3 library
//
// Copyright 2019 Christopher Di Bella
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#include <range/v3/algorithm/starts_with.hpp>
#include "../simple_test.hpp"
#include "../test_iterators.hpp"
#include <forward_list>
#include <range/v3/range/conversion.hpp>
#include <range/v3/view/iota.hpp>
#include <range/v3/view/slice.hpp>
#include <range/v3/view/take_exactly.hpp>
#include <range/v3/view/istream.hpp>
#include <sstream>
#include <vector>
void test_defaults()
{
using namespace ranges;
{ // checks starts_with works for input ranges
constexpr auto full_latin_alphabet = "a b c d e f g h i j k l m n o p q r s t u v w x y z";
auto const partial_latin_alphabet = "a b c d";
{
auto long_stream = std::istringstream{full_latin_alphabet};
auto short_stream = std::istringstream{partial_latin_alphabet};
auto r1 = istream<char>(long_stream);
auto r2 = istream<char>(short_stream);
CHECK(starts_with(begin(r1), end(r1), begin(r2), end(r2)));
}
{
auto long_stream = std::istringstream{full_latin_alphabet};
auto short_stream = std::istringstream{partial_latin_alphabet};
auto r1 = istream<char>(long_stream);
auto r2 = istream<char>(short_stream);
CHECK(!starts_with(begin(r2), end(r2), begin(r1), end(r1)));
}
{
auto long_stream = std::istringstream{full_latin_alphabet};
auto short_stream = std::istringstream{partial_latin_alphabet};
CHECK(starts_with(istream<char>(long_stream), istream<char>(short_stream)));
}
{
auto long_stream = std::istringstream{full_latin_alphabet};
auto short_stream = std::istringstream{partial_latin_alphabet};
CHECK(!starts_with(istream<char>(short_stream), istream<char>(long_stream)));
}
}
{ // checks starts_with works for random-access ranges
#ifdef RANGES_WORKAROUND_MSVC_779708
auto const long_range = views::iota(0, 100) | to<std::vector>();
auto const short_range = views::iota(0, 10) | to<std::vector>();
#else // ^^^ workaround / no workaround vvv
auto const long_range = views::iota(0, 100) | to<std::vector>;
auto const short_range = views::iota(0, 10) | to<std::vector>;
#endif // RANGES_WORKAROUND_MSVC_779708
CHECK(starts_with(begin(long_range), end(long_range), begin(short_range), end(short_range)));
CHECK(starts_with(long_range, short_range));
CHECK(!starts_with(begin(short_range), end(short_range), begin(long_range), end(long_range)));
CHECK(!starts_with(short_range, long_range));
}
{ // checks starts_with works for random-access ranges with arbitrary sentinels
auto const long_range = views::iota(0);
auto const short_range = views::iota(0) | views::take_exactly(100);
CHECK(starts_with(begin(long_range), end(long_range), begin(short_range), end(short_range)));
CHECK(starts_with(long_range, short_range));
CHECK(!starts_with(begin(short_range), end(short_range), begin(long_range), end(long_range)));
CHECK(!starts_with(short_range, long_range));
}
{ // checks starts_with identifies a subrange
auto const range = views::iota(0) | views::slice(50, 100);
auto const offset = views::iota(50, 100);
CHECK(starts_with(begin(range), end(range), begin(offset), end(offset)));
CHECK(starts_with(range, offset));
CHECK(starts_with(begin(offset), end(offset), begin(range), end(range)));
CHECK(starts_with(offset, range));
}
{ // checks starts_with identifies when two ranges don't have the same start sequence
auto const first = views::iota(0, 1'000);
auto const second = views::iota(10, 1'000);
CHECK(!starts_with(begin(first), end(first), begin(second), end(second)));
CHECK(!starts_with(first, second));
CHECK(!starts_with(begin(second), end(second), begin(first), end(first)));
CHECK(!starts_with(second, first));
}
}
void test_comparison()
{
using namespace ranges;
auto const long_range = views::iota(0, 100);
auto const short_range = views::iota(1, 51);
CHECK(starts_with(begin(long_range), end(long_range), begin(short_range), end(short_range),
less{}));
CHECK(starts_with(long_range, short_range, less{}));
CHECK(!starts_with(begin(long_range), end(long_range), begin(short_range), end(short_range),
greater{}));
CHECK(!starts_with(long_range, short_range, greater{}));
}
int main()
{
::test_defaults();
::test_comparison();
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/stable_partition.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright 2005 - 2007 Adobe Systems Incorporated
// Distributed under the MIT License(see accompanying file LICENSE_1_0_0.txt
// or a copy at http://stlab.adobe.com/licenses.html)
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <memory>
#include <utility>
#include <vector>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/stable_partition.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
struct is_odd
{
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;
}
};
template<class Iter, class Sent = Iter>
void
test_iter()
{
using P = std::pair<int, int>;
{ // check mixed
P ap[] = { {0, 1}, {0, 2}, {1, 1}, {1, 2}, {2, 1}, {2, 2}, {3, 1}, {3, 2}, {4, 1}, {4, 2} };
std::size_t size = ranges::size(ap);
Iter r = ranges::stable_partition(Iter(ap), Sent(ap+size), odd_first());
CHECK(base(r) == ap + 4);
CHECK(ap[0] == P{1, 1});
CHECK(ap[1] == P{1, 2});
CHECK(ap[2] == P{3, 1});
CHECK(ap[3] == P{3, 2});
CHECK(ap[4] == P{0, 1});
CHECK(ap[5] == P{0, 2});
CHECK(ap[6] == P{2, 1});
CHECK(ap[7] == P{2, 2});
CHECK(ap[8] == P{4, 1});
CHECK(ap[9] == P{4, 2});
}
{
P ap[] = { {0, 1}, {0, 2}, {1, 1}, {1, 2}, {2, 1}, {2, 2}, {3, 1}, {3, 2}, {4, 1}, {4, 2} };
std::size_t size = ranges::size(ap);
Iter r = ranges::stable_partition(Iter(ap), Sent(ap+size), odd_first());
CHECK(base(r) == ap + 4);
CHECK(ap[0] == P{1, 1});
CHECK(ap[1] == P{1, 2});
CHECK(ap[2] == P{3, 1});
CHECK(ap[3] == P{3, 2});
CHECK(ap[4] == P{0, 1});
CHECK(ap[5] == P{0, 2});
CHECK(ap[6] == P{2, 1});
CHECK(ap[7] == P{2, 2});
CHECK(ap[8] == P{4, 1});
CHECK(ap[9] == P{4, 2});
// check empty
r = ranges::stable_partition(Iter(ap), Sent(ap), odd_first());
CHECK(base(r) == ap);
// check one true
r = ranges::stable_partition(Iter(ap), Sent(ap+1), odd_first());
CHECK(base(r) == ap+1);
CHECK(ap[0] == P{1, 1});
// check one false
r = ranges::stable_partition(Iter(ap+4), Sent(ap+5), odd_first());
CHECK(base(r) == ap+4);
CHECK(ap[4] == P{0, 1});
}
{ // check all false
P ap[] = { {0, 1}, {0, 2}, {2, 1}, {2, 2}, {4, 1}, {4, 2}, {6, 1}, {6, 2}, {8, 1}, {8, 2} };
std::size_t size = ranges::size(ap);
Iter r = ranges::stable_partition(Iter(ap), Sent(ap+size), odd_first());
CHECK(base(r) == ap);
CHECK(ap[0] == P{0, 1});
CHECK(ap[1] == P{0, 2});
CHECK(ap[2] == P{2, 1});
CHECK(ap[3] == P{2, 2});
CHECK(ap[4] == P{4, 1});
CHECK(ap[5] == P{4, 2});
CHECK(ap[6] == P{6, 1});
CHECK(ap[7] == P{6, 2});
CHECK(ap[8] == P{8, 1});
CHECK(ap[9] == P{8, 2});
}
{ // check all true
P ap[] = { {1, 1}, {1, 2}, {3, 1}, {3, 2}, {5, 1}, {5, 2}, {7, 1}, {7, 2}, {9, 1}, {9, 2} };
std::size_t size = ranges::size(ap);
Iter r = ranges::stable_partition(Iter(ap), Sent(ap+size), odd_first());
CHECK(base(r) == ap + size);
CHECK(ap[0] == P{1, 1});
CHECK(ap[1] == P{1, 2});
CHECK(ap[2] == P{3, 1});
CHECK(ap[3] == P{3, 2});
CHECK(ap[4] == P{5, 1});
CHECK(ap[5] == P{5, 2});
CHECK(ap[6] == P{7, 1});
CHECK(ap[7] == P{7, 2});
CHECK(ap[8] == P{9, 1});
CHECK(ap[9] == P{9, 2});
}
{ // check all false but first true
P ap[] = { {1, 1}, {0, 2}, {2, 1}, {2, 2}, {4, 1}, {4, 2}, {6, 1}, {6, 2}, {8, 1}, {8, 2} };
std::size_t size = ranges::size(ap);
Iter r = ranges::stable_partition(Iter(ap), Sent(ap+size), odd_first());
CHECK(base(r) == ap + 1);
CHECK(ap[0] == P{1, 1});
CHECK(ap[1] == P{0, 2});
CHECK(ap[2] == P{2, 1});
CHECK(ap[3] == P{2, 2});
CHECK(ap[4] == P{4, 1});
CHECK(ap[5] == P{4, 2});
CHECK(ap[6] == P{6, 1});
CHECK(ap[7] == P{6, 2});
CHECK(ap[8] == P{8, 1});
CHECK(ap[9] == P{8, 2});
}
{ // check all false but last true
P ap[] = { {0, 1}, {0, 2}, {2, 1}, {2, 2}, {4, 1}, {4, 2}, {6, 1}, {6, 2}, {8, 1}, {1, 2} };
std::size_t size = ranges::size(ap);
Iter r = ranges::stable_partition(Iter(ap), Sent(ap+size), odd_first());
CHECK(base(r) == ap + 1);
CHECK(ap[0] == P{1, 2});
CHECK(ap[1] == P{0, 1});
CHECK(ap[2] == P{0, 2});
CHECK(ap[3] == P{2, 1});
CHECK(ap[4] == P{2, 2});
CHECK(ap[5] == P{4, 1});
CHECK(ap[6] == P{4, 2});
CHECK(ap[7] == P{6, 1});
CHECK(ap[8] == P{6, 2});
CHECK(ap[9] == P{8, 1});
}
{ // check all true but first false
P ap[] = { {0, 1}, {1, 2}, {3, 1}, {3, 2}, {5, 1}, {5, 2}, {7, 1}, {7, 2}, {9, 1}, {9, 2} };
std::size_t size = ranges::size(ap);
Iter r = ranges::stable_partition(Iter(ap), Sent(ap+size), odd_first());
CHECK(base(r) == ap + size-1);
CHECK(ap[0] == P{1, 2});
CHECK(ap[1] == P{3, 1});
CHECK(ap[2] == P{3, 2});
CHECK(ap[3] == P{5, 1});
CHECK(ap[4] == P{5, 2});
CHECK(ap[5] == P{7, 1});
CHECK(ap[6] == P{7, 2});
CHECK(ap[7] == P{9, 1});
CHECK(ap[8] == P{9, 2});
CHECK(ap[9] == P{0, 1});
}
{ // check all true but last false
P ap[] = { {1, 1}, {1, 2}, {3, 1}, {3, 2}, {5, 1}, {5, 2}, {7, 1}, {7, 2}, {9, 1}, {0, 2} };
std::size_t size = ranges::size(ap);
Iter r = ranges::stable_partition(Iter(ap), Sent(ap+size), odd_first());
CHECK(base(r) == ap + size-1);
CHECK(ap[0] == P{1, 1});
CHECK(ap[1] == P{1, 2});
CHECK(ap[2] == P{3, 1});
CHECK(ap[3] == P{3, 2});
CHECK(ap[4] == P{5, 1});
CHECK(ap[5] == P{5, 2});
CHECK(ap[6] == P{7, 1});
CHECK(ap[7] == P{7, 2});
CHECK(ap[8] == P{9, 1});
CHECK(ap[9] == P{0, 2});
}
}
template<class Iter, class Sent = Iter>
void
test_range()
{
using P = std::pair<int, int>;
{ // check mixed
P ap[] = { {0, 1}, {0, 2}, {1, 1}, {1, 2}, {2, 1}, {2, 2}, {3, 1}, {3, 2}, {4, 1}, {4, 2} };
std::size_t size = ranges::size(ap);
Iter r = ranges::stable_partition(::as_lvalue(ranges::make_subrange(Iter(ap), Sent(ap+size))), odd_first());
CHECK(base(r) == ap + 4);
CHECK(ap[0] == P{1, 1});
CHECK(ap[1] == P{1, 2});
CHECK(ap[2] == P{3, 1});
CHECK(ap[3] == P{3, 2});
CHECK(ap[4] == P{0, 1});
CHECK(ap[5] == P{0, 2});
CHECK(ap[6] == P{2, 1});
CHECK(ap[7] == P{2, 2});
CHECK(ap[8] == P{4, 1});
CHECK(ap[9] == P{4, 2});
}
{
P ap[] = { {0, 1}, {0, 2}, {1, 1}, {1, 2}, {2, 1}, {2, 2}, {3, 1}, {3, 2}, {4, 1}, {4, 2} };
std::size_t size = ranges::size(ap);
Iter r = ranges::stable_partition(::as_lvalue(ranges::make_subrange(Iter(ap), Sent(ap+size))), odd_first());
CHECK(base(r) == ap + 4);
CHECK(ap[0] == P{1, 1});
CHECK(ap[1] == P{1, 2});
CHECK(ap[2] == P{3, 1});
CHECK(ap[3] == P{3, 2});
CHECK(ap[4] == P{0, 1});
CHECK(ap[5] == P{0, 2});
CHECK(ap[6] == P{2, 1});
CHECK(ap[7] == P{2, 2});
CHECK(ap[8] == P{4, 1});
CHECK(ap[9] == P{4, 2});
// check empty
r = ranges::stable_partition(::as_lvalue(ranges::make_subrange(Iter(ap), Sent(ap))), odd_first());
CHECK(base(r) == ap);
// check one true
r = ranges::stable_partition(::as_lvalue(ranges::make_subrange(Iter(ap), Sent(ap+1))), odd_first());
CHECK(base(r) == ap+1);
CHECK(ap[0] == P{1, 1});
// check one false
r = ranges::stable_partition(::as_lvalue(ranges::make_subrange(Iter(ap+4), Sent(ap+5))), odd_first());
CHECK(base(r) == ap+4);
CHECK(ap[4] == P{0, 1});
}
{ // check all false
P ap[] = { {0, 1}, {0, 2}, {2, 1}, {2, 2}, {4, 1}, {4, 2}, {6, 1}, {6, 2}, {8, 1}, {8, 2} };
std::size_t size = ranges::size(ap);
Iter r = ranges::stable_partition(::as_lvalue(ranges::make_subrange(Iter(ap), Sent(ap+size))), odd_first());
CHECK(base(r) == ap);
CHECK(ap[0] == P{0, 1});
CHECK(ap[1] == P{0, 2});
CHECK(ap[2] == P{2, 1});
CHECK(ap[3] == P{2, 2});
CHECK(ap[4] == P{4, 1});
CHECK(ap[5] == P{4, 2});
CHECK(ap[6] == P{6, 1});
CHECK(ap[7] == P{6, 2});
CHECK(ap[8] == P{8, 1});
CHECK(ap[9] == P{8, 2});
}
{ // check all true
P ap[] = { {1, 1}, {1, 2}, {3, 1}, {3, 2}, {5, 1}, {5, 2}, {7, 1}, {7, 2}, {9, 1}, {9, 2} };
std::size_t size = ranges::size(ap);
Iter r = ranges::stable_partition(::as_lvalue(ranges::make_subrange(Iter(ap), Sent(ap+size))), odd_first());
CHECK(base(r) == ap + size);
CHECK(ap[0] == P{1, 1});
CHECK(ap[1] == P{1, 2});
CHECK(ap[2] == P{3, 1});
CHECK(ap[3] == P{3, 2});
CHECK(ap[4] == P{5, 1});
CHECK(ap[5] == P{5, 2});
CHECK(ap[6] == P{7, 1});
CHECK(ap[7] == P{7, 2});
CHECK(ap[8] == P{9, 1});
CHECK(ap[9] == P{9, 2});
}
{ // check all false but first true
P ap[] = { {1, 1}, {0, 2}, {2, 1}, {2, 2}, {4, 1}, {4, 2}, {6, 1}, {6, 2}, {8, 1}, {8, 2} };
std::size_t size = ranges::size(ap);
Iter r = ranges::stable_partition(::as_lvalue(ranges::make_subrange(Iter(ap), Sent(ap+size))), odd_first());
CHECK(base(r) == ap + 1);
CHECK(ap[0] == P{1, 1});
CHECK(ap[1] == P{0, 2});
CHECK(ap[2] == P{2, 1});
CHECK(ap[3] == P{2, 2});
CHECK(ap[4] == P{4, 1});
CHECK(ap[5] == P{4, 2});
CHECK(ap[6] == P{6, 1});
CHECK(ap[7] == P{6, 2});
CHECK(ap[8] == P{8, 1});
CHECK(ap[9] == P{8, 2});
}
{ // check all false but last true
P ap[] = { {0, 1}, {0, 2}, {2, 1}, {2, 2}, {4, 1}, {4, 2}, {6, 1}, {6, 2}, {8, 1}, {1, 2} };
std::size_t size = ranges::size(ap);
Iter r = ranges::stable_partition(::as_lvalue(ranges::make_subrange(Iter(ap), Sent(ap+size))), odd_first());
CHECK(base(r) == ap + 1);
CHECK(ap[0] == P{1, 2});
CHECK(ap[1] == P{0, 1});
CHECK(ap[2] == P{0, 2});
CHECK(ap[3] == P{2, 1});
CHECK(ap[4] == P{2, 2});
CHECK(ap[5] == P{4, 1});
CHECK(ap[6] == P{4, 2});
CHECK(ap[7] == P{6, 1});
CHECK(ap[8] == P{6, 2});
CHECK(ap[9] == P{8, 1});
}
{ // check all true but first false
P ap[] = { {0, 1}, {1, 2}, {3, 1}, {3, 2}, {5, 1}, {5, 2}, {7, 1}, {7, 2}, {9, 1}, {9, 2} };
std::size_t size = ranges::size(ap);
Iter r = ranges::stable_partition(::as_lvalue(ranges::make_subrange(Iter(ap), Sent(ap+size))), odd_first());
CHECK(base(r) == ap + size-1);
CHECK(ap[0] == P{1, 2});
CHECK(ap[1] == P{3, 1});
CHECK(ap[2] == P{3, 2});
CHECK(ap[3] == P{5, 1});
CHECK(ap[4] == P{5, 2});
CHECK(ap[5] == P{7, 1});
CHECK(ap[6] == P{7, 2});
CHECK(ap[7] == P{9, 1});
CHECK(ap[8] == P{9, 2});
CHECK(ap[9] == P{0, 1});
}
{ // check all true but last false
P ap[] = { {1, 1}, {1, 2}, {3, 1}, {3, 2}, {5, 1}, {5, 2}, {7, 1}, {7, 2}, {9, 1}, {0, 2} };
std::size_t size = ranges::size(ap);
Iter r = ranges::stable_partition(::as_lvalue(ranges::make_subrange(Iter(ap), Sent(ap+size))), odd_first());
CHECK(base(r) == ap + size-1);
CHECK(ap[0] == P{1, 1});
CHECK(ap[1] == P{1, 2});
CHECK(ap[2] == P{3, 1});
CHECK(ap[3] == P{3, 2});
CHECK(ap[4] == P{5, 1});
CHECK(ap[5] == P{5, 2});
CHECK(ap[6] == P{7, 1});
CHECK(ap[7] == P{7, 2});
CHECK(ap[8] == P{9, 1});
CHECK(ap[9] == P{0, 2});
}
}
struct move_only
{
static int count;
int i;
move_only() = delete;
move_only(int j) : i(j) { ++count; }
move_only(move_only &&that) : i(that.i) { ++count; }
move_only(move_only const &) = delete;
~move_only() { --count; }
move_only &operator=(move_only &&) = default;
move_only &operator=(move_only const &) = delete;
};
int move_only::count = 0;
template<class Iter>
void
test_move_only()
{
const unsigned size = 5;
move_only array[size] = { 1, 2, 3, 4, 5 };
Iter r = ranges::stable_partition(Iter(array), Iter(array+size), is_odd{}, &move_only::i);
CHECK(base(r) == array + 3);
CHECK(array[0].i == 1);
CHECK(array[1].i == 3);
CHECK(array[2].i == 5);
CHECK(array[3].i == 2);
CHECK(array[4].i == 4);
}
struct S
{
std::pair<int,int> p;
};
int main()
{
test_iter<BidirectionalIterator<std::pair<int,int>*> >();
test_iter<RandomAccessIterator<std::pair<int,int>*> >();
test_iter<std::pair<int,int>*>();
test_iter<BidirectionalIterator<std::pair<int,int>*>, Sentinel<std::pair<int,int>*> >();
test_iter<RandomAccessIterator<std::pair<int,int>*>, Sentinel<std::pair<int,int>*> >();
test_range<BidirectionalIterator<std::pair<int,int>*> >();
test_range<RandomAccessIterator<std::pair<int,int>*> >();
test_range<std::pair<int,int>*>();
test_range<BidirectionalIterator<std::pair<int,int>*>, Sentinel<std::pair<int,int>*> >();
test_range<RandomAccessIterator<std::pair<int,int>*>, Sentinel<std::pair<int,int>*> >();
CHECK(move_only::count == 0);
test_move_only<BidirectionalIterator<move_only*> >();
CHECK(move_only::count == 0);
// Test projections
using P = std::pair<int, int>;
{ // check mixed
S ap[] = { {{0, 1}}, {{0, 2}}, {{1, 1}}, {{1, 2}}, {{2, 1}}, {{2, 2}}, {{3, 1}}, {{3, 2}}, {{4, 1}}, {{4, 2}} };
S* r = ranges::stable_partition(ap, odd_first(), &S::p);
CHECK(r == ap + 4);
CHECK(ap[0].p == P{1, 1});
CHECK(ap[1].p == P{1, 2});
CHECK(ap[2].p == P{3, 1});
CHECK(ap[3].p == P{3, 2});
CHECK(ap[4].p == P{0, 1});
CHECK(ap[5].p == P{0, 2});
CHECK(ap[6].p == P{2, 1});
CHECK(ap[7].p == P{2, 2});
CHECK(ap[8].p == P{4, 1});
CHECK(ap[9].p == P{4, 2});
}
// Test rvalue ranges
using P = std::pair<int, int>;
{ // check mixed
S ap[] = { {{0, 1}}, {{0, 2}}, {{1, 1}}, {{1, 2}}, {{2, 1}}, {{2, 2}}, {{3, 1}}, {{3, 2}}, {{4, 1}}, {{4, 2}} };
auto r = ranges::stable_partition(ranges::views::all(ap), odd_first(), &S::p);
CHECK(r == ap + 4);
CHECK(ap[0].p == P{1, 1});
CHECK(ap[1].p == P{1, 2});
CHECK(ap[2].p == P{3, 1});
CHECK(ap[3].p == P{3, 2});
CHECK(ap[4].p == P{0, 1});
CHECK(ap[5].p == P{0, 2});
CHECK(ap[6].p == P{2, 1});
CHECK(ap[7].p == P{2, 2});
CHECK(ap[8].p == P{4, 1});
CHECK(ap[9].p == P{4, 2});
}
{ // check mixed
S ap[] = { {{0, 1}}, {{0, 2}}, {{1, 1}}, {{1, 2}}, {{2, 1}}, {{2, 2}}, {{3, 1}}, {{3, 2}}, {{4, 1}}, {{4, 2}} };
auto r = ranges::stable_partition(std::move(ap), odd_first(), &S::p);
#ifndef RANGES_WORKAROUND_MSVC_573728
CHECK(::is_dangling(r));
#endif // RANGES_WORKAROUND_MSVC_573728
CHECK(ap[0].p == P{1, 1});
CHECK(ap[1].p == P{1, 2});
CHECK(ap[2].p == P{3, 1});
CHECK(ap[3].p == P{3, 2});
CHECK(ap[4].p == P{0, 1});
CHECK(ap[5].p == P{0, 2});
CHECK(ap[6].p == P{2, 1});
CHECK(ap[7].p == P{2, 2});
CHECK(ap[8].p == P{4, 1});
CHECK(ap[9].p == P{4, 2});
}
{ // check mixed
std::vector<S> ap{ {{0, 1}}, {{0, 2}}, {{1, 1}}, {{1, 2}}, {{2, 1}}, {{2, 2}}, {{3, 1}}, {{3, 2}}, {{4, 1}}, {{4, 2}} };
auto r = ranges::stable_partition(std::move(ap), odd_first(), &S::p);
CHECK(::is_dangling(r));
CHECK(ap[0].p == P{1, 1});
CHECK(ap[1].p == P{1, 2});
CHECK(ap[2].p == P{3, 1});
CHECK(ap[3].p == P{3, 2});
CHECK(ap[4].p == P{0, 1});
CHECK(ap[5].p == P{0, 2});
CHECK(ap[6].p == P{2, 1});
CHECK(ap[7].p == P{2, 2});
CHECK(ap[8].p == P{4, 1});
CHECK(ap[9].p == P{4, 2});
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/set_union5.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#define SET_UNION_5
#include "./set_union.hpp"
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/upper_bound.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright 2005 - 2007 Adobe Systems Incorporated
// Distributed under the MIT License(see accompanying file LICENSE_1_0_0.txt
// or a copy at http://stlab.adobe.com/licenses.html)
#include <utility>
#include <vector>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/upper_bound.hpp>
#include "../simple_test.hpp"
#include "../test_iterators.hpp"
struct my_int
{
int value;
};
bool compare(my_int lhs, my_int rhs)
{
return lhs.value < rhs.value;
}
void not_totally_ordered()
{
// This better compile!
std::vector<my_int> vec;
ranges::upper_bound(vec, my_int{10}, compare);
}
int main()
{
using ranges::begin;
using ranges::end;
using ranges::size;
using ranges::less;
using P = std::pair<int, int>;
constexpr P a[] = {{0, 0}, {0, 1}, {1, 2}, {1, 3}, {3, 4}, {3, 5}};
constexpr P const c[] = {{0, 0}, {0, 1}, {1, 2}, {1, 3}, {3, 4}, {3, 5}};
CHECK(ranges::aux::upper_bound_n(begin(a), size(a), a[0]) == &a[1]);
CHECK(ranges::aux::upper_bound_n(begin(a), size(a), a[1], less()) == &a[2]);
CHECK(ranges::aux::upper_bound_n(begin(a), size(a), 1, less(), &std::pair<int, int>::first) == &a[4]);
CHECK(ranges::upper_bound(begin(a), end(a), a[0]) == &a[1]);
CHECK(ranges::upper_bound(begin(a), end(a), a[1], less()) == &a[2]);
CHECK(ranges::upper_bound(begin(a), end(a), 1, less(), &std::pair<int, int>::first) == &a[4]);
CHECK(ranges::upper_bound(a, a[2]) == &a[3]);
CHECK(ranges::upper_bound(c, c[3]) == &c[4]);
CHECK(ranges::upper_bound(a, a[4], less()) == &a[5]);
CHECK(ranges::upper_bound(c, c[5], less()) == &c[6]);
CHECK(ranges::upper_bound(a, 1, less(), &std::pair<int, int>::first) == &a[4]);
CHECK(ranges::upper_bound(c, 1, less(), &std::pair<int, int>::first) == &c[4]);
std::vector<P> vec_a(ranges::begin(a), ranges::end(a));
std::vector<P> const vec_c(ranges::begin(c), ranges::end(c));
CHECK(ranges::upper_bound(ranges::views::all(a), a[2]) == &a[3]);
CHECK(ranges::upper_bound(ranges::views::all(c), c[3]) == &c[4]);
#ifndef RANGES_WORKAROUND_MSVC_573728
CHECK(::is_dangling(ranges::upper_bound(std::move(a), a[2])));
CHECK(::is_dangling(ranges::upper_bound(std::move(c), c[3])));
#endif // RANGES_WORKAROUND_MSVC_573728
CHECK(::is_dangling(ranges::upper_bound(std::move(vec_a), vec_a[2])));
CHECK(::is_dangling(ranges::upper_bound(std::move(vec_c), vec_c[3])));
CHECK(ranges::upper_bound(ranges::views::all(a), a[4], less()) == &a[5]);
CHECK(ranges::upper_bound(ranges::views::all(c), c[5], less()) == &c[6]);
#ifndef RANGES_WORKAROUND_MSVC_573728
CHECK(::is_dangling(ranges::upper_bound(std::move(a), a[4], less())));
CHECK(::is_dangling(ranges::upper_bound(std::move(c), c[5], less())));
#endif // RANGES_WORKAROUND_MSVC_573728
CHECK(::is_dangling(ranges::upper_bound(std::move(vec_a), vec_a[4], less())));
CHECK(::is_dangling(ranges::upper_bound(std::move(vec_c), vec_c[5], less())));
CHECK(ranges::upper_bound(ranges::views::all(a), 1, less(), &std::pair<int, int>::first) == &a[4]);
CHECK(ranges::upper_bound(ranges::views::all(c), 1, less(), &std::pair<int, int>::first) == &c[4]);
#ifndef RANGES_WORKAROUND_MSVC_573728
CHECK(::is_dangling(ranges::upper_bound(std::move(a), 1, less(), &std::pair<int, int>::first)));
CHECK(::is_dangling(ranges::upper_bound(std::move(c), 1, less(), &std::pair<int, int>::first)));
#endif // RANGES_WORKAROUND_MSVC_573728
CHECK(::is_dangling(ranges::upper_bound(std::move(vec_a), 1, less(), &std::pair<int, int>::first)));
CHECK(::is_dangling(ranges::upper_bound(std::move(vec_c), 1, less(), &std::pair<int, int>::first)));
{
using namespace ranges;
STATIC_CHECK(aux::upper_bound_n(begin(a), size(a), a[0]) == &a[1]);
STATIC_CHECK(aux::upper_bound_n(begin(a), size(a), a[1], less()) == &a[2]);
STATIC_CHECK(upper_bound(begin(a), end(a), a[0]) == &a[1]);
STATIC_CHECK(upper_bound(begin(a), end(a), a[1], less()) == &a[2]);
STATIC_CHECK(upper_bound(a, a[2]) == &a[3]);
STATIC_CHECK(upper_bound(a, a[3], less()) == &a[4]);
STATIC_CHECK(upper_bound(a, std::make_pair(1, 3), less()) == &a[4]);
#if RANGES_CXX_CONSTEXPR >= RANGES_CXX_CONSTEXPR_17
// requires constexpr std::addressof
STATIC_CHECK(upper_bound(views::all(a), std::make_pair(1, 3), less()) == &a[4]);
#endif
}
return test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/lower_bound.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright 2005 - 2007 Adobe Systems Incorporated
// Distributed under the MIT License(see accompanying file LICENSE_1_0_0.txt
// or a copy at http://stlab.adobe.com/licenses.html)
#include <utility>
#include <vector>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/lower_bound.hpp>
#include "../simple_test.hpp"
#include "../test_iterators.hpp"
#include "../test_utils.hpp"
struct my_int
{
int value;
};
bool compare(my_int lhs, my_int rhs)
{
return lhs.value < rhs.value;
}
void not_totally_ordered()
{
// This better compile!
std::vector<my_int> vec;
ranges::lower_bound(vec, my_int{10}, compare);
}
int main()
{
using ranges::begin;
using ranges::end;
using ranges::size;
using ranges::less;
constexpr std::pair<int, int> a[] = {{0, 0}, {0, 1}, {1, 2}, {1, 3}, {3, 4}, {3, 5}};
constexpr const std::pair<int, int> c[] = {
{0, 0}, {0, 1}, {1, 2}, {1, 3}, {3, 4}, {3, 5}};
CHECK(ranges::aux::lower_bound_n(begin(a), size(a), a[0]) == &a[0]);
CHECK(ranges::aux::lower_bound_n(begin(a), size(a), a[1], less()) == &a[1]);
CHECK(ranges::aux::lower_bound_n(begin(a), size(a), 1, less(), &std::pair<int, int>::first) == &a[2]);
CHECK(ranges::lower_bound(begin(a), end(a), a[0]) == &a[0]);
CHECK(ranges::lower_bound(begin(a), end(a), a[1], less()) == &a[1]);
CHECK(ranges::lower_bound(begin(a), end(a), 1, less(), &std::pair<int, int>::first) == &a[2]);
CHECK(ranges::lower_bound(a, a[2]) == &a[2]);
CHECK(ranges::lower_bound(c, c[3]) == &c[3]);
CHECK(ranges::lower_bound(a, a[4], less()) == &a[4]);
CHECK(ranges::lower_bound(c, c[5], less()) == &c[5]);
CHECK(ranges::lower_bound(a, 1, less(), &std::pair<int, int>::first) == &a[2]);
CHECK(ranges::lower_bound(c, 1, less(), &std::pair<int, int>::first) == &c[2]);
CHECK(ranges::lower_bound(ranges::views::all(a), 1, less(), &std::pair<int, int>::first) == &a[2]);
CHECK(ranges::lower_bound(ranges::views::all(c), 1, less(), &std::pair<int, int>::first) == &c[2]);
#ifndef RANGES_WORKAROUND_MSVC_573728
CHECK(::is_dangling(ranges::lower_bound(std::move(a), 1, less(), &std::pair<int, int>::first)));
CHECK(::is_dangling(ranges::lower_bound(std::move(c), 1, less(), &std::pair<int, int>::first)));
#endif // RANGES_WORKAROUND_MSVC_573728
{
std::vector<std::pair<int, int>> vec_a(ranges::begin(a), ranges::end(a));
CHECK(::is_dangling(ranges::lower_bound(std::move(vec_a), 1, less(), &std::pair<int, int>::first)));
}
{
std::vector<std::pair<int, int>> const vec_c(ranges::begin(c), ranges::end(c));
CHECK(::is_dangling(ranges::lower_bound(std::move(vec_c), 1, less(), &std::pair<int, int>::first)));
}
{
using namespace ranges;
STATIC_CHECK(aux::lower_bound_n(begin(a), size(a), a[0]) == &a[0]);
STATIC_CHECK(aux::lower_bound_n(begin(a), size(a), a[1], less()) == &a[1]);
STATIC_CHECK(lower_bound(begin(a), end(a), a[0]) == &a[0]);
STATIC_CHECK(lower_bound(begin(a), end(a), a[1], less()) == &a[1]);
STATIC_CHECK(lower_bound(a, a[2]) == &a[2]);
STATIC_CHECK(lower_bound(a, a[4], less()) == &a[4]);
STATIC_CHECK(lower_bound(a, std::make_pair(1, 2), less()) == &a[2]);
#if RANGES_CXX_CONSTEXPR >= RANGES_CXX_CONSTEXPR_17
// requires constexpr std::addressof
STATIC_CHECK(lower_bound(views::all(a), std::make_pair(1, 2), less()) == &a[2]);
#endif
}
return test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/copy_n.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#include <range/v3/algorithm/copy_n.hpp>
#include "../array.hpp"
#include "../simple_test.hpp"
constexpr bool test_constexpr()
{
using namespace ranges;
test::array<int, 4> a{{1, 2, 3, 4}};
test::array<int, 4> b{{0, 0, 0, 0}};
const auto res = copy_n(begin(a), 2, ranges::begin(b));
STATIC_CHECK_RETURN(res.first == begin(a) + 2);
STATIC_CHECK_RETURN(res.second == begin(b) + 2);
STATIC_CHECK_RETURN(a[0] == 1);
STATIC_CHECK_RETURN(a[1] == 2);
STATIC_CHECK_RETURN(a[2] == 3);
STATIC_CHECK_RETURN(a[3] == 4);
STATIC_CHECK_RETURN(b[0] == 1);
STATIC_CHECK_RETURN(b[1] == 2);
STATIC_CHECK_RETURN(b[2] == 0);
STATIC_CHECK_RETURN(b[3] == 0);
return true;
}
int main()
{
{
STATIC_CHECK(test_constexpr());
}
return test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/move.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <memory>
#include <algorithm>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/move.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
template<typename InIter, typename OutIter, typename Sent = InIter>
void
test()
{
{
const int N = 1000;
int ia[N];
for(int i = 0; i < N; ++i)
ia[i] = i;
int ib[N] = {0};
ranges::move_result<InIter, OutIter> r = ranges::move(InIter(ia), Sent(ia+N), OutIter(ib));
CHECK(base(r.in) == ia+N);
CHECK(base(r.out) == ib+N);
for(int i = 0; i < N; ++i)
CHECK(ia[i] == ib[i]);
}
{
const int N = 1000;
int ia[N];
for(int i = 0; i < N; ++i)
ia[i] = i;
int ib[N] = {0};
ranges::move_result<InIter, OutIter> r = ranges::move(as_lvalue(ranges::make_subrange(InIter(ia), Sent(ia+N))), OutIter(ib));
CHECK(base(r.in) == ia+N);
CHECK(base(r.out) == ib+N);
for(int i = 0; i < N; ++i)
CHECK(ia[i] == ib[i]);
}
}
template<typename InIter, typename OutIter, typename Sent = InIter>
constexpr bool test_constexpr()
{
{
constexpr int N = 1000;
int ia[N]{1};
for(int i = 0; i < N; ++i)
ia[i] = i;
int ib[N] = {0};
const auto r = ranges::move(InIter(ia), Sent(ia + N), OutIter(ib));
if(base(r.in) != ia + N)
{
return false;
}
if(base(r.out) != ib + N)
{
return false;
}
for(int i = 0; i < N; ++i)
if(ia[i] != ib[i])
{
return false;
}
}
{
constexpr int N = 1000;
int ia[N]{1};
for(int i = 0; i < N; ++i)
ia[i] = i;
int ib[N] = {0};
const auto r = ranges::move(
as_lvalue(ranges::make_subrange(InIter(ia), Sent(ia + N))), OutIter(ib));
if(base(r.in) != ia + N)
{
return false;
}
if(base(r.out) != ib + N)
{
return false;
}
for(int i = 0; i < N; ++i)
if(ia[i] != ib[i])
{
return false;
}
}
return true;
}
struct S
{
std::unique_ptr<int> p;
};
template<typename InIter, typename OutIter, typename Sent = InIter>
void
test1()
{
{
const int N = 100;
std::unique_ptr<int> ia[N];
for(int i = 0; i < N; ++i)
ia[i].reset(new int(i));
std::unique_ptr<int> ib[N];
ranges::move_result<InIter, OutIter> r = ranges::move(InIter(ia), Sent(ia+N), OutIter(ib));
CHECK(base(r.in) == ia+N);
CHECK(base(r.out) == ib+N);
for(int i = 0; i < N; ++i)
{
CHECK(ia[i].get() == nullptr);
CHECK(*ib[i] == i);
}
}
{
const int N = 100;
std::unique_ptr<int> ia[N];
for(int i = 0; i < N; ++i)
ia[i].reset(new int(i));
std::unique_ptr<int> ib[N];
ranges::move_result<InIter, OutIter> r = ranges::move(as_lvalue(ranges::make_subrange(InIter(ia), Sent(ia+N))), OutIter(ib));
CHECK(base(r.in) == ia+N);
CHECK(base(r.out) == ib+N);
for(int i = 0; i < N; ++i)
{
CHECK(ia[i].get() == nullptr);
CHECK(*ib[i] == i);
}
ranges::move(ib, ib+N, ia);
auto r2 = ranges::move(ranges::make_subrange(InIter(ia), Sent(ia+N)), OutIter(ib));
CHECK(base(r2.in) == ia+N);
CHECK(base(r2.out) == ib+N);
for(int i = 0; i < N; ++i)
{
CHECK(ia[i].get() == nullptr);
CHECK(*ib[i] == i);
}
}
}
int main()
{
test<InputIterator<const int*>, OutputIterator<int*> >();
test<InputIterator<const int*>, InputIterator<int*> >();
test<InputIterator<const int*>, ForwardIterator<int*> >();
test<InputIterator<const int*>, BidirectionalIterator<int*> >();
test<InputIterator<const int*>, RandomAccessIterator<int*> >();
test<InputIterator<const int*>, int*>();
test<ForwardIterator<const int*>, OutputIterator<int*> >();
test<ForwardIterator<const int*>, InputIterator<int*> >();
test<ForwardIterator<const int*>, ForwardIterator<int*> >();
test<ForwardIterator<const int*>, BidirectionalIterator<int*> >();
test<ForwardIterator<const int*>, RandomAccessIterator<int*> >();
test<ForwardIterator<const int*>, int*>();
test<BidirectionalIterator<const int*>, OutputIterator<int*> >();
test<BidirectionalIterator<const int*>, InputIterator<int*> >();
test<BidirectionalIterator<const int*>, ForwardIterator<int*> >();
test<BidirectionalIterator<const int*>, BidirectionalIterator<int*> >();
test<BidirectionalIterator<const int*>, RandomAccessIterator<int*> >();
test<BidirectionalIterator<const int*>, int*>();
test<RandomAccessIterator<const int*>, OutputIterator<int*> >();
test<RandomAccessIterator<const int*>, InputIterator<int*> >();
test<RandomAccessIterator<const int*>, ForwardIterator<int*> >();
test<RandomAccessIterator<const int*>, BidirectionalIterator<int*> >();
test<RandomAccessIterator<const int*>, RandomAccessIterator<int*> >();
test<RandomAccessIterator<const int*>, int*>();
test<const int*, OutputIterator<int*> >();
test<const int*, InputIterator<int*> >();
test<const int*, ForwardIterator<int*> >();
test<const int*, BidirectionalIterator<int*> >();
test<const int*, RandomAccessIterator<int*> >();
test<const int*, int*>();
test<InputIterator<const int*>, OutputIterator<int*>, Sentinel<const int*>>();
test<InputIterator<const int*>, InputIterator<int*>, Sentinel<const int*> >();
test<InputIterator<const int*>, ForwardIterator<int*>, Sentinel<const int*> >();
test<InputIterator<const int*>, BidirectionalIterator<int*>, Sentinel<const int*> >();
test<InputIterator<const int*>, RandomAccessIterator<int*>, Sentinel<const int*> >();
test<ForwardIterator<const int*>, OutputIterator<int*>, Sentinel<const int*> >();
test<ForwardIterator<const int*>, InputIterator<int*>, Sentinel<const int*> >();
test<ForwardIterator<const int*>, ForwardIterator<int*>, Sentinel<const int*> >();
test<ForwardIterator<const int*>, BidirectionalIterator<int*>, Sentinel<const int*> >();
test<ForwardIterator<const int*>, RandomAccessIterator<int*>, Sentinel<const int*> >();
test<BidirectionalIterator<const int*>, OutputIterator<int*>, Sentinel<const int*> >();
test<BidirectionalIterator<const int*>, InputIterator<int*>, Sentinel<const int*> >();
test<BidirectionalIterator<const int*>, ForwardIterator<int*>, Sentinel<const int*> >();
test<BidirectionalIterator<const int*>, BidirectionalIterator<int*>, Sentinel<const int*> >();
test<BidirectionalIterator<const int*>, RandomAccessIterator<int*>, Sentinel<const int*> >();
test<RandomAccessIterator<const int*>, OutputIterator<int*>, Sentinel<const int*> >();
test<RandomAccessIterator<const int*>, InputIterator<int*>, Sentinel<const int*> >();
test<RandomAccessIterator<const int*>, ForwardIterator<int*>, Sentinel<const int*> >();
test<RandomAccessIterator<const int*>, BidirectionalIterator<int*>, Sentinel<const int*> >();
test<RandomAccessIterator<const int*>, RandomAccessIterator<int*>, Sentinel<const int*> >();
test1<InputIterator<std::unique_ptr<int>*>, OutputIterator<std::unique_ptr<int>*> >();
test1<InputIterator<std::unique_ptr<int>*>, InputIterator<std::unique_ptr<int>*> >();
test1<InputIterator<std::unique_ptr<int>*>, ForwardIterator<std::unique_ptr<int>*> >();
test1<InputIterator<std::unique_ptr<int>*>, BidirectionalIterator<std::unique_ptr<int>*> >();
test1<InputIterator<std::unique_ptr<int>*>, RandomAccessIterator<std::unique_ptr<int>*> >();
test1<InputIterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
test1<ForwardIterator<std::unique_ptr<int>*>, OutputIterator<std::unique_ptr<int>*> >();
test1<ForwardIterator<std::unique_ptr<int>*>, InputIterator<std::unique_ptr<int>*> >();
test1<ForwardIterator<std::unique_ptr<int>*>, ForwardIterator<std::unique_ptr<int>*> >();
test1<ForwardIterator<std::unique_ptr<int>*>, BidirectionalIterator<std::unique_ptr<int>*> >();
test1<ForwardIterator<std::unique_ptr<int>*>, RandomAccessIterator<std::unique_ptr<int>*> >();
test1<ForwardIterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
test1<BidirectionalIterator<std::unique_ptr<int>*>, OutputIterator<std::unique_ptr<int>*> >();
test1<BidirectionalIterator<std::unique_ptr<int>*>, InputIterator<std::unique_ptr<int>*> >();
test1<BidirectionalIterator<std::unique_ptr<int>*>, ForwardIterator<std::unique_ptr<int>*> >();
test1<BidirectionalIterator<std::unique_ptr<int>*>, BidirectionalIterator<std::unique_ptr<int>*> >();
test1<BidirectionalIterator<std::unique_ptr<int>*>, RandomAccessIterator<std::unique_ptr<int>*> >();
test1<BidirectionalIterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
test1<RandomAccessIterator<std::unique_ptr<int>*>, OutputIterator<std::unique_ptr<int>*> >();
test1<RandomAccessIterator<std::unique_ptr<int>*>, InputIterator<std::unique_ptr<int>*> >();
test1<RandomAccessIterator<std::unique_ptr<int>*>, ForwardIterator<std::unique_ptr<int>*> >();
test1<RandomAccessIterator<std::unique_ptr<int>*>, BidirectionalIterator<std::unique_ptr<int>*> >();
test1<RandomAccessIterator<std::unique_ptr<int>*>, RandomAccessIterator<std::unique_ptr<int>*> >();
test1<RandomAccessIterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
test1<std::unique_ptr<int>*, OutputIterator<std::unique_ptr<int>*> >();
test1<std::unique_ptr<int>*, InputIterator<std::unique_ptr<int>*> >();
test1<std::unique_ptr<int>*, ForwardIterator<std::unique_ptr<int>*> >();
test1<std::unique_ptr<int>*, BidirectionalIterator<std::unique_ptr<int>*> >();
test1<std::unique_ptr<int>*, RandomAccessIterator<std::unique_ptr<int>*> >();
test1<std::unique_ptr<int>*, std::unique_ptr<int>*>();
test1<InputIterator<std::unique_ptr<int>*>, OutputIterator<std::unique_ptr<int>*>, Sentinel<std::unique_ptr<int>*> >();
test1<InputIterator<std::unique_ptr<int>*>, InputIterator<std::unique_ptr<int>*>, Sentinel<std::unique_ptr<int>*> >();
test1<InputIterator<std::unique_ptr<int>*>, ForwardIterator<std::unique_ptr<int>*>, Sentinel<std::unique_ptr<int>*> >();
test1<InputIterator<std::unique_ptr<int>*>, BidirectionalIterator<std::unique_ptr<int>*>, Sentinel<std::unique_ptr<int>*> >();
test1<InputIterator<std::unique_ptr<int>*>, RandomAccessIterator<std::unique_ptr<int>*>, Sentinel<std::unique_ptr<int>*> >();
test1<InputIterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
test1<ForwardIterator<std::unique_ptr<int>*>, OutputIterator<std::unique_ptr<int>*>, Sentinel<std::unique_ptr<int>*> >();
test1<ForwardIterator<std::unique_ptr<int>*>, InputIterator<std::unique_ptr<int>*>, Sentinel<std::unique_ptr<int>*> >();
test1<ForwardIterator<std::unique_ptr<int>*>, ForwardIterator<std::unique_ptr<int>*>, Sentinel<std::unique_ptr<int>*> >();
test1<ForwardIterator<std::unique_ptr<int>*>, BidirectionalIterator<std::unique_ptr<int>*>, Sentinel<std::unique_ptr<int>*> >();
test1<ForwardIterator<std::unique_ptr<int>*>, RandomAccessIterator<std::unique_ptr<int>*>, Sentinel<std::unique_ptr<int>*> >();
test1<ForwardIterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
test1<BidirectionalIterator<std::unique_ptr<int>*>, OutputIterator<std::unique_ptr<int>*>, Sentinel<std::unique_ptr<int>*> >();
test1<BidirectionalIterator<std::unique_ptr<int>*>, InputIterator<std::unique_ptr<int>*>, Sentinel<std::unique_ptr<int>*> >();
test1<BidirectionalIterator<std::unique_ptr<int>*>, ForwardIterator<std::unique_ptr<int>*>, Sentinel<std::unique_ptr<int>*> >();
test1<BidirectionalIterator<std::unique_ptr<int>*>, BidirectionalIterator<std::unique_ptr<int>*>, Sentinel<std::unique_ptr<int>*> >();
test1<BidirectionalIterator<std::unique_ptr<int>*>, RandomAccessIterator<std::unique_ptr<int>*>, Sentinel<std::unique_ptr<int>*> >();
test1<BidirectionalIterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
test1<RandomAccessIterator<std::unique_ptr<int>*>, OutputIterator<std::unique_ptr<int>*>, Sentinel<std::unique_ptr<int>*> >();
test1<RandomAccessIterator<std::unique_ptr<int>*>, InputIterator<std::unique_ptr<int>*>, Sentinel<std::unique_ptr<int>*> >();
test1<RandomAccessIterator<std::unique_ptr<int>*>, ForwardIterator<std::unique_ptr<int>*>, Sentinel<std::unique_ptr<int>*> >();
test1<RandomAccessIterator<std::unique_ptr<int>*>, BidirectionalIterator<std::unique_ptr<int>*>, Sentinel<std::unique_ptr<int>*> >();
test1<RandomAccessIterator<std::unique_ptr<int>*>, RandomAccessIterator<std::unique_ptr<int>*>, Sentinel<std::unique_ptr<int>*> >();
{
STATIC_CHECK(test_constexpr<InputIterator<const int *>, OutputIterator<int *>>());
STATIC_CHECK(test_constexpr<InputIterator<const int *>, InputIterator<int *>>());
STATIC_CHECK(
test_constexpr<InputIterator<const int *>, ForwardIterator<int *>>());
STATIC_CHECK(
test_constexpr<InputIterator<const int *>, BidirectionalIterator<int *>>());
STATIC_CHECK(
test_constexpr<InputIterator<const int *>, RandomAccessIterator<int *>>());
STATIC_CHECK(test_constexpr<InputIterator<const int *>, int *>());
STATIC_CHECK(
test_constexpr<ForwardIterator<const int *>, OutputIterator<int *>>());
STATIC_CHECK(
test_constexpr<ForwardIterator<const int *>, InputIterator<int *>>());
STATIC_CHECK(
test_constexpr<ForwardIterator<const int *>, ForwardIterator<int *>>());
STATIC_CHECK(
test_constexpr<ForwardIterator<const int *>, BidirectionalIterator<int *>>());
STATIC_CHECK(
test_constexpr<ForwardIterator<const int *>, RandomAccessIterator<int *>>());
STATIC_CHECK(test_constexpr<ForwardIterator<const int *>, int *>());
STATIC_CHECK(
test_constexpr<BidirectionalIterator<const int *>, OutputIterator<int *>>());
STATIC_CHECK(
test_constexpr<BidirectionalIterator<const int *>, InputIterator<int *>>());
STATIC_CHECK(
test_constexpr<BidirectionalIterator<const int *>, ForwardIterator<int *>>());
STATIC_CHECK(test_constexpr<BidirectionalIterator<const int *>,
BidirectionalIterator<int *>>());
STATIC_CHECK(test_constexpr<BidirectionalIterator<const int *>,
RandomAccessIterator<int *>>());
STATIC_CHECK(test_constexpr<BidirectionalIterator<const int *>, int *>());
STATIC_CHECK(
test_constexpr<RandomAccessIterator<const int *>, OutputIterator<int *>>());
STATIC_CHECK(
test_constexpr<RandomAccessIterator<const int *>, InputIterator<int *>>());
STATIC_CHECK(
test_constexpr<RandomAccessIterator<const int *>, ForwardIterator<int *>>());
STATIC_CHECK(test_constexpr<RandomAccessIterator<const int *>,
BidirectionalIterator<int *>>());
STATIC_CHECK(test_constexpr<RandomAccessIterator<const int *>,
RandomAccessIterator<int *>>());
STATIC_CHECK(test_constexpr<RandomAccessIterator<const int *>, int *>());
STATIC_CHECK(test_constexpr<const int *, OutputIterator<int *>>());
STATIC_CHECK(test_constexpr<const int *, InputIterator<int *>>());
STATIC_CHECK(test_constexpr<const int *, ForwardIterator<int *>>());
STATIC_CHECK(test_constexpr<const int *, BidirectionalIterator<int *>>());
STATIC_CHECK(test_constexpr<const int *, RandomAccessIterator<int *>>());
STATIC_CHECK(test_constexpr<const int *, int *>());
STATIC_CHECK(test_constexpr<InputIterator<const int *>,
OutputIterator<int *>,
Sentinel<const int *>>());
STATIC_CHECK(test_constexpr<InputIterator<const int *>,
InputIterator<int *>,
Sentinel<const int *>>());
STATIC_CHECK(test_constexpr<InputIterator<const int *>,
ForwardIterator<int *>,
Sentinel<const int *>>());
STATIC_CHECK(test_constexpr<InputIterator<const int *>,
BidirectionalIterator<int *>,
Sentinel<const int *>>());
STATIC_CHECK(test_constexpr<InputIterator<const int *>,
RandomAccessIterator<int *>,
Sentinel<const int *>>());
STATIC_CHECK(test_constexpr<ForwardIterator<const int *>,
OutputIterator<int *>,
Sentinel<const int *>>());
STATIC_CHECK(test_constexpr<ForwardIterator<const int *>,
InputIterator<int *>,
Sentinel<const int *>>());
STATIC_CHECK(test_constexpr<ForwardIterator<const int *>,
ForwardIterator<int *>,
Sentinel<const int *>>());
STATIC_CHECK(test_constexpr<ForwardIterator<const int *>,
BidirectionalIterator<int *>,
Sentinel<const int *>>());
STATIC_CHECK(test_constexpr<ForwardIterator<const int *>,
RandomAccessIterator<int *>,
Sentinel<const int *>>());
STATIC_CHECK(test_constexpr<BidirectionalIterator<const int *>,
OutputIterator<int *>,
Sentinel<const int *>>());
STATIC_CHECK(test_constexpr<BidirectionalIterator<const int *>,
InputIterator<int *>,
Sentinel<const int *>>());
STATIC_CHECK(test_constexpr<BidirectionalIterator<const int *>,
ForwardIterator<int *>,
Sentinel<const int *>>());
STATIC_CHECK(test_constexpr<BidirectionalIterator<const int *>,
BidirectionalIterator<int *>,
Sentinel<const int *>>());
STATIC_CHECK(test_constexpr<BidirectionalIterator<const int *>,
RandomAccessIterator<int *>,
Sentinel<const int *>>());
STATIC_CHECK(test_constexpr<RandomAccessIterator<const int *>,
OutputIterator<int *>,
Sentinel<const int *>>());
STATIC_CHECK(test_constexpr<RandomAccessIterator<const int *>,
InputIterator<int *>,
Sentinel<const int *>>());
STATIC_CHECK(test_constexpr<RandomAccessIterator<const int *>,
ForwardIterator<int *>,
Sentinel<const int *>>());
STATIC_CHECK(test_constexpr<RandomAccessIterator<const int *>,
BidirectionalIterator<int *>,
Sentinel<const int *>>());
STATIC_CHECK(test_constexpr<RandomAccessIterator<const int *>,
RandomAccessIterator<int *>,
Sentinel<const int *>>());
}
return test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/is_heap3.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#define IS_HEAP_3
#include "./is_heap.hpp"
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/partition_move.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright 2005 - 2007 Adobe Systems Incorporated
// Distributed under the MIT License(see accompanying file LICENSE_1_0_0.txt
// or a copy at http://stlab.adobe.com/licenses.html)
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <tuple>
#include <range/v3/algorithm/partition_move.hpp>
#include <range/v3/core.hpp>
#include "../simple_test.hpp"
struct is_odd
{
constexpr bool operator()(const int & i) const
{
return i & 1;
}
};
constexpr bool test_constexpr()
{
using namespace ranges;
const int ia[] = {1, 2, 3, 4, 6, 8, 5, 7};
int r1[10] = {0};
int r2[10] = {0};
typedef std::tuple<int const *, int *, int *> P;
P p = partition_move(ia, r1, r2, is_odd());
STATIC_CHECK_RETURN(std::get<0>(p) == std::end(ia));
STATIC_CHECK_RETURN(std::get<1>(p) == r1 + 4);
STATIC_CHECK_RETURN(r1[0] == 1);
STATIC_CHECK_RETURN(r1[1] == 3);
STATIC_CHECK_RETURN(r1[2] == 5);
STATIC_CHECK_RETURN(r1[3] == 7);
STATIC_CHECK_RETURN(std::get<2>(p) == r2 + 4);
STATIC_CHECK_RETURN(r2[0] == 2);
STATIC_CHECK_RETURN(r2[1] == 4);
STATIC_CHECK_RETURN(r2[2] == 6);
STATIC_CHECK_RETURN(r2[3] == 8);
return true;
}
int main()
{
{
STATIC_CHECK(test_constexpr());
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/is_heap_until3.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#define IS_HEAP_UNTIL_3
#include "./is_heap_until.hpp"
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/swap_ranges.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <array>
#include <memory>
#include <algorithm>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/swap_ranges.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
template<class Iter1, class Iter2>
void test_iter_3()
{
int i[3] = {1, 2, 3};
int j[3] = {4, 5, 6};
ranges::swap_ranges_result<Iter1, Iter2> r =
ranges::swap_ranges(Iter1(i), Iter1(i+3), Iter2(j));
CHECK(base(r.in1) == i+3);
CHECK(base(r.in2) == j+3);
CHECK(i[0] == 4);
CHECK(i[1] == 5);
CHECK(i[2] == 6);
CHECK(j[0] == 1);
CHECK(j[1] == 2);
CHECK(j[2] == 3);
using Sent1 = typename sentinel_type<Iter1>::type;
r = ranges::swap_ranges(Iter1(j), Sent1(j+3), Iter2(i));
CHECK(base(r.in1) == j+3);
CHECK(base(r.in2) == i+3);
CHECK(i[0] == 1);
CHECK(i[1] == 2);
CHECK(i[2] == 3);
CHECK(j[0] == 4);
CHECK(j[1] == 5);
CHECK(j[2] == 6);
}
template<class Iter1, class Iter2>
void test_iter_4()
{
int i[3] = {1, 2, 3};
int j[4] = {4, 5, 6, 7};
ranges::swap_ranges_result<Iter1, Iter2> r =
ranges::swap_ranges(Iter1(i), Iter1(i+3), Iter2(j), Iter2(j+4));
CHECK(base(r.in1) == i+3);
CHECK(base(r.in2) == j+3);
CHECK(i[0] == 4);
CHECK(i[1] == 5);
CHECK(i[2] == 6);
CHECK(j[0] == 1);
CHECK(j[1] == 2);
CHECK(j[2] == 3);
CHECK(j[3] == 7);
using Sent1 = typename sentinel_type<Iter1>::type;
using Sent2 = typename sentinel_type<Iter2>::type;
r = ranges::swap_ranges(Iter1(j), Sent1(j+4), Iter2(i), Sent2(i+3));
CHECK(base(r.in1) == j+3);
CHECK(base(r.in2) == i+3);
CHECK(i[0] == 1);
CHECK(i[1] == 2);
CHECK(i[2] == 3);
CHECK(j[0] == 4);
CHECK(j[1] == 5);
CHECK(j[2] == 6);
CHECK(j[3] == 7);
}
template<class Iter1, class Iter2>
void test_rng_3()
{
int i[3] = {1, 2, 3};
int j[3] = {4, 5, 6};
ranges::swap_ranges_result<Iter1, Iter2> r =
ranges::swap_ranges(as_lvalue(ranges::make_subrange(Iter1(i), Iter1(i+3))), Iter2(j));
CHECK(base(r.in1) == i+3);
CHECK(base(r.in2) == j+3);
CHECK(i[0] == 4);
CHECK(i[1] == 5);
CHECK(i[2] == 6);
CHECK(j[0] == 1);
CHECK(j[1] == 2);
CHECK(j[2] == 3);
using Sent1 = typename sentinel_type<Iter1>::type;
r = ranges::swap_ranges(as_lvalue(ranges::make_subrange(Iter1(j), Sent1(j+3))), Iter2(i));
CHECK(base(r.in1) == j+3);
CHECK(base(r.in2) == i+3);
CHECK(i[0] == 1);
CHECK(i[1] == 2);
CHECK(i[2] == 3);
CHECK(j[0] == 4);
CHECK(j[1] == 5);
CHECK(j[2] == 6);
}
template<class Iter1, class Iter2>
void test_rng_4()
{
int i[3] = {1, 2, 3};
int j[4] = {4, 5, 6, 7};
ranges::swap_ranges_result<Iter1, Iter2> r = ranges::swap_ranges(
as_lvalue(ranges::make_subrange(Iter1(i), Iter1(i+3))),
as_lvalue(ranges::make_subrange(Iter2(j), Iter2(j+4))));
CHECK(base(r.in1) == i+3);
CHECK(base(r.in2) == j+3);
CHECK(i[0] == 4);
CHECK(i[1] == 5);
CHECK(i[2] == 6);
CHECK(j[0] == 1);
CHECK(j[1] == 2);
CHECK(j[2] == 3);
CHECK(j[3] == 7);
using Sent1 = typename sentinel_type<Iter1>::type;
using Sent2 = typename sentinel_type<Iter2>::type;
r = ranges::swap_ranges(
as_lvalue(ranges::make_subrange(Iter1(j), Sent1(j+4))),
as_lvalue(ranges::make_subrange(Iter2(i), Sent2(i+3))));
CHECK(base(r.in1) == j+3);
CHECK(base(r.in2) == i+3);
CHECK(i[0] == 1);
CHECK(i[1] == 2);
CHECK(i[2] == 3);
CHECK(j[0] == 4);
CHECK(j[1] == 5);
CHECK(j[2] == 6);
CHECK(j[3] == 7);
auto r2 = ranges::swap_ranges(
ranges::make_subrange(Iter1(j), Sent1(j+4)),
ranges::make_subrange(Iter2(i), Sent2(i+3)));
CHECK(base(r2.in1) == j+3);
CHECK(base(r2.in2) == i+3);
CHECK(i[0] == 4);
CHECK(i[1] == 5);
CHECK(i[2] == 6);
CHECK(j[0] == 1);
CHECK(j[1] == 2);
CHECK(j[2] == 3);
CHECK(j[3] == 7);
}
template<class Iter1, class Iter2>
void test_move_only()
{
std::unique_ptr<int> i[3];
for (int k = 0; k < 3; ++k)
i[k].reset(new int(k+1));
std::unique_ptr<int> j[3];
for (int k = 0; k < 3; ++k)
j[k].reset(new int(k+4));
ranges::swap_ranges_result<Iter1, Iter2> r =
ranges::swap_ranges(Iter1(i), Iter1(i+3), Iter2(j));
CHECK(base(r.in1) == i+3);
CHECK(base(r.in2) == j+3);
CHECK(*i[0] == 4);
CHECK(*i[1] == 5);
CHECK(*i[2] == 6);
CHECK(*j[0] == 1);
CHECK(*j[1] == 2);
CHECK(*j[2] == 3);
}
template<class Iter1, class Iter2>
void test()
{
test_iter_3<Iter1, Iter2>();
test_iter_4<Iter1, Iter2>();
test_rng_3<Iter1, Iter2>();
test_rng_4<Iter1, Iter2>();
}
constexpr bool test_constexpr()
{
using namespace ranges;
int i[3] = {1, 2, 3};
int j[3] = {4, 5, 6};
const auto r = ranges::swap_ranges(i, j);
STATIC_CHECK_RETURN(r.in1 == i + 3);
STATIC_CHECK_RETURN(r.in2 == j + 3);
STATIC_CHECK_RETURN(i[0] == 4);
STATIC_CHECK_RETURN(i[1] == 5);
STATIC_CHECK_RETURN(i[2] == 6);
STATIC_CHECK_RETURN(j[0] == 1);
STATIC_CHECK_RETURN(j[1] == 2);
STATIC_CHECK_RETURN(j[2] == 3);
return true;
}
int main()
{
test<ForwardIterator<int*>, ForwardIterator<int*> >();
test<ForwardIterator<int*>, BidirectionalIterator<int*> >();
test<ForwardIterator<int*>, RandomAccessIterator<int*> >();
test<ForwardIterator<int*>, int*>();
test<BidirectionalIterator<int*>, ForwardIterator<int*> >();
test<BidirectionalIterator<int*>, BidirectionalIterator<int*> >();
test<BidirectionalIterator<int*>, RandomAccessIterator<int*> >();
test<BidirectionalIterator<int*>, int*>();
test<RandomAccessIterator<int*>, ForwardIterator<int*> >();
test<RandomAccessIterator<int*>, BidirectionalIterator<int*> >();
test<RandomAccessIterator<int*>, RandomAccessIterator<int*> >();
test<RandomAccessIterator<int*>, int*>();
test<int*, ForwardIterator<int*> >();
test<int*, BidirectionalIterator<int*> >();
test<int*, RandomAccessIterator<int*> >();
test<int*, int*>();
test_move_only<ForwardIterator<std::unique_ptr<int>*>, ForwardIterator<std::unique_ptr<int>*> >();
test_move_only<ForwardIterator<std::unique_ptr<int>*>, BidirectionalIterator<std::unique_ptr<int>*> >();
test_move_only<ForwardIterator<std::unique_ptr<int>*>, RandomAccessIterator<std::unique_ptr<int>*> >();
test_move_only<ForwardIterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
test_move_only<BidirectionalIterator<std::unique_ptr<int>*>, ForwardIterator<std::unique_ptr<int>*> >();
test_move_only<BidirectionalIterator<std::unique_ptr<int>*>, BidirectionalIterator<std::unique_ptr<int>*> >();
test_move_only<BidirectionalIterator<std::unique_ptr<int>*>, RandomAccessIterator<std::unique_ptr<int>*> >();
test_move_only<BidirectionalIterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
test_move_only<RandomAccessIterator<std::unique_ptr<int>*>, ForwardIterator<std::unique_ptr<int>*> >();
test_move_only<RandomAccessIterator<std::unique_ptr<int>*>, BidirectionalIterator<std::unique_ptr<int>*> >();
test_move_only<RandomAccessIterator<std::unique_ptr<int>*>, RandomAccessIterator<std::unique_ptr<int>*> >();
test_move_only<RandomAccessIterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
test_move_only<std::unique_ptr<int>*, ForwardIterator<std::unique_ptr<int>*> >();
test_move_only<std::unique_ptr<int>*, BidirectionalIterator<std::unique_ptr<int>*> >();
test_move_only<std::unique_ptr<int>*, RandomAccessIterator<std::unique_ptr<int>*> >();
test_move_only<std::unique_ptr<int>*, std::unique_ptr<int>*>();
{
int a[4] = {1, 2, 3, 4};
int b[4] = {5, 6, 7, 8};
ranges::swap_ranges(a, a + 4, b);
::check_equal(a, {5, 6, 7, 8});
::check_equal(b, {1, 2, 3, 4});
ranges::swap_ranges(std::array<int, 2>{{3,4}}, a+2);
::check_equal(a, {5, 6, 3, 4});
}
{
STATIC_CHECK(test_constexpr());
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/set_intersection1.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#define SET_INTERSECTION_1
#include "./set_intersection.hpp"
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/all_of.cpp | // Range v3 library
//
// Copyright Andrew Sutton 2014
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#include <vector>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/all_of.hpp>
#include "../simple_test.hpp"
constexpr bool even(int n)
{
return n % 2 == 0;
}
struct S {
S(bool p) : test(p) { }
bool p() const { return test; }
bool test;
};
constexpr bool test_constexpr(std::initializer_list<int> il)
{
return ranges::all_of(il, even);
}
int main()
{
std::vector<int> all_even { 0, 2, 4, 6 };
std::vector<int> one_even { 1, 3, 4, 7 };
std::vector<int> none_even { 1, 3, 5, 7 };
CHECK(ranges::all_of(all_even.begin(), all_even.end(), even));
CHECK(!ranges::all_of(one_even.begin(), one_even.end(), even));
CHECK(!ranges::all_of(none_even.begin(), none_even.end(), even));
CHECK(ranges::all_of(all_even, even));
CHECK(!ranges::all_of(one_even, even));
CHECK(!ranges::all_of(none_even, even));
using ILI = std::initializer_list<int>;
CHECK(ranges::all_of(ILI{0, 2, 4, 6}, [](int n) { return n % 2 == 0; }));
CHECK(!ranges::all_of(ILI{1, 3, 4, 7}, [](int n) { return n % 2 == 0; }));
CHECK(!ranges::all_of(ILI{1, 3, 5, 7}, [](int n) { return n % 2 == 0; }));
std::vector<S> all_true { true, true, true };
std::vector<S> one_true { false, false, true };
std::vector<S> none_true { false, false, false };
CHECK(ranges::all_of(all_true.begin(), all_true.end(), &S::p));
CHECK(!ranges::all_of(one_true.begin(), one_true.end(), &S::p));
CHECK(!ranges::all_of(none_true.begin(), none_true.end(), &S::p));
CHECK(ranges::all_of(all_true, &S::p));
CHECK(!ranges::all_of(one_true, &S::p));
CHECK(!ranges::all_of(none_true, &S::p));
using ILS = std::initializer_list<S>;
CHECK(ranges::all_of(ILS{S(true), S(true), S(true)}, &S::p));
CHECK(!ranges::all_of(ILS{S(false), S(true), S(false)}, &S::p));
CHECK(!ranges::all_of(ILS{S(false), S(false), S(false)}, &S::p));
STATIC_CHECK(test_constexpr({0, 2, 4, 6}));
STATIC_CHECK(!test_constexpr({0, 2, 4, 5}));
STATIC_CHECK(!test_constexpr({1, 3, 4, 7}));
STATIC_CHECK(!test_constexpr({1, 3, 5, 7}));
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/set_intersection5.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#define SET_INTERSECTION_5
#include "./set_intersection.hpp"
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/adjacent_find.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#include <range/v3/core.hpp>
#include <range/v3/algorithm/adjacent_find.hpp>
#include "../array.hpp"
#include "../simple_test.hpp"
int main()
{
int v1[] = { 0, 2, 2, 4, 6 };
CHECK(ranges::adjacent_find(ranges::begin(v1), ranges::end(v1)) == &v1[1]);
CHECK(ranges::adjacent_find(v1) == &v1[1]);
std::pair<int, int> v2[] = {{0, 0}, {0, 2}, {0, 2}, {0, 4}, {0, 6}};
CHECK(ranges::adjacent_find(ranges::begin(v2), ranges::end(v2),
ranges::equal_to{}, &std::pair<int, int>::second) == &v2[1]);
CHECK(ranges::adjacent_find(v2, ranges::equal_to{}, &std::pair<int, int>::second) == &v2[1]);
static_assert(std::is_same<std::pair<int,int>*,
decltype(ranges::adjacent_find(v2, ranges::equal_to{},
&std::pair<int, int>::second))>::value, "");
{
using namespace ranges;
constexpr auto a1 = test::array<int, 5>{{0, 2, 2, 4, 6}};
STATIC_CHECK(adjacent_find(begin(a1), end(a1)) == (begin(a1) + 1));
STATIC_CHECK(adjacent_find(a1) == (begin(a1) + 1));
constexpr std::pair<int, int> a2[] = {{0, 0}, {0, 2}, {0, 2}, {0, 4}, {0, 6}};
STATIC_CHECK(adjacent_find(a2, ranges::equal_to{}) == (begin(a2) + 1));
}
return test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/minmax.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
// Copyright Casey Carter 2015
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <range/v3/algorithm/minmax.hpp>
#include <range/v3/view/subrange.hpp>
#include <memory>
#include <numeric>
#include <random>
#include <algorithm>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
RANGES_DIAGNOSTIC_IGNORE_GLOBAL_CONSTRUCTORS
namespace
{
std::mt19937 gen;
template<class Iter, class Sent = Iter>
void
test_iter(Iter first, Sent last)
{
RANGES_ENSURE(first != last);
auto rng = ranges::make_subrange(first, last);
auto res = ranges::minmax(rng);
for (Iter i = first; i != last; ++i) {
CHECK(!(*i < res.min));
CHECK(!(res.max < *i));
}
}
template<class Iter, class Sent = Iter>
void
test_iter(unsigned N)
{
RANGES_ENSURE(N > 0);
std::unique_ptr<int[]> a{new int[N]};
std::iota(a.get(), a.get()+N, 0);
std::shuffle(a.get(), a.get()+N, gen);
test_iter(Iter(a.get()), Sent(a.get()+N));
}
template<class Iter, class Sent = Iter>
void
test_iter()
{
test_iter<Iter, Sent>(1);
test_iter<Iter, Sent>(2);
test_iter<Iter, Sent>(3);
test_iter<Iter, Sent>(10);
test_iter<Iter, Sent>(1000);
}
template<class Iter, class Sent = Iter>
void
test_iter_comp(Iter first, Sent last)
{
RANGES_ENSURE(first != last);
typedef std::greater<int> Compare;
Compare comp;
auto rng = ranges::make_subrange(first, last);
auto res = ranges::minmax(rng, comp);
for (Iter i = first; i != last; ++i) {
CHECK(!comp(*i, res.min));
CHECK(!comp(res.max, *i));
}
}
template<class Iter, class Sent = Iter>
void
test_iter_comp(unsigned N)
{
RANGES_ENSURE(N > 0);
std::unique_ptr<int[]> a{new int[N]};
std::iota(a.get(), a.get()+N, 0);
std::shuffle(a.get(), a.get()+N, gen);
test_iter_comp(Iter(a.get()), Sent(a.get()+N));
}
template<class Iter, class Sent = Iter>
void
test_iter_comp()
{
test_iter_comp<Iter, Sent>(1);
test_iter_comp<Iter, Sent>(2);
test_iter_comp<Iter, Sent>(3);
test_iter_comp<Iter, Sent>(10);
test_iter_comp<Iter, Sent>(1000);
}
struct S
{
int value;
int index;
};
}
int main()
{
test_iter<InputIterator<const int*> >();
test_iter<ForwardIterator<const int*> >();
test_iter<BidirectionalIterator<const int*> >();
test_iter<RandomAccessIterator<const int*> >();
test_iter<const int*>();
test_iter<InputIterator<const int*>, Sentinel<const int*>>();
test_iter<ForwardIterator<const int*>, Sentinel<const int*>>();
test_iter<BidirectionalIterator<const int*>, Sentinel<const int*>>();
test_iter<RandomAccessIterator<const int*>, Sentinel<const int*>>();
test_iter<InputIterator<const int*> >();
test_iter<ForwardIterator<const int*> >();
test_iter<BidirectionalIterator<const int*> >();
test_iter<RandomAccessIterator<const int*> >();
test_iter<const int*>();
test_iter<InputIterator<const int*>, Sentinel<const int*>>();
test_iter<ForwardIterator<const int*>, Sentinel<const int*>>();
test_iter<BidirectionalIterator<const int*>, Sentinel<const int*>>();
test_iter<RandomAccessIterator<const int*>, Sentinel<const int*>>();
test_iter_comp<InputIterator<const int*> >();
test_iter_comp<ForwardIterator<const int*> >();
test_iter_comp<BidirectionalIterator<const int*> >();
test_iter_comp<RandomAccessIterator<const int*> >();
test_iter_comp<const int*>();
test_iter_comp<InputIterator<const int*>, Sentinel<const int*>>();
test_iter_comp<ForwardIterator<const int*>, Sentinel<const int*>>();
test_iter_comp<BidirectionalIterator<const int*>, Sentinel<const int*>>();
test_iter_comp<RandomAccessIterator<const int*>, Sentinel<const int*>>();
test_iter_comp<InputIterator<const int*> >();
test_iter_comp<ForwardIterator<const int*> >();
test_iter_comp<BidirectionalIterator<const int*> >();
test_iter_comp<RandomAccessIterator<const int*> >();
test_iter_comp<const int*>();
test_iter_comp<InputIterator<const int*>, Sentinel<const int*>>();
test_iter_comp<ForwardIterator<const int*>, Sentinel<const int*>>();
test_iter_comp<BidirectionalIterator<const int*>, Sentinel<const int*>>();
test_iter_comp<RandomAccessIterator<const int*>, Sentinel<const int*>>();
// Works with projections?
S s[] = {S{1,0},S{2,1},S{3,2},S{4,3},S{-4,4},S{40,5},S{-4,6},S{40,7},S{7,8},S{8,9},S{9,10}};
auto res = ranges::minmax(s, std::less<int>{}, &S::value);
CHECK(res.min.value == -4);
CHECK(res.min.index == 4);
CHECK(res.max.value == 40);
CHECK(res.max.index == 7);
// Works with initializer_lists? (Regression test for #1004)
CHECK(ranges::minmax({4,3,1,2,6,5}) == ranges::minmax_result<int>{1,6});
return test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/set_union4.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#define SET_UNION_4
#include "./set_union.hpp"
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/find_end.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <utility>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/find_end.hpp>
#include "../simple_test.hpp"
#include "../test_iterators.hpp"
constexpr bool test_constexpr()
{
using namespace ranges;
int ia[] = {0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 0, 1, 2, 3, 0, 1, 2, 0, 1, 0};
auto ia_b = begin(ia);
auto ia_e = end(ia);
constexpr auto sa = size(ia);
int b[] = {0};
int c[] = {0, 1};
int d[] = {0, 1, 2};
int e[] = {0, 1, 2, 3};
int f[] = {0, 1, 2, 3, 4};
int g[] = {0, 1, 2, 3, 4, 5};
int h[] = {0, 1, 2, 3, 4, 5, 6};
STATIC_CHECK_RETURN(find_end(ia_b, ia_e, begin(b), b + 1).begin() == ia + sa - 1);
STATIC_CHECK_RETURN(find_end(ia_b, ia_e, begin(c), c + 2).begin() == ia + 18);
STATIC_CHECK_RETURN(find_end(ia_b, ia_e, begin(d), d + 3).begin() == ia + 15);
STATIC_CHECK_RETURN(find_end(ia_b, ia_e, begin(e), e + 4).begin() == ia + 11);
STATIC_CHECK_RETURN(find_end(ia_b, ia_e, begin(f), f + 5).begin() == ia + 6);
STATIC_CHECK_RETURN(find_end(ia_b, ia_e, begin(g), g + 6).begin() == ia);
STATIC_CHECK_RETURN(find_end(ia_b, ia_e, begin(h), h + 7).begin() == ia + sa);
STATIC_CHECK_RETURN(find_end(ia_b, ia_e, begin(b), b).begin() == ia + sa);
STATIC_CHECK_RETURN(find_end(ia_b, ia_b, begin(b), b + 1).begin() == ia);
auto ir = make_subrange(ia_b, ia_e);
STATIC_CHECK_RETURN(find_end(ir, make_subrange(begin(b), b + 1)).begin() == ia + sa - 1);
STATIC_CHECK_RETURN(find_end(ir, make_subrange(begin(c), c + 2)).begin() == ia + 18);
STATIC_CHECK_RETURN(find_end(ir, make_subrange(begin(d), d + 3)).begin() == ia + 15);
STATIC_CHECK_RETURN(find_end(ir, make_subrange(begin(e), e + 4)).begin() == ia + 11);
STATIC_CHECK_RETURN(find_end(ir, make_subrange(begin(f), f + 5)).begin() == ia + 6);
STATIC_CHECK_RETURN(find_end(ir, make_subrange(begin(g), g + 6)).begin() == ia);
STATIC_CHECK_RETURN(find_end(ir, make_subrange(begin(h), h + 7)).begin() == ia + sa);
STATIC_CHECK_RETURN(find_end(ir, make_subrange(begin(b), b)).begin() == ia + sa);
STATIC_CHECK_RETURN(find_end(std::move(ir), make_subrange(begin(b), b + 1)).begin() == ia + sa - 1);
STATIC_CHECK_RETURN(find_end(std::move(ir), make_subrange(begin(c), c + 2)).begin() == ia + 18);
STATIC_CHECK_RETURN(find_end(std::move(ir), make_subrange(begin(d), d + 3)).begin() == ia + 15);
STATIC_CHECK_RETURN(find_end(std::move(ir), make_subrange(begin(e), e + 4)).begin() == ia + 11);
STATIC_CHECK_RETURN(find_end(std::move(ir), make_subrange(begin(f), f + 5)).begin() == ia + 6);
STATIC_CHECK_RETURN(find_end(std::move(ir), make_subrange(begin(g), g + 6)).begin() == ia);
STATIC_CHECK_RETURN(find_end(std::move(ir), make_subrange(begin(h), h + 7)).begin() == ia + sa);
STATIC_CHECK_RETURN(find_end(std::move(ir), make_subrange(begin(b), b)).begin() == ia + sa);
auto er = make_subrange(ia_b, ia);
STATIC_CHECK_RETURN(find_end(er, make_subrange(b, b + 1)).begin() == ia);
STATIC_CHECK_RETURN(find_end(std::move(er), make_subrange(b, b + 1)).begin() == ia);
return true;
}
template<class Iter1, class Iter2, typename Sent1 = Iter1, typename Sent2 = Iter2>
void
test()
{
using namespace ranges;
int ia[] = {0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 0, 1, 2, 3, 0, 1, 2, 0, 1, 0};
constexpr auto sa = size(ia);
int b[] = {0};
int c[] = {0, 1};
int d[] = {0, 1, 2};
int e[] = {0, 1, 2, 3};
int f[] = {0, 1, 2, 3, 4};
int g[] = {0, 1, 2, 3, 4, 5};
int h[] = {0, 1, 2, 3, 4, 5, 6};
CHECK(find_end(Iter1(ia), Sent1(ia + sa), Iter2(b), Sent2(b + 1)).begin() == Iter1(ia + sa - 1));
CHECK(find_end(Iter1(ia), Sent1(ia + sa), Iter2(b), Sent2(b + 1)).end() == Iter1(ia + sa - 1 + 1));
CHECK(find_end(Iter1(ia), Sent1(ia + sa), Iter2(c), Sent2(c + 2)).begin() == Iter1(ia + 18));
CHECK(find_end(Iter1(ia), Sent1(ia + sa), Iter2(c), Sent2(c + 2)).end() == Iter1(ia + 18 + 2));
CHECK(find_end(Iter1(ia), Sent1(ia + sa), Iter2(d), Sent2(d + 3)).begin() == Iter1(ia + 15));
CHECK(find_end(Iter1(ia), Sent1(ia + sa), Iter2(d), Sent2(d + 3)).end() == Iter1(ia + 15 + 3));
CHECK(find_end(Iter1(ia), Sent1(ia + sa), Iter2(e), Sent2(e + 4)).begin() == Iter1(ia + 11));
CHECK(find_end(Iter1(ia), Sent1(ia + sa), Iter2(e), Sent2(e + 4)).end() == Iter1(ia + 11 + 4));
CHECK(find_end(Iter1(ia), Sent1(ia + sa), Iter2(f), Sent2(f + 5)).begin() == Iter1(ia + 6));
CHECK(find_end(Iter1(ia), Sent1(ia + sa), Iter2(f), Sent2(f + 5)).end() == Iter1(ia + 6 + 5));
CHECK(find_end(Iter1(ia), Sent1(ia + sa), Iter2(g), Sent2(g + 6)).begin() == Iter1(ia));
CHECK(find_end(Iter1(ia), Sent1(ia + sa), Iter2(g), Sent2(g + 6)).end() == Iter1(ia + 6));
CHECK(find_end(Iter1(ia), Sent1(ia + sa), Iter2(h), Sent2(h + 7)).begin() == Iter1(ia + sa));
CHECK(find_end(Iter1(ia), Sent1(ia + sa), Iter2(h), Sent2(h + 7)).end() == Iter1(ia + sa));
CHECK(find_end(Iter1(ia), Sent1(ia + sa), Iter2(b), Sent2(b)).begin() == Iter1(ia + sa));
CHECK(find_end(Iter1(ia), Sent1(ia + sa), Iter2(b), Sent2(b)).end() == Iter1(ia + sa));
CHECK(find_end(Iter1(ia), Sent1(ia), Iter2(b), Sent2(b + 1)).begin() == Iter1(ia));
CHECK(find_end(Iter1(ia), Sent1(ia), Iter2(b), Sent2(b + 1)).end() == Iter1(ia));
auto ir = make_subrange(Iter1(ia), Sent1(ia + sa));
CHECK(find_end(ir, make_subrange(Iter2(b), Sent2(b + 1))).begin() == Iter1(ia + sa - 1));
CHECK(find_end(ir, make_subrange(Iter2(b), Sent2(b + 1))).end() == Iter1(ia + sa - 1 + 1));
CHECK(find_end(ir, make_subrange(Iter2(c), Sent2(c + 2))).begin() == Iter1(ia + 18));
CHECK(find_end(ir, make_subrange(Iter2(c), Sent2(c + 2))).end() == Iter1(ia + 18 + 2));
CHECK(find_end(ir, make_subrange(Iter2(d), Sent2(d + 3))).begin() == Iter1(ia + 15));
CHECK(find_end(ir, make_subrange(Iter2(d), Sent2(d + 3))).end() == Iter1(ia + 15 + 3));
CHECK(find_end(ir, make_subrange(Iter2(e), Sent2(e + 4))).begin() == Iter1(ia + 11));
CHECK(find_end(ir, make_subrange(Iter2(e), Sent2(e + 4))).end() == Iter1(ia + 11 + 4));
CHECK(find_end(ir, make_subrange(Iter2(f), Sent2(f + 5))).begin() == Iter1(ia + 6));
CHECK(find_end(ir, make_subrange(Iter2(f), Sent2(f + 5))).end() == Iter1(ia + 6 + 5));
CHECK(find_end(ir, make_subrange(Iter2(g), Sent2(g + 6))).begin() == Iter1(ia));
CHECK(find_end(ir, make_subrange(Iter2(g), Sent2(g + 6))).end() == Iter1(ia + 6));
CHECK(find_end(ir, make_subrange(Iter2(h), Sent2(h + 7))).begin() == Iter1(ia + sa));
CHECK(find_end(ir, make_subrange(Iter2(h), Sent2(h + 7))).end() == Iter1(ia + sa));
CHECK(find_end(ir, make_subrange(Iter2(b), Sent2(b))).begin() == Iter1(ia + sa));
CHECK(find_end(ir, make_subrange(Iter2(b), Sent2(b))).end() == Iter1(ia + sa));
CHECK(find_end(std::move(ir), make_subrange(Iter2(b), Sent2(b + 1))).begin() == Iter1(ia + sa - 1));
CHECK(find_end(std::move(ir), make_subrange(Iter2(c), Sent2(c + 2))).begin() == Iter1(ia + 18));
CHECK(find_end(std::move(ir), make_subrange(Iter2(c), Sent2(c + 2))).end() == Iter1(ia + 18 + 2));
CHECK(find_end(std::move(ir), make_subrange(Iter2(d), Sent2(d + 3))).begin() == Iter1(ia + 15));
CHECK(find_end(std::move(ir), make_subrange(Iter2(d), Sent2(d + 3))).end() == Iter1(ia + 15 + 3));
CHECK(find_end(std::move(ir), make_subrange(Iter2(e), Sent2(e + 4))).begin() == Iter1(ia + 11));
CHECK(find_end(std::move(ir), make_subrange(Iter2(e), Sent2(e + 4))).end() == Iter1(ia + 11 + 4));
CHECK(find_end(std::move(ir), make_subrange(Iter2(f), Sent2(f + 5))).begin() == Iter1(ia + 6));
CHECK(find_end(std::move(ir), make_subrange(Iter2(f), Sent2(f + 5))).end() == Iter1(ia + 6 + 5));
CHECK(find_end(std::move(ir), make_subrange(Iter2(g), Sent2(g + 6))).begin() == Iter1(ia));
CHECK(find_end(std::move(ir), make_subrange(Iter2(g), Sent2(g + 6))).end() == Iter1(ia + 6));
CHECK(find_end(std::move(ir), make_subrange(Iter2(h), Sent2(h + 7))).begin() == Iter1(ia + sa));
CHECK(find_end(std::move(ir), make_subrange(Iter2(h), Sent2(h + 7))).end() == Iter1(ia + sa));
CHECK(find_end(std::move(ir), make_subrange(Iter2(b), Sent2(b))).begin() == Iter1(ia + sa));
auto er = make_subrange(Iter1(ia), Sent1(ia));
CHECK(find_end(er, make_subrange(Iter2(b), Sent2(b + 1))).begin() == Iter1(ia));
CHECK(find_end(er, make_subrange(Iter2(b), Sent2(b + 1))).end() == Iter1(ia));
CHECK(find_end(std::move(er), make_subrange(Iter2(b), Sent2(b + 1))).begin() == Iter1(ia));
CHECK(find_end(std::move(er), make_subrange(Iter2(b), Sent2(b + 1))).end() == Iter1(ia));
}
struct count_equal
{
static unsigned count;
template<class T>
bool operator()(const T& x, const T& y)
{
++count; return x == y;
}
};
unsigned count_equal::count = 0;
template<class Iter1, class Iter2, typename Sent1 = Iter1, typename Sent2 = Iter2>
void
test_pred()
{
using namespace ranges;
int ia[] = {0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 0, 1, 2, 3, 0, 1, 2, 0, 1, 0};
constexpr auto sa = size(ia);
int b[] = {0};
int c[] = {0, 1};
int d[] = {0, 1, 2};
int e[] = {0, 1, 2, 3};
int f[] = {0, 1, 2, 3, 4};
int g[] = {0, 1, 2, 3, 4, 5};
int h[] = {0, 1, 2, 3, 4, 5, 6};
count_equal::count = 0;
CHECK(find_end(Iter1(ia), Sent1(ia + sa), Iter2(b), Sent2(b + 1), count_equal()).begin() == Iter1(ia + sa - 1));
CHECK(count_equal::count <= 1 * (sa - 1 + 1));
count_equal::count = 0;
CHECK(find_end(Iter1(ia), Sent1(ia + sa), Iter2(c), Sent2(c + 2), count_equal()).begin() == Iter1(ia + 18));
CHECK(count_equal::count <= 2 * (sa - 2 + 1));
count_equal::count = 0;
CHECK(find_end(Iter1(ia), Sent1(ia + sa), Iter2(d), Sent2(d + 3), count_equal()).begin() == Iter1(ia + 15));
CHECK(count_equal::count <= 3 * (sa - 3 + 1));
count_equal::count = 0;
CHECK(find_end(Iter1(ia), Sent1(ia + sa), Iter2(e), Sent2(e + 4), count_equal()).begin() == Iter1(ia + 11));
CHECK(count_equal::count <= 4 * (sa - 4 + 1));
count_equal::count = 0;
CHECK(find_end(Iter1(ia), Sent1(ia + sa), Iter2(f), Sent2(f + 5), count_equal()).begin() == Iter1(ia + 6));
CHECK(count_equal::count <= 5 * (sa - 5 + 1));
count_equal::count = 0;
CHECK(find_end(Iter1(ia), Sent1(ia + sa), Iter2(g), Sent2(g + 6), count_equal()).begin() == Iter1(ia));
CHECK(count_equal::count <= 6 * (sa - 6 + 1));
count_equal::count = 0;
CHECK(find_end(Iter1(ia), Sent1(ia + sa), Iter2(h), Sent2(h + 7), count_equal()).begin() == Iter1(ia + sa));
CHECK(count_equal::count <= 7 * (sa - 7 + 1));
count_equal::count = 0;
CHECK(find_end(Iter1(ia), Sent1(ia + sa), Iter2(b), Sent2(b), count_equal()).begin() == Iter1(ia + sa));
CHECK(count_equal::count == 0u);
count_equal::count = 0;
CHECK(find_end(Iter1(ia), Sent1(ia), Iter2(b), Sent2(b + 1), count_equal()).begin() == Iter1(ia));
CHECK(count_equal::count == 0u);
auto ir = make_subrange(Iter1(ia), Sent1(ia + sa));
count_equal::count = 0;
CHECK(find_end(ir, make_subrange(Iter2(b), Sent2(b + 1)), count_equal()).begin() == Iter1(ia + sa - 1));
CHECK(count_equal::count <= 1 * (sa - 1 + 1));
count_equal::count = 0;
CHECK(find_end(ir, make_subrange(Iter2(c), Sent2(c + 2)), count_equal()).begin() == Iter1(ia + 18));
CHECK(count_equal::count <= 2 * (sa - 2 + 1));
count_equal::count = 0;
CHECK(find_end(ir, make_subrange(Iter2(d), Sent2(d + 3)), count_equal()).begin() == Iter1(ia + 15));
CHECK(count_equal::count <= 3 * (sa - 3 + 1));
count_equal::count = 0;
CHECK(find_end(ir, make_subrange(Iter2(e), Sent2(e + 4)), count_equal()).begin() == Iter1(ia + 11));
CHECK(count_equal::count <= 4 * (sa - 4 + 1));
count_equal::count = 0;
CHECK(find_end(ir, make_subrange(Iter2(f), Sent2(f + 5)), count_equal()).begin() == Iter1(ia + 6));
CHECK(count_equal::count <= 5 * (sa - 5 + 1));
count_equal::count = 0;
CHECK(find_end(ir, make_subrange(Iter2(g), Sent2(g + 6)), count_equal()).begin() == Iter1(ia));
CHECK(count_equal::count <= 6 * (sa - 6 + 1));
count_equal::count = 0;
CHECK(find_end(ir, make_subrange(Iter2(h), Sent2(h + 7)), count_equal()).begin() == Iter1(ia + sa));
CHECK(count_equal::count <= 7 * (sa - 7 + 1));
count_equal::count = 0;
CHECK(find_end(ir, make_subrange(Iter2(b), Sent2(b)), count_equal()).begin() == Iter1(ia + sa));
CHECK(count_equal::count == 0u);
count_equal::count = 0;
auto er = make_subrange(Iter1(ia), Sent1(ia));
CHECK(find_end(er, make_subrange(Iter2(b), Sent2(b + 1)), count_equal()).begin() == Iter1(ia));
CHECK(count_equal::count == 0u);
static_assert(std::is_same<subrange<Iter1>, decltype(find_end(er, {1, 2, 3}))>::value, "");
}
struct S
{
int i_;
};
template<class Iter1, class Iter2, typename Sent1 = Iter1, typename Sent2 = Iter2>
void
test_proj()
{
using namespace ranges;
S ia[] = {{0}, {1}, {2}, {3}, {4}, {5}, {0}, {1}, {2}, {3}, {4}, {0}, {1}, {2}, {3}, {0}, {1}, {2}, {0}, {1}, {0}};
constexpr auto sa = size(ia);
int b[] = {0};
int c[] = {0, 1};
int d[] = {0, 1, 2};
int e[] = {0, 1, 2, 3};
int f[] = {0, 1, 2, 3, 4};
int g[] = {0, 1, 2, 3, 4, 5};
int h[] = {0, 1, 2, 3, 4, 5, 6};
CHECK(find_end(Iter1(ia), Sent1(ia + sa), Iter2(b), Sent2(b + 1), equal_to(), &S::i_).begin() == Iter1(ia + sa - 1));
CHECK(find_end(Iter1(ia), Sent1(ia + sa), Iter2(c), Sent2(c + 2), equal_to(), &S::i_).begin() == Iter1(ia + 18));
CHECK(find_end(Iter1(ia), Sent1(ia + sa), Iter2(d), Sent2(d + 3), equal_to(), &S::i_).begin() == Iter1(ia + 15));
CHECK(find_end(Iter1(ia), Sent1(ia + sa), Iter2(e), Sent2(e + 4), equal_to(), &S::i_).begin() == Iter1(ia + 11));
CHECK(find_end(Iter1(ia), Sent1(ia + sa), Iter2(f), Sent2(f + 5), equal_to(), &S::i_).begin() == Iter1(ia + 6));
CHECK(find_end(Iter1(ia), Sent1(ia + sa), Iter2(g), Sent2(g + 6), equal_to(), &S::i_).begin() == Iter1(ia));
CHECK(find_end(Iter1(ia), Sent1(ia + sa), Iter2(h), Sent2(h + 7), equal_to(), &S::i_).begin() == Iter1(ia + sa));
CHECK(find_end(Iter1(ia), Sent1(ia + sa), Iter2(b), Sent2(b), equal_to(), &S::i_).begin() == Iter1(ia + sa));
CHECK(find_end(Iter1(ia), Sent1(ia), Iter2(b), Sent2(b + 1), equal_to(), &S::i_).begin() == Iter1(ia));
auto ir = make_subrange(Iter1(ia), Sent1(ia + sa));
CHECK(find_end(ir, make_subrange(Iter2(b), Sent2(b + 1)), equal_to(), &S::i_).begin() == Iter1(ia + sa - 1));
CHECK(find_end(ir, make_subrange(Iter2(c), Sent2(c + 2)), equal_to(), &S::i_).begin() == Iter1(ia + 18));
CHECK(find_end(ir, make_subrange(Iter2(d), Sent2(d + 3)), equal_to(), &S::i_).begin() == Iter1(ia + 15));
CHECK(find_end(ir, make_subrange(Iter2(e), Sent2(e + 4)), equal_to(), &S::i_).begin() == Iter1(ia + 11));
CHECK(find_end(ir, make_subrange(Iter2(f), Sent2(f + 5)), equal_to(), &S::i_).begin() == Iter1(ia + 6));
CHECK(find_end(ir, make_subrange(Iter2(g), Sent2(g + 6)), equal_to(), &S::i_).begin() == Iter1(ia));
CHECK(find_end(ir, make_subrange(Iter2(h), Sent2(h + 7)), equal_to(), &S::i_).begin() == Iter1(ia + sa));
CHECK(find_end(ir, make_subrange(Iter2(b), Sent2(b)), equal_to(), &S::i_).begin() == Iter1(ia + sa));
auto er = make_subrange(Iter1(ia), Sent1(ia));
CHECK(find_end(er, make_subrange(Iter2(b), Sent2(b + 1)), equal_to(), &S::i_).begin() == Iter1(ia));
}
int main()
{
test<ForwardIterator<const int*>, ForwardIterator<const int*> >();
// test<ForwardIterator<const int*>, BidirectionalIterator<const int*> >();
// test<ForwardIterator<const int*>, RandomAccessIterator<const int*> >();
// test<BidirectionalIterator<const int*>, ForwardIterator<const int*> >();
// test<BidirectionalIterator<const int*>, BidirectionalIterator<const int*> >();
// test<BidirectionalIterator<const int*>, RandomAccessIterator<const int*> >();
// test<RandomAccessIterator<const int*>, ForwardIterator<const int*> >();
// test<RandomAccessIterator<const int*>, BidirectionalIterator<const int*> >();
// test<RandomAccessIterator<const int*>, RandomAccessIterator<const int*> >();
// test<ForwardIterator<const int*>, ForwardIterator<const int*>, Sentinel<const int*>, Sentinel<const int *> >();
// test<ForwardIterator<const int*>, BidirectionalIterator<const int*>, Sentinel<const int*>, Sentinel<const int *> >();
// test<ForwardIterator<const int*>, RandomAccessIterator<const int*>, Sentinel<const int*>, Sentinel<const int *> >();
// test<BidirectionalIterator<const int*>, ForwardIterator<const int*>, Sentinel<const int*>, Sentinel<const int *> >();
// test<BidirectionalIterator<const int*>, BidirectionalIterator<const int*>, Sentinel<const int*>, Sentinel<const int *> >();
// test<BidirectionalIterator<const int*>, RandomAccessIterator<const int*>, Sentinel<const int*>, Sentinel<const int *> >();
// test<RandomAccessIterator<const int*>, ForwardIterator<const int*>, Sentinel<const int*>, Sentinel<const int *> >();
// test<RandomAccessIterator<const int*>, BidirectionalIterator<const int*>, Sentinel<const int*>, Sentinel<const int *> >();
// test<RandomAccessIterator<const int*>, RandomAccessIterator<const int*>, Sentinel<const int*>, Sentinel<const int *> >();
// test_pred<ForwardIterator<const int*>, ForwardIterator<const int*> >();
// test_pred<ForwardIterator<const int*>, BidirectionalIterator<const int*> >();
// test_pred<ForwardIterator<const int*>, RandomAccessIterator<const int*> >();
// test_pred<BidirectionalIterator<const int*>, ForwardIterator<const int*> >();
// test_pred<BidirectionalIterator<const int*>, BidirectionalIterator<const int*> >();
// test_pred<BidirectionalIterator<const int*>, RandomAccessIterator<const int*> >();
// test_pred<RandomAccessIterator<const int*>, ForwardIterator<const int*> >();
// test_pred<RandomAccessIterator<const int*>, BidirectionalIterator<const int*> >();
// test_pred<RandomAccessIterator<const int*>, RandomAccessIterator<const int*> >();
// test_pred<ForwardIterator<const int*>, ForwardIterator<const int*>, Sentinel<const int*>, Sentinel<const int *> >();
// test_pred<ForwardIterator<const int*>, BidirectionalIterator<const int*>, Sentinel<const int*>, Sentinel<const int *> >();
// test_pred<ForwardIterator<const int*>, RandomAccessIterator<const int*>, Sentinel<const int*>, Sentinel<const int *> >();
// test_pred<BidirectionalIterator<const int*>, ForwardIterator<const int*>, Sentinel<const int*>, Sentinel<const int *> >();
// test_pred<BidirectionalIterator<const int*>, BidirectionalIterator<const int*>, Sentinel<const int*>, Sentinel<const int *> >();
// test_pred<BidirectionalIterator<const int*>, RandomAccessIterator<const int*>, Sentinel<const int*>, Sentinel<const int *> >();
// test_pred<RandomAccessIterator<const int*>, ForwardIterator<const int*>, Sentinel<const int*>, Sentinel<const int *> >();
// test_pred<RandomAccessIterator<const int*>, BidirectionalIterator<const int*>, Sentinel<const int*>, Sentinel<const int *> >();
// test_pred<RandomAccessIterator<const int*>, RandomAccessIterator<const int*>, Sentinel<const int*>, Sentinel<const int *> >();
// test_proj<ForwardIterator<const S*>, ForwardIterator<const int*> >();
// test_proj<ForwardIterator<const S*>, BidirectionalIterator<const int*> >();
// test_proj<ForwardIterator<const S*>, RandomAccessIterator<const int*> >();
// test_proj<BidirectionalIterator<const S*>, ForwardIterator<const int*> >();
// test_proj<BidirectionalIterator<const S*>, BidirectionalIterator<const int*> >();
// test_proj<BidirectionalIterator<const S*>, RandomAccessIterator<const int*> >();
// test_proj<RandomAccessIterator<const S*>, ForwardIterator<const int*> >();
// test_proj<RandomAccessIterator<const S*>, BidirectionalIterator<const int*> >();
// test_proj<RandomAccessIterator<const S*>, RandomAccessIterator<const int*> >();
// test_proj<ForwardIterator<const S*>, ForwardIterator<const int*>, Sentinel<const S*>, Sentinel<const int *> >();
// test_proj<ForwardIterator<const S*>, BidirectionalIterator<const int*>, Sentinel<const S*>, Sentinel<const int *> >();
// test_proj<ForwardIterator<const S*>, RandomAccessIterator<const int*>, Sentinel<const S*>, Sentinel<const int *> >();
// test_proj<BidirectionalIterator<const S*>, ForwardIterator<const int*>, Sentinel<const S*>, Sentinel<const int *> >();
// test_proj<BidirectionalIterator<const S*>, BidirectionalIterator<const int*>, Sentinel<const S*>, Sentinel<const int *> >();
// test_proj<BidirectionalIterator<const S*>, RandomAccessIterator<const int*>, Sentinel<const S*>, Sentinel<const int *> >();
// test_proj<RandomAccessIterator<const S*>, ForwardIterator<const int*>, Sentinel<const S*>, Sentinel<const int *> >();
// test_proj<RandomAccessIterator<const S*>, BidirectionalIterator<const int*>, Sentinel<const S*>, Sentinel<const int *> >();
// test_proj<RandomAccessIterator<const S*>, RandomAccessIterator<const int*>, Sentinel<const S*>, Sentinel<const int *> >();
{
STATIC_CHECK(test_constexpr());
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/remove.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright 2005 - 2007 Adobe Systems Incorporated
// Distributed under the MIT License(see accompanying file LICENSE_1_0_0.txt
// or a copy at http://stlab.adobe.com/licenses.html)
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <memory>
#include <utility>
#include <vector>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/remove.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
template<class Iter, class Sent = Iter>
void
test_iter()
{
int ia[] = {0, 1, 2, 3, 4, 2, 3, 4, 2};
constexpr auto sa = ranges::size(ia);
Iter r = ranges::remove(Iter(ia), Sent(ia+sa), 2);
CHECK(base(r) == ia + sa-3);
CHECK(ia[0] == 0);
CHECK(ia[1] == 1);
CHECK(ia[2] == 3);
CHECK(ia[3] == 4);
CHECK(ia[4] == 3);
CHECK(ia[5] == 4);
}
template<class Iter, class Sent = Iter>
void
test_range()
{
int ia[] = {0, 1, 2, 3, 4, 2, 3, 4, 2};
constexpr auto sa = ranges::size(ia);
Iter r = ranges::remove(ranges::make_subrange(Iter(ia), Sent(ia+sa)), 2);
CHECK(base(r) == ia + sa-3);
CHECK(ia[0] == 0);
CHECK(ia[1] == 1);
CHECK(ia[2] == 3);
CHECK(ia[3] == 4);
CHECK(ia[4] == 3);
CHECK(ia[5] == 4);
}
template<class Iter, class Sent = Iter>
void
test_iter_rvalue()
{
constexpr 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 = ranges::remove(Iter(ia), Sent(ia+sa), std::unique_ptr<int>());
CHECK(base(r) == ia + sa-3);
CHECK(*ia[0] == 0);
CHECK(*ia[1] == 1);
CHECK(*ia[2] == 3);
CHECK(*ia[3] == 4);
CHECK(*ia[4] == 3);
CHECK(*ia[5] == 4);
}
template<class Iter, class Sent = Iter>
void
test_range_rvalue()
{
constexpr 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 = ranges::remove(ranges::make_subrange(Iter(ia), Sent(ia+sa)), std::unique_ptr<int>());
CHECK(base(r) == ia + sa-3);
CHECK(*ia[0] == 0);
CHECK(*ia[1] == 1);
CHECK(*ia[2] == 3);
CHECK(*ia[3] == 4);
CHECK(*ia[4] == 3);
CHECK(*ia[5] == 4);
}
struct S
{
int i;
};
constexpr bool test_constexpr()
{
using namespace ranges;
int ia[] = {0, 1, 2, 3, 4, 2, 3, 4, 2};
constexpr auto sa = ranges::size(ia);
auto r = ranges::remove(ia, 2);
STATIC_CHECK_RETURN(r == ia + sa - 3);
STATIC_CHECK_RETURN(ia[0] == 0);
STATIC_CHECK_RETURN(ia[1] == 1);
STATIC_CHECK_RETURN(ia[2] == 3);
STATIC_CHECK_RETURN(ia[3] == 4);
STATIC_CHECK_RETURN(ia[4] == 3);
STATIC_CHECK_RETURN(ia[5] == 4);
return true;
}
int main()
{
test_iter<ForwardIterator<int*> >();
test_iter<BidirectionalIterator<int*> >();
test_iter<RandomAccessIterator<int*> >();
test_iter<int*>();
test_iter<ForwardIterator<int*>, Sentinel<int*>>();
test_iter<BidirectionalIterator<int*>, Sentinel<int*>>();
test_iter<RandomAccessIterator<int*>, Sentinel<int*>>();
test_range<ForwardIterator<int*> >();
test_range<BidirectionalIterator<int*> >();
test_range<RandomAccessIterator<int*> >();
test_range<int*>();
test_range<ForwardIterator<int*>, Sentinel<int*>>();
test_range<BidirectionalIterator<int*>, Sentinel<int*>>();
test_range<RandomAccessIterator<int*>, Sentinel<int*>>();
test_iter_rvalue<ForwardIterator<std::unique_ptr<int>*> >();
test_iter_rvalue<BidirectionalIterator<std::unique_ptr<int>*> >();
test_iter_rvalue<RandomAccessIterator<std::unique_ptr<int>*> >();
test_iter_rvalue<std::unique_ptr<int>*>();
test_iter_rvalue<ForwardIterator<std::unique_ptr<int>*>, Sentinel<std::unique_ptr<int>*>>();
test_iter_rvalue<BidirectionalIterator<std::unique_ptr<int>*>, Sentinel<std::unique_ptr<int>*>>();
test_iter_rvalue<RandomAccessIterator<std::unique_ptr<int>*>, Sentinel<std::unique_ptr<int>*>>();
test_range_rvalue<ForwardIterator<std::unique_ptr<int>*> >();
test_range_rvalue<BidirectionalIterator<std::unique_ptr<int>*> >();
test_range_rvalue<RandomAccessIterator<std::unique_ptr<int>*> >();
test_range_rvalue<std::unique_ptr<int>*>();
test_range_rvalue<ForwardIterator<std::unique_ptr<int>*>, Sentinel<std::unique_ptr<int>*>>();
test_range_rvalue<BidirectionalIterator<std::unique_ptr<int>*>, Sentinel<std::unique_ptr<int>*>>();
test_range_rvalue<RandomAccessIterator<std::unique_ptr<int>*>, Sentinel<std::unique_ptr<int>*>>();
// Check projection
S ia[] = {S{0}, S{1}, S{2}, S{3}, S{4}, S{2}, S{3}, S{4}, S{2}};
constexpr auto sa = ranges::size(ia);
S* r = ranges::remove(ia, 2, &S::i);
CHECK(r == ia + sa-3);
CHECK(ia[0].i == 0);
CHECK(ia[1].i == 1);
CHECK(ia[2].i == 3);
CHECK(ia[3].i == 4);
CHECK(ia[4].i == 3);
CHECK(ia[5].i == 4);
// Check rvalue ranges
S ia2[] = {S{0}, S{1}, S{2}, S{3}, S{4}, S{2}, S{3}, S{4}, S{2}};
auto r2 = ranges::remove(std::move(ia2), 2, &S::i);
#ifndef RANGES_WORKAROUND_MSVC_573728
CHECK(::is_dangling(r2));
#endif // RANGES_WORKAROUND_MSVC_573728
CHECK(ia2[0].i == 0);
CHECK(ia2[1].i == 1);
CHECK(ia2[2].i == 3);
CHECK(ia2[3].i == 4);
CHECK(ia2[4].i == 3);
CHECK(ia2[5].i == 4);
std::vector<S> vec{S{0}, S{1}, S{2}, S{3}, S{4}, S{2}, S{3}, S{4}, S{2}};
auto r3 = ranges::remove(std::move(vec), 2, &S::i);
CHECK(::is_dangling(r3));
CHECK(vec[0].i == 0);
CHECK(vec[1].i == 1);
CHECK(vec[2].i == 3);
CHECK(vec[3].i == 4);
CHECK(vec[4].i == 3);
CHECK(vec[5].i == 4);
{
STATIC_CHECK(test_constexpr());
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/ends_with.cpp | // Range v3 library
//
// Copyright Johel Guerrero 2019
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#include <initializer_list>
#include <range/v3/algorithm/ends_with.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/view/subrange.hpp>
#include "../simple_test.hpp"
#include "../test_iterators.hpp"
int comparison_count = 0;
template<typename T>
bool counting_equals(const T &a, const T &b)
{
++comparison_count;
return a == b;
}
int main()
{
using namespace ranges;
int ia[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
constexpr auto as = distance(ia);
int ib[] = {5, 6, 7, 8, 9};
constexpr auto bs = distance(ib);
CHECK(ends_with(RandomAccessIterator<const int*>(ia),
RandomAccessIterator<const int*>(ia + as),
RandomAccessIterator<const int*>(ib),
RandomAccessIterator<const int*>(ib + bs)));
CHECK(!ends_with(InputIterator<const int*>(ia),
InputIterator<const int*, true>(ia + as),
InputIterator<const int*>(ib),
InputIterator<const int*, true>(ib + bs - 1)));
CHECK(!ends_with(ForwardIterator<const int*>(ia),
Sentinel<const int*>(ia + as),
ForwardIterator<const int*>(ib),
Sentinel<const int*>(ib + bs - 1)));
CHECK(!ends_with(make_subrange(RandomAccessIterator<const int*>(ia),
RandomAccessIterator<const int*>(ia + as)),
make_subrange(RandomAccessIterator<const int*>(ib),
RandomAccessIterator<const int*>(ib + bs - 1))));
CHECK(ends_with(make_subrange(InputIterator<const int*>(ia),
InputIterator<const int*, true>(ia + as)),
make_subrange(InputIterator<const int*>(ib),
InputIterator<const int*, true>(ib + bs))));
CHECK(ends_with(make_subrange(ForwardIterator<const int*>(ia),
Sentinel<const int*>(ia + as)),
make_subrange(ForwardIterator<const int*>(ib),
Sentinel<const int*>(ib + bs))));
comparison_count = 0;
CHECK(!ends_with(RandomAccessIterator<const int*>(ib),
RandomAccessIterator<const int*>(ib + bs),
RandomAccessIterator<const int*>(ia),
RandomAccessIterator<const int*>(ia + as),
counting_equals<int>));
CHECK(comparison_count == 0);
comparison_count = 0;
CHECK(ends_with(InputIterator<const int*>(ia),
InputIterator<const int*, true>(ia + as),
InputIterator<const int*>(ib),
InputIterator<const int*, true>(ib + bs),
counting_equals<int>));
CHECK(comparison_count > 0);
comparison_count = 0;
CHECK(ends_with(ForwardIterator<const int*>(ia),
Sentinel<const int*>(ia + as),
ForwardIterator<const int*>(ib),
Sentinel<const int*>(ib + bs),
counting_equals<int>));
CHECK(comparison_count > 0);
comparison_count = 0;
CHECK(ends_with(make_subrange(RandomAccessIterator<const int*>(ia),
RandomAccessIterator<const int*>(ia + as)),
make_subrange(RandomAccessIterator<const int*>(ib),
RandomAccessIterator<const int*>(ib + bs)),
counting_equals<int>));
CHECK(comparison_count > 0);
comparison_count = 0;
CHECK(!ends_with(make_subrange(InputIterator<const int*>(ib),
InputIterator<const int*, true>(ib + bs - 1)),
make_subrange(InputIterator<const int*>(ib),
InputIterator<const int*, true>(ib + bs)),
counting_equals<int>));
CHECK(comparison_count == 0);
comparison_count = 0;
CHECK(!ends_with(make_subrange(ForwardIterator<const int*>(ia),
Sentinel<const int*>(ia)),
make_subrange(ForwardIterator<const int*>(ib),
Sentinel<const int*>(ib + bs)),
counting_equals<int>));
CHECK(comparison_count == 0);
#if RANGES_CXX_CONSTEXPR >= RANGES_CXX_CONSTEXPR_14 && RANGES_CONSTEXPR_INVOKE
using IL = std::initializer_list<int>;
static_assert(ends_with(IL{0, 1, 2, 3, 4}, IL{3, 4}), "");
static_assert(!ends_with(IL{0, 1, 2, 3, 4}, IL{2, 3}), "");
static_assert(ends_with(IL{}, IL{}), "");
#endif
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/find_if_not.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <utility>
#include <range/v3/algorithm/find_if_not.hpp>
#include <range/v3/core.hpp>
#include "../simple_test.hpp"
#include "../test_iterators.hpp"
constexpr bool is_three(int i)
{
return i == 3;
}
template<class Rng>
constexpr bool contains_other_than_three(Rng r)
{
auto it = ranges::find_if_not(r, is_three);
return it != ranges::end(r);
}
int main()
{
using namespace ranges;
{
using IL = std::initializer_list<int>;
STATIC_CHECK(contains_other_than_three(IL{3, 3, 2, 3}));
STATIC_CHECK(!contains_other_than_three(IL{3, 3, 3}));
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/set_union2.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#define SET_UNION_2
#include "./set_union.hpp"
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/sort_n_with_buffer.cpp | /// \file
// Range v3 library
//
// Copyright Casey Carter 2016
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#include <range/v3/algorithm/aux_/sort_n_with_buffer.hpp>
#include <functional>
#include <iostream>
#include <utility>
#include <range/v3/range/primitives.hpp>
#include "../simple_test.hpp"
// BUGBUGBUG
namespace std {
template<typename F, typename S>
ostream& operator<<(ostream& os, std::pair<F, S> const& p)
{
return os << '{' << p.first << ", " << p.second << '}';
}
}
int main()
{
std::pair<int, int> some_pairs[] = {
{0, 3}, {1, 2}, {2, 1}, {3, 0}
};
std::pair<int, int> space[2];
ranges::aux::sort_n_with_buffer(some_pairs + 0, ranges::size(some_pairs), space + 0, std::less<int>{}, &std::pair<int, int>::second);
CHECK(some_pairs[0] == std::make_pair(3, 0));
CHECK(some_pairs[1] == std::make_pair(2, 1));
CHECK(some_pairs[2] == std::make_pair(1, 2));
CHECK(some_pairs[3] == std::make_pair(0, 3));
ranges::aux::sort_n_with_buffer(some_pairs + 0, ranges::size(some_pairs), space + 0, std::less<int>{}, &std::pair<int, int>::first);
CHECK(some_pairs[0] == std::make_pair(0, 3));
CHECK(some_pairs[1] == std::make_pair(1, 2));
CHECK(some_pairs[2] == std::make_pair(2, 1));
CHECK(some_pairs[3] == std::make_pair(3, 0));
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/contains_subrange.cpp | // Range v3 library
//
// Copyright Johel Guerrero 2019
// Copyright Google LLC 2021
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#include <array>
#include <initializer_list>
#include <range/v3/algorithm/contains_subrange.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/view/subrange.hpp>
#include "../simple_test.hpp"
#include "../test_iterators.hpp"
int comparison_count = 0;
template<typename T>
bool counting_equals(const T & a, const T & b)
{
++comparison_count;
return a == b;
}
namespace {
template <class T, std::size_t N>
struct array
{
T elems[N];
T* begin() { return elems; }
T* end() { return elems + N; }
};
}
int main()
{
using namespace ranges;
auto full_range = array<int, 10>{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}};
auto valid_subrange = array<int, 5>{{2, 3, 4, 5, 6}};
auto invalid_subrange = array<int, 5>{{3, 4, 5, 6, 2}};
CHECK(contains_subrange(ForwardIterator<const int *>(full_range.begin()),
Sentinel<const int *>(full_range.end()),
ForwardIterator<const int *>(valid_subrange.begin()),
Sentinel<const int *>(valid_subrange.end())));
CHECK(!contains_subrange(ForwardIterator<const int *>(full_range.begin()),
Sentinel<const int *>(full_range.end()),
ForwardIterator<const int *>(invalid_subrange.begin()),
Sentinel<const int *>(invalid_subrange.end())));
CHECK(!contains_subrange(full_range, invalid_subrange));
CHECK(contains_subrange(
make_subrange(ForwardIterator<const int *>(full_range.begin()),
Sentinel<const int *>(full_range.end())),
make_subrange(ForwardIterator<const int *>(valid_subrange.begin()),
Sentinel<const int *>(valid_subrange.end()))));
comparison_count = 0;
CHECK(!contains_subrange(RandomAccessIterator<const int*>(valid_subrange.begin()),
RandomAccessIterator<const int*>(valid_subrange.end()),
RandomAccessIterator<const int*>(full_range.begin()),
RandomAccessIterator<const int*>(full_range.end()),
counting_equals<int>));
CHECK(comparison_count == 0);
comparison_count = 0;
CHECK(contains_subrange(ForwardIterator<const int *>(full_range.begin()),
Sentinel<const int *>(full_range.end()),
ForwardIterator<const int *>(valid_subrange.begin()),
Sentinel<const int *>(valid_subrange.end()),
counting_equals<int>));
CHECK(comparison_count > 0);
comparison_count = 0;
CHECK(contains_subrange(make_subrange(ForwardIterator<const int *>(full_range.begin()),
Sentinel<const int *>(full_range.end())),
make_subrange(ForwardIterator<const int *>(valid_subrange.begin()),
Sentinel<const int *>(valid_subrange.end())),
counting_equals<int>));
CHECK(comparison_count > 0);
comparison_count = 0;
CHECK(!contains_subrange(
make_subrange(ForwardIterator<const int *>(full_range.begin()),
Sentinel<const int *>(full_range.begin())),
make_subrange(ForwardIterator<const int *>(valid_subrange.begin()),
Sentinel<const int *>(valid_subrange.end())),
counting_equals<int>));
CHECK(comparison_count == 0);
#if RANGES_CXX_CONSTEXPR >= RANGES_CXX_CONSTEXPR_14 && RANGES_CONSTEXPR_INVOKE
using IL = std::initializer_list<int>;
static_assert(contains_subrange(IL{0, 1, 2, 3, 4}, IL{3, 4}), "");
static_assert(!contains_subrange(IL{0, 1, 2, 3, 4}, IL{2, 8}), "");
static_assert(contains_subrange(IL{}, IL{}), "");
#endif
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/max_element.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <memory>
#include <numeric>
#include <random>
#include <algorithm>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/max_element.hpp>
#include "../array.hpp"
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
RANGES_DIAGNOSTIC_IGNORE_GLOBAL_CONSTRUCTORS
namespace
{
std::mt19937 gen;
template<class Iter, class Sent = Iter>
void
test_iter(Iter first, Sent last)
{
Iter i = ranges::max_element(first, last);
if (first != last)
{
for (Iter j = first; j != last; ++j)
CHECK(!(*i < *j));
}
else
CHECK(i == last);
auto rng = ::MakeTestRange(first, last);
i = ranges::max_element(rng);
if (first != last)
{
for (Iter j = first; j != last; ++j)
CHECK(!(*i < *j));
}
else
CHECK(i == last);
auto j = ranges::max_element(std::move(rng));
CHECK(::is_dangling(j));
}
template<class Iter, class Sent = Iter>
void
test_iter(unsigned N)
{
std::unique_ptr<int[]> a{new int[N]};
std::iota(a.get(), a.get()+N, 0);
std::shuffle(a.get(), a.get()+N, gen);
test_iter(Iter(a.get()), Sent(a.get()+N));
}
template<class Iter, class Sent = Iter>
void
test_iter()
{
test_iter<Iter, Sent>(0);
test_iter<Iter, Sent>(1);
test_iter<Iter, Sent>(2);
test_iter<Iter, Sent>(3);
test_iter<Iter, Sent>(10);
test_iter<Iter, Sent>(1000);
}
template<class Iter, class Sent = Iter>
void
test_iter_comp(Iter first, Sent last)
{
Iter i = ranges::max_element(first, last, std::greater<int>());
if (first != last)
{
for (Iter j = first; j != last; ++j)
CHECK(!std::greater<int>()(*i, *j));
}
else
CHECK(i == last);
auto rng = ::MakeTestRange(first, last);
i = ranges::max_element(rng, std::greater<int>());
if (first != last)
{
for (Iter j = first; j != last; ++j)
CHECK(!std::greater<int>()(*i, *j));
}
else
CHECK(i == last);
auto res = ranges::max_element(std::move(rng), std::greater<int>());
CHECK(::is_dangling(res));
}
template<class Iter, class Sent = Iter>
void
test_iter_comp(unsigned N)
{
std::unique_ptr<int[]> a{new int[N]};
std::iota(a.get(), a.get()+N, 0);
std::shuffle(a.get(), a.get()+N, gen);
test_iter_comp(Iter(a.get()), Sent(a.get()+N));
}
template<class Iter, class Sent = Iter>
void
test_iter_comp()
{
test_iter_comp<Iter, Sent>(0);
test_iter_comp<Iter, Sent>(1);
test_iter_comp<Iter, Sent>(2);
test_iter_comp<Iter, Sent>(3);
test_iter_comp<Iter, Sent>(10);
test_iter_comp<Iter, Sent>(1000);
}
struct S
{
int i;
};
}
int main()
{
test_iter<ForwardIterator<const int*> >();
test_iter<BidirectionalIterator<const int*> >();
test_iter<RandomAccessIterator<const int*> >();
test_iter<const int*>();
test_iter<ForwardIterator<const int*>, Sentinel<const int*>>();
test_iter<BidirectionalIterator<const int*>, Sentinel<const int*>>();
test_iter<RandomAccessIterator<const int*>, Sentinel<const int*>>();
test_iter_comp<ForwardIterator<const int*> >();
test_iter_comp<BidirectionalIterator<const int*> >();
test_iter_comp<RandomAccessIterator<const int*> >();
test_iter_comp<const int*>();
test_iter_comp<ForwardIterator<const int*>, Sentinel<const int*>>();
test_iter_comp<BidirectionalIterator<const int*>, Sentinel<const int*>>();
test_iter_comp<RandomAccessIterator<const int*>, Sentinel<const int*>>();
// Works with projections?
S s[] = {S{1},S{2},S{3},S{4},S{40},S{5},S{6},S{7},S{8},S{9}};
S const *ps = ranges::max_element(s, std::less<int>{}, &S::i);
CHECK(ps->i == 40);
{
constexpr auto a = test::array<int, 10>{{1, 2, 3, 4, 40, 5, 6, 7, 8, 9}};
STATIC_CHECK(ranges::max_element(a) == ranges::begin(a) + 4);
}
return test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/is_heap1.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#define IS_HEAP_1
#include "./is_heap.hpp"
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/unique.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright 2005 - 2007 Adobe Systems Incorporated
// Distributed under the MIT License(see accompanying file LICENSE_1_0_0.txt
// or a copy at http://stlab.adobe.com/licenses.html)
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Implementation based on the code in libc++
// http://http://libcxx.llvm.org/
#include <vector>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/unique.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
/// Calls the iterator interface of the algorithm
template<class Iter>
struct iter_call
{
using begin_t = Iter;
using sentinel_t = typename sentinel_type<Iter>::type;
template<class B, class E, class... Args>
auto operator()(B &&It, E &&e, Args &&... args) const
-> decltype(ranges::unique(begin_t{It}, sentinel_t{e}, std::forward<Args>(args)...))
{
return ranges::unique(begin_t{It}, sentinel_t{e}, std::forward<Args>(args)...);
}
};
/// Calls the range interface of the algorithm
template<class Iter>
struct range_call
{
using begin_t = Iter;
using sentinel_t = typename sentinel_type<Iter>::type;
template<class B, class E, class... Args>
auto operator()(B &&It, E &&e, Args &&... args) const
-> ranges::iterator_t<decltype(ranges::make_subrange(begin_t{It}, sentinel_t{e}))>
{
auto rng = ranges::make_subrange(begin_t{It}, sentinel_t{e});
return ranges::unique(rng, std::forward<Args>(args)...);
}
};
template<class T> using identity_t = T;
template<class It, template<class> class FunT>
void test()
{
using Fun = FunT<It>;
{
int a[] = {0};
const unsigned sa = sizeof(a) / sizeof(a[0]);
auto r = Fun{}(a, a + sa);
CHECK(r == It(a + sa));
CHECK(a[0] == 0);
}
{
int a[] = {0, 1};
const unsigned sa = sizeof(a) / sizeof(a[0]);
auto r = Fun{}(a, a + sa);
CHECK(r == It(a + sa));
CHECK(a[0] == 0);
CHECK(a[1] == 1);
}
{
int a[] = {0, 0};
const unsigned sa = sizeof(a) / sizeof(a[0]);
auto r = Fun{}(a, a + sa);
CHECK(r == It(a + 1));
CHECK(a[0] == 0);
}
{
int a[] = {0, 0, 1};
const unsigned sa = sizeof(a) / sizeof(a[0]);
auto r = Fun{}(a, a + sa);
CHECK(r == It(a + 2));
CHECK(a[0] == 0);
CHECK(a[1] == 1);
}
{
int a[] = {0, 0, 1, 0};
const unsigned sa = sizeof(a) / sizeof(a[0]);
auto r = Fun{}(a, a + sa);
CHECK(r == It(a + 3));
CHECK(a[0] == 0);
CHECK(a[1] == 1);
CHECK(a[2] == 0);
}
{
int a[] = {0, 0, 1, 1};
const unsigned sa = sizeof(a) / sizeof(a[0]);
auto r = Fun{}(a, a + sa);
CHECK(r == It(a + 2));
CHECK(a[0] == 0);
CHECK(a[1] == 1);
}
{
int a[] = {0, 1, 1};
const unsigned sa = sizeof(a) / sizeof(a[0]);
auto r = Fun{}(a, a + sa);
CHECK(r == It(a + 2));
CHECK(a[0] == 0);
CHECK(a[1] == 1);
}
{
int a[] = {0, 1, 1, 1, 2, 2, 2};
const unsigned sa = sizeof(a) / sizeof(a[0]);
auto r = Fun{}(a, a + sa);
CHECK(r == It(a + 3));
CHECK(a[0] == 0);
CHECK(a[1] == 1);
CHECK(a[2] == 2);
}
}
constexpr bool test_constexpr()
{
using namespace ranges;
int a[] = {0, 1, 1, 1, 2, 2, 2};
const unsigned sa = sizeof(a) / sizeof(a[0]);
auto r = unique(a, a + sa);
STATIC_CHECK_RETURN(r == a + 3);
STATIC_CHECK_RETURN(a[0] == 0);
STATIC_CHECK_RETURN(a[1] == 1);
STATIC_CHECK_RETURN(a[2] == 2);
return true;
}
int main()
{
test<ForwardIterator<int*>, iter_call>();
test<BidirectionalIterator<int*>, iter_call>();
test<RandomAccessIterator<int*>, iter_call>();
test<int*, iter_call>();
test<ForwardIterator<int*>, range_call>();
test<BidirectionalIterator<int*>, range_call>();
test<RandomAccessIterator<int*>, range_call>();
test<int*, range_call>();
// Test rvalue range
{
int a[] = {0, 1, 1, 1, 2, 2, 2};
auto r = ranges::unique(ranges::views::all(a));
CHECK(r == a + 3);
CHECK(a[0] == 0);
CHECK(a[1] == 1);
CHECK(a[2] == 2);
}
{
int a[] = {0, 1, 1, 1, 2, 2, 2};
auto r = ranges::unique(std::move(a));
#ifndef RANGES_WORKAROUND_MSVC_573728
CHECK(::is_dangling(r));
#endif // RANGES_WORKAROUND_MSVC_573728
CHECK(a[0] == 0);
CHECK(a[1] == 1);
CHECK(a[2] == 2);
}
{
std::vector<int> a{0, 1, 1, 1, 2, 2, 2};
auto r = ranges::unique(std::move(a));
CHECK(::is_dangling(r));
CHECK(a[0] == 0);
CHECK(a[1] == 1);
CHECK(a[2] == 2);
}
{
STATIC_CHECK(test_constexpr());
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/sort.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <memory>
#include <random>
#include <vector>
#include <algorithm>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/sort.hpp>
#include <range/v3/algorithm/copy.hpp>
#include <range/v3/view/for_each.hpp>
#include <range/v3/view/iota.hpp>
#include <range/v3/view/repeat_n.hpp>
#include <range/v3/view/reverse.hpp>
#include <range/v3/view/zip.hpp>
#include <range/v3/view/transform.hpp>
#include <range/v3/range/conversion.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
RANGES_DIAGNOSTIC_IGNORE_GLOBAL_CONSTRUCTORS
RANGES_DIAGNOSTIC_IGNORE_SIGN_CONVERSION
RANGES_DIAGNOSTIC_IGNORE_UNNEEDED_INTERNAL
// BUGBUG
namespace std
{
template<typename F, typename S>
std::ostream & operator<<(std::ostream &sout, std::pair<F,S> const & p)
{
return sout << '[' << p.first << ',' << p.second << ']';
}
}
namespace
{
std::mt19937 gen;
struct indirect_less
{
template<class P>
bool operator()(const P& x, const P& y)
{return *x < *y;}
};
template<class RI>
void
test_sort_helper(RI f, RI l)
{
using value_type = ranges::iter_value_t<RI>;
auto sort = make_testable_1<false>(ranges::sort);
if (f != l)
{
auto len = l - f;
value_type* save(new value_type[len]);
do
{
std::copy(f, l, save);
sort(save, save+len).check([&](int *res)
{
CHECK(res == save+len);
CHECK(std::is_sorted(save, save+len));
std::copy(f, l, save);
});
sort(save, save+len, std::greater<int>{}).check([&](int *res)
{
CHECK(res == save+len);
CHECK(std::is_sorted(save, save+len, std::greater<int>{}));
std::copy(f, l, save);
});
} while (std::next_permutation(f, l));
delete [] save;
}
}
template<class RI>
void
test_sort_driver_driver(RI f, RI l, int start, RI real_last)
{
for (RI i = l; i > f + start;)
{
*--i = start;
if (f == i)
{
test_sort_helper(f, real_last);
}
if (start > 0)
test_sort_driver_driver(f, i, start-1, real_last);
}
}
template<class RI>
void
test_sort_driver(RI f, RI l, int start)
{
test_sort_driver_driver(f, l, start, l);
}
template<int sa>
void
test_sort_()
{
int ia[sa];
for (int i = 0; i < sa; ++i)
{
test_sort_driver(ia, ia+sa, i);
}
}
void
test_larger_sorts(int N, int M)
{
RANGES_ENSURE(N > 0);
RANGES_ENSURE(M > 0);
// create array length N filled with M different numbers
int* array = new int[N];
int x = 0;
for (int i = 0; i < N; ++i)
{
array[i] = x;
if (++x == M)
x = 0;
}
// test saw tooth pattern
CHECK(ranges::sort(array, array+N) == array+N);
CHECK(std::is_sorted(array, array+N));
// test random pattern
std::shuffle(array, array+N, gen);
CHECK(ranges::sort(array, array+N) == array+N);
CHECK(std::is_sorted(array, array+N));
// test sorted pattern
CHECK(ranges::sort(array, array+N) == array+N);
CHECK(std::is_sorted(array, array+N));
// test reverse sorted pattern
std::reverse(array, array+N);
CHECK(ranges::sort(array, array+N) == array+N);
CHECK(std::is_sorted(array, array+N));
// test swap ranges 2 pattern
std::swap_ranges(array, array+N/2, array+N/2);
CHECK(ranges::sort(array, array+N) == array+N);
CHECK(std::is_sorted(array, array+N));
// test reverse swap ranges 2 pattern
std::reverse(array, array+N);
std::swap_ranges(array, array+N/2, array+N/2);
CHECK(ranges::sort(array, array+N) == array+N);
CHECK(std::is_sorted(array, array+N));
delete [] array;
}
void
test_larger_sorts(unsigned N)
{
test_larger_sorts(N, 1);
test_larger_sorts(N, 2);
test_larger_sorts(N, 3);
test_larger_sorts(N, N/2-1);
test_larger_sorts(N, N/2);
test_larger_sorts(N, N/2+1);
test_larger_sorts(N, N-2);
test_larger_sorts(N, N-1);
test_larger_sorts(N, N);
}
struct S
{
int i, j;
};
struct Int
{
using difference_type = int;
int i_;
Int(int i = 0) : i_(i) {}
Int(Int && that) : i_(that.i_) { that.i_ = 0; }
Int(Int const &) = delete;
Int & operator=(Int && that)
{
i_ = that.i_;
that.i_ = 0;
return *this;
}
friend bool operator==(Int const &a, Int const &b)
{
return a.i_ == b.i_;
}
friend bool operator!=(Int const &a, Int const &b)
{
return !(a == b);
}
friend bool operator<(Int const &a, Int const &b)
{
return a.i_ < b.i_;
}
friend bool operator>(Int const &a, Int const &b)
{
return a.i_ > b.i_;
}
friend bool operator<=(Int const &a, Int const &b)
{
return a.i_ <= b.i_;
}
friend bool operator>=(Int const &a, Int const &b)
{
return a.i_ >= b.i_;
}
};
CPP_assert(ranges::default_constructible<Int>);
CPP_assert(ranges::movable<Int>);
CPP_assert(ranges::totally_ordered<Int>);
}
int main()
{
// test null range
int d = 0;
ranges::sort(&d, &d);
// exhaustively test all possibilities up to length 8
test_sort_<1>();
test_sort_<2>();
test_sort_<3>();
test_sort_<4>();
test_sort_<5>();
test_sort_<6>();
test_sort_<7>();
test_sort_<8>();
test_larger_sorts(15);
test_larger_sorts(16);
test_larger_sorts(17);
test_larger_sorts(256);
test_larger_sorts(257);
test_larger_sorts(499);
test_larger_sorts(500);
test_larger_sorts(997);
test_larger_sorts(1000);
test_larger_sorts(1009);
// Check move-only types
{
std::vector<std::unique_ptr<int> > v(1000);
for(int i = 0; (std::size_t)i < v.size(); ++i)
v[i].reset(new int((int)v.size() - i - 1));
ranges::sort(v, indirect_less());
for(int i = 0; (std::size_t)i < v.size(); ++i)
CHECK(*v[i] == i);
}
// Check projections
{
std::vector<S> v(1000, S{});
for(int i = 0; (std::size_t)i < v.size(); ++i)
{
v[i].i = (int)v.size() - i - 1;
v[i].j = i;
}
ranges::sort(v, std::less<int>{}, &S::i);
for(int i = 0; (std::size_t)i < v.size(); ++i)
{
CHECK(v[i].i == i);
CHECK((std::size_t)v[i].j == v.size() - i - 1);
}
}
// Check rvalue range
{
std::vector<S> v(1000, S{});
for(int i = 0; (std::size_t)i < v.size(); ++i)
{
v[i].i = (int)v.size() - i - 1;
v[i].j = i;
}
CHECK(ranges::sort(ranges::views::all(v), std::less<int>{}, &S::i) == v.end());
for(int i = 0; (std::size_t)i < v.size(); ++i)
{
CHECK(v[i].i == i);
CHECK((std::size_t)v[i].j == v.size() - i - 1);
}
}
{
std::vector<S> v(1000, S{});
for(int i = 0; (std::size_t)i < v.size(); ++i)
{
v[i].i = (int)v.size() - i - 1;
v[i].j = i;
}
CHECK(::is_dangling(ranges::sort(std::move(v), std::less<int>{}, &S::i)));
for(int i = 0; (std::size_t)i < v.size(); ++i)
{
CHECK(v[i].i == i);
CHECK((std::size_t)v[i].j == v.size() - i - 1);
}
}
// Check sorting a zip view, which uses iter_move
{
using namespace ranges;
auto v0 =
views::for_each(views::ints(1,6) | views::reverse, [](int i){
return ranges::yield_from(views::repeat_n(i,i));
}) | to<std::vector>();
auto v1 = ranges::to<std::vector<Int>>(
{1,2,2,3,3,3,4,4,4,4,5,5,5,5,5});
auto rng = views::zip(v0, v1);
::check_equal(v0,{5,5,5,5,5,4,4,4,4,3,3,3,2,2,1});
::check_equal(v1,{1,2,2,3,3,3,4,4,4,4,5,5,5,5,5});
using Rng = decltype(rng);
using CR = range_common_reference_t<Rng>;
auto proj = [](CR r) { return r; };
auto pred = [](CR r1, CR r2) { return r1 < r2; };
sort(rng, pred, proj);
::check_equal(v0,{1,2,2,3,3,3,4,4,4,4,5,5,5,5,5});
::check_equal(v1,{5,5,5,4,5,5,3,4,4,4,1,2,2,3,3});
// Check that this compiles, too:
sort(rng);
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/set_symmetric_difference2.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#define SET_SYMMETRIC_DIFFERENCE_2
#include "./set_symmetric_difference.hpp"
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/for_each.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#include <vector>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/for_each.hpp>
#include "../array.hpp"
#include "../simple_test.hpp"
#include "../test_iterators.hpp"
struct S
{
void p() const { *p_ += i_; }
int *p_;
int i_;
};
constexpr int void_f(int const &)
{
return 3;
}
int main()
{
int sum = 0;
auto fun = [&](int i){sum += i; };
std::vector<int> v1 { 0, 2, 4, 6 };
CHECK(ranges::for_each(v1.begin(), v1.end(), fun).in == v1.end());
CHECK(ranges::for_each(v1, fun).in == v1.end());
CHECK(sum == 24);
sum = 0;
auto rfun = [&](int & i){sum += i; };
CHECK(ranges::for_each(v1.begin(), v1.end(), rfun).in == v1.end());
CHECK(ranges::for_each(v1, rfun).in == v1.end());
CHECK(sum == 24);
sum = 0;
std::vector<S> v2{{&sum, 0}, {&sum, 2}, {&sum, 4}, {&sum, 6}};
CHECK(ranges::for_each(v2.begin(), v2.end(), &S::p).in == v2.end());
CHECK(ranges::for_each(v2, &S::p).in == v2.end());
CHECK(sum == 24);
sum = 0;
CHECK(::is_dangling(ranges::for_each(::MakeTestRange(v1.begin(), v1.end()), fun).in));
CHECK(sum == 12);
{
constexpr auto rng = test::array<int, 4>{{0, 2, 4, 6}};
STATIC_CHECK(ranges::for_each(rng, void_f).in == ranges::end(rng));
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/count.cpp | // Range v3 library
//
// Copyright Andrew Sutton 2014
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#include <range/v3/core.hpp>
#include <range/v3/algorithm/count.hpp>
#include "../simple_test.hpp"
#include "../test_iterators.hpp"
struct S
{
int i;
};
int main()
{
using namespace ranges;
int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
constexpr auto cia = size(ia);
CHECK(count(InputIterator<const int*>(ia),
Sentinel<const int*>(ia + cia), 2) == 3);
CHECK(count(InputIterator<const int*>(ia),
Sentinel<const int*>(ia + cia), 7) == 0);
CHECK(count(InputIterator<const int*>(ia),
Sentinel<const int*>(ia), 2) == 0);
CHECK(count(make_subrange(InputIterator<const int*>(ia),
Sentinel<const int*>(ia + cia)), 2) == 3);
CHECK(count(make_subrange(InputIterator<const int*>(ia),
Sentinel<const int*>(ia + cia)), 7) == 0);
CHECK(count(make_subrange(InputIterator<const int*>(ia),
Sentinel<const int*>(ia)), 2) == 0);
S sa[] = {{0}, {1}, {2}, {2}, {0}, {1}, {2}, {3}};
constexpr auto csa = size(ia);
CHECK(count(InputIterator<const S*>(sa),
Sentinel<const S*>(sa + csa), 2, &S::i) == 3);
CHECK(count(InputIterator<const S*>(sa),
Sentinel<const S*>(sa + csa), 7, &S::i) == 0);
CHECK(count(InputIterator<const S*>(sa),
Sentinel<const S*>(sa), 2, &S::i) == 0);
CHECK(count(make_subrange(InputIterator<const S*>(sa),
Sentinel<const S*>(sa + csa)), 2, &S::i) == 3);
CHECK(count(make_subrange(InputIterator<const S*>(sa),
Sentinel<const S*>(sa + csa)), 7, &S::i) == 0);
CHECK(count(make_subrange(InputIterator<const S*>(sa),
Sentinel<const S*>(sa)), 2, &S::i) == 0);
{
using IL = std::initializer_list<int>;
STATIC_CHECK(ranges::count(IL{0, 1, 2, 1, 3, 1, 4}, 1) == 3);
STATIC_CHECK(ranges::count(IL{0, 1, 2, 1, 3, 1, 4}, 5) == 0);
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/set_difference6.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#define SET_DIFFERENCE_6
#include "./set_difference.hpp"
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/copy_if.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#include <range/v3/algorithm/copy_if.hpp>
#include "../array.hpp"
#include "../simple_test.hpp"
constexpr bool is_even(int i)
{
return i % 2 == 0;
}
constexpr bool test_constexpr()
{
using namespace ranges;
test::array<int, 4> a{{1, 2, 3, 4}};
test::array<int, 4> b{{0, 0, 0, 0}};
const auto res = copy_if(a, ranges::begin(b), is_even);
STATIC_CHECK_RETURN(res.in == end(a));
STATIC_CHECK_RETURN(res.out == begin(b) + 2);
STATIC_CHECK_RETURN(a[0] == 1);
STATIC_CHECK_RETURN(a[1] == 2);
STATIC_CHECK_RETURN(a[2] == 3);
STATIC_CHECK_RETURN(a[3] == 4);
STATIC_CHECK_RETURN(b[0] == 2);
STATIC_CHECK_RETURN(b[1] == 4);
STATIC_CHECK_RETURN(b[2] == 0);
STATIC_CHECK_RETURN(b[3] == 0);
return true;
}
int main()
{
STATIC_CHECK(test_constexpr());
return test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/minmax_element.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <memory>
#include <numeric>
#include <random>
#include <algorithm>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/minmax_element.hpp>
#include "../array.hpp"
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
RANGES_DIAGNOSTIC_IGNORE_GLOBAL_CONSTRUCTORS
namespace
{
std::mt19937 gen;
template<class Iter, class Sent = Iter>
void
test_iter(Iter first, Sent last)
{
ranges::minmax_element_result<Iter> p = ranges::minmax_element(first, last);
if (first != last)
{
for (Iter j = first; j != last; ++j)
{
CHECK(!(*j < *p.min));
CHECK(!(*p.max < *j));
}
}
else
{
CHECK(p.min == last);
CHECK(p.max == last);
}
auto rng = ::MakeTestRange(first, last);
p = ranges::minmax_element(rng);
if (first != last)
{
for (Iter j = first; j != last; ++j)
{
CHECK(!(*j < *p.min));
CHECK(!(*p.max < *j));
}
}
else
{
CHECK(p.min == last);
CHECK(p.max == last);
}
auto res = ranges::minmax_element(std::move(rng));
if (first != last)
{
for (Iter j = first; j != last; ++j)
{
CHECK(is_dangling(res.min));
CHECK(!(*p.max < *j));
}
}
else
{
CHECK(is_dangling(res.min));
CHECK(is_dangling(res.max));
}
}
template<class Iter, class Sent = Iter>
void
test_iter(unsigned N)
{
std::unique_ptr<int[]> a{new int[N]};
std::iota(a.get(), a.get()+N, 0);
std::shuffle(a.get(), a.get()+N, gen);
test_iter(Iter(a.get()), Sent(a.get()+N));
}
template<class Iter, class Sent = Iter>
void
test_iter()
{
test_iter<Iter, Sent>(0);
test_iter<Iter, Sent>(1);
test_iter<Iter, Sent>(2);
test_iter<Iter, Sent>(3);
test_iter<Iter, Sent>(10);
test_iter<Iter, Sent>(1000);
{
const unsigned N = 100;
std::unique_ptr<int[]> a{new int[N]};
std::fill_n(a.get(), N, 5);
std::shuffle(a.get(), a.get()+N, gen);
ranges::minmax_element_result<Iter> p = ranges::minmax_element(Iter(a.get()), Sent(a.get()+N));
CHECK(base(p.min) == a.get());
CHECK(base(p.max) == a.get()+N-1);
}
}
template<class Iter, class Sent = Iter>
void
test_iter_comp(Iter first, Sent last)
{
typedef std::greater<int> Compare;
Compare comp;
ranges::minmax_element_result<Iter> p = ranges::minmax_element(first, last, comp);
if (first != last)
{
for (Iter j = first; j != last; ++j)
{
CHECK(!comp(*j, *p.min));
CHECK(!comp(*p.max, *j));
}
}
else
{
CHECK(p.min == last);
CHECK(p.max == last);
}
auto rng = ::MakeTestRange(first, last);
p = ranges::minmax_element(rng, comp);
if (first != last)
{
for (Iter j = first; j != last; ++j)
{
CHECK(!comp(*j, *p.min));
CHECK(!comp(*p.max, *j));
}
}
else
{
CHECK(p.min == last);
CHECK(p.max == last);
}
auto res = ranges::minmax_element(std::move(rng), comp);
CHECK(is_dangling(res.min));
CHECK(is_dangling(res.max));
}
template<class Iter, class Sent = Iter>
void
test_iter_comp(unsigned N)
{
std::unique_ptr<int[]> a{new int[N]};
std::iota(a.get(), a.get()+N, 0);
std::shuffle(a.get(), a.get()+N, gen);
test_iter_comp(Iter(a.get()), Sent(a.get()+N));
}
template<class Iter, class Sent = Iter>
void
test_iter_comp()
{
test_iter_comp<Iter, Sent>(0);
test_iter_comp<Iter, Sent>(1);
test_iter_comp<Iter, Sent>(2);
test_iter_comp<Iter, Sent>(3);
test_iter_comp<Iter, Sent>(10);
test_iter_comp<Iter, Sent>(1000);
{
const unsigned N = 100;
std::unique_ptr<int[]> a{new int[N]};
std::fill_n(a.get(), N, 5);
std::shuffle(a.get(), a.get()+N, gen);
typedef std::greater<int> Compare;
Compare comp;
ranges::minmax_element_result<Iter> p = ranges::minmax_element(Iter(a.get()), Sent(a.get()+N), comp);
CHECK(base(p.min) == a.get());
CHECK(base(p.max) == a.get()+N-1);
}
}
struct S
{
int i;
};
}
int main()
{
test_iter<ForwardIterator<const int*> >();
test_iter<BidirectionalIterator<const int*> >();
test_iter<RandomAccessIterator<const int*> >();
test_iter<const int*>();
test_iter<ForwardIterator<const int*>, Sentinel<const int*>>();
test_iter<BidirectionalIterator<const int*>, Sentinel<const int*>>();
test_iter<RandomAccessIterator<const int*>, Sentinel<const int*>>();
test_iter<ForwardIterator<const int*> >();
test_iter<BidirectionalIterator<const int*> >();
test_iter<RandomAccessIterator<const int*> >();
test_iter<const int*>();
test_iter<ForwardIterator<const int*>, Sentinel<const int*>>();
test_iter<BidirectionalIterator<const int*>, Sentinel<const int*>>();
test_iter<RandomAccessIterator<const int*>, Sentinel<const int*>>();
test_iter_comp<ForwardIterator<const int*> >();
test_iter_comp<BidirectionalIterator<const int*> >();
test_iter_comp<RandomAccessIterator<const int*> >();
test_iter_comp<const int*>();
test_iter_comp<ForwardIterator<const int*>, Sentinel<const int*>>();
test_iter_comp<BidirectionalIterator<const int*>, Sentinel<const int*>>();
test_iter_comp<RandomAccessIterator<const int*>, Sentinel<const int*>>();
test_iter_comp<ForwardIterator<const int*> >();
test_iter_comp<BidirectionalIterator<const int*> >();
test_iter_comp<RandomAccessIterator<const int*> >();
test_iter_comp<const int*>();
test_iter_comp<ForwardIterator<const int*>, Sentinel<const int*>>();
test_iter_comp<BidirectionalIterator<const int*>, Sentinel<const int*>>();
test_iter_comp<RandomAccessIterator<const int*>, Sentinel<const int*>>();
// Works with projections?
S s[] = {S{1},S{2},S{3},S{4},S{-4},S{5},S{6},S{40},S{7},S{8},S{9}};
ranges::minmax_element_result<S const *> ps = ranges::minmax_element(s, std::less<int>{}, &S::i);
CHECK(ps.min->i == -4);
CHECK(ps.max->i == 40);
{
constexpr auto a = test::array<int, 10>{{1, 2, 3, 4, -4, 5, 6, 40, 8, 9}};
STATIC_CHECK(ranges::minmax_element(a).min == ranges::begin(a) + 4);
STATIC_CHECK(ranges::minmax_element(a).max == ranges::begin(a) + 7);
}
return test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/set_intersection3.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#define SET_INTERSECTION_3
#include "./set_intersection.hpp"
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/is_heap_until4.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#define IS_HEAP_UNTIL_4
#include "./is_heap_until.hpp"
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/push_heap.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright 2005 - 2007 Adobe Systems Incorporated
// Distributed under the MIT License(see accompanying file LICENSE_1_0_0.txt
// or a copy at http://stlab.adobe.com/licenses.html)
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <algorithm>
// template<random_access_iterator Iter>
// requires ShuffleIterator<Iter>
// && LessThanComparable<Iter::value_type>
// void
// push_heap(Iter first, Iter last);
#include <memory>
#include <random>
#include <algorithm>
#include <functional>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/heap_algorithm.hpp>
#include "../array.hpp"
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
RANGES_DIAGNOSTIC_IGNORE_GLOBAL_CONSTRUCTORS
RANGES_DIAGNOSTIC_IGNORE_SIGN_CONVERSION
namespace
{
std::mt19937 gen;
void test_basic(int N)
{
auto push_heap = make_testable_1(ranges::push_heap);
int* ia = new int[N];
for (int i = 0; i < N; ++i)
ia[i] = i;
std::shuffle(ia, ia+N, gen);
for (int i = 0; i <= N; ++i)
{
push_heap(ia, ia+i).check([&](int *r){CHECK(r == ia + i);});
CHECK(std::is_heap(ia, ia+i));
}
delete[] ia;
}
void test_comp(int N)
{
auto push_heap = make_testable_1(ranges::push_heap);
int* ia = new int[N];
for (int i = 0; i < N; ++i)
ia[i] = i;
std::shuffle(ia, ia+N, gen);
for (int i = 0; i <= N; ++i)
{
push_heap(ia, ia+i, std::greater<int>()).check([&](int *r){CHECK(r == ia+i);});
CHECK(std::is_heap(ia, ia+i, std::greater<int>()));
}
delete[] ia;
}
struct S
{
int i;
};
void test_proj(int N)
{
auto push_heap = make_testable_1(ranges::push_heap);
S* ia = new S[N];
int* ib = new int[N];
for (int i = 0; i < N; ++i)
ia[i].i = i;
std::shuffle(ia, ia+N, gen);
for (int i = 0; i <= N; ++i)
{
push_heap(ia, ia+i, std::greater<int>(), &S::i).check([&](S *r){CHECK(r == ia+i);});
std::transform(ia, ia+i, ib, std::mem_fn(&S::i));
CHECK(std::is_heap(ib, ib+i, std::greater<int>()));
}
delete[] ia;
delete[] ib;
}
struct indirect_less
{
template<class P>
bool operator()(const P& x, const P& y)
{return *x < *y;}
};
void test_move_only(int N)
{
auto const push_heap = make_testable_1(ranges::push_heap);
std::unique_ptr<int>* ia = new std::unique_ptr<int>[N];
for (int i = 0; i < N; ++i)
ia[i].reset(new int(i));
std::shuffle(ia, ia+N, gen);
for (int i = 0; i <= N; ++i)
{
push_heap(ia, ia+i, indirect_less()).check([&](std::unique_ptr<int> *r){CHECK(r == ia+i);});
CHECK(std::is_heap(ia, ia+i, indirect_less()));
}
delete[] ia;
}
}
constexpr bool test_constexpr()
{
using namespace ranges;
constexpr int N = 100;
test::array<int, N> ia{{0}};
for(int i = 0; i < N; ++i)
ia[i] = i;
for(int i = 0; i <= N; ++i)
{
STATIC_CHECK_RETURN(push_heap(make_subrange(begin(ia), begin(ia) + i),
std::greater<int>()) == begin(ia) + i);
STATIC_CHECK_RETURN(is_heap(begin(ia), begin(ia) + i, std::greater<int>()));
}
return true;
}
int main()
{
test_basic(1000);
test_comp(1000);
test_proj(1000);
test_move_only(1000);
{
int const N = 1000;
S* ia = new S[N];
int* ib = new int[N];
for (int i = 0; i < N; ++i)
ia[i].i = i;
std::shuffle(ia, ia+N, gen);
for (int i = 0; i <= N; ++i)
{
CHECK(ranges::push_heap(ranges::make_subrange(ia, ia+i), std::greater<int>(), &S::i) == ia+i);
std::transform(ia, ia+i, ib, std::mem_fn(&S::i));
CHECK(std::is_heap(ib, ib+i, std::greater<int>()));
}
delete[] ia;
delete[] ib;
}
{
STATIC_CHECK(test_constexpr());
}
return test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/unique_copy.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright 2005 - 2007 Adobe Systems Incorporated
// Distributed under the MIT License(see accompanying file LICENSE_1_0_0.txt
// or a copy at http://stlab.adobe.com/licenses.html)
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Implementation based on the code in libc++
// http://http://libcxx.llvm.org/
#include <cstring>
#include <vector>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/unique_copy.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
struct count_equal
{
static unsigned count;
template<class T>
bool operator()(const T& x, const T& y)
{++count; return x == y;}
};
unsigned count_equal::count = 0;
template<class InIter, class OutIter, typename Sent = InIter>
void
test_iter()
{
const int ia[] = {0};
const unsigned sa = sizeof(ia)/sizeof(ia[0]);
int ja[sa] = {-1};
count_equal::count = 0;
ranges::unique_copy_result<InIter, OutIter> r = ranges::unique_copy(InIter(ia), Sent(ia+sa), OutIter(ja), count_equal());
CHECK(base(r.in) == ia + sa);
CHECK(base(r.out) == ja + sa);
CHECK(ja[0] == 0);
CHECK(count_equal::count == sa-1);
const int ib[] = {0, 1};
const unsigned sb = sizeof(ib)/sizeof(ib[0]);
int jb[sb] = {-1};
count_equal::count = 0;
r = ranges::unique_copy(InIter(ib), Sent(ib+sb), OutIter(jb), count_equal());
CHECK(base(r.in) == ib + sb);
CHECK(base(r.out) == jb + sb);
CHECK(jb[0] == 0);
CHECK(jb[1] == 1);
CHECK(count_equal::count == sb-1);
const int ic[] = {0, 0};
const unsigned sc = sizeof(ic)/sizeof(ic[0]);
int jc[sc] = {-1};
count_equal::count = 0;
r = ranges::unique_copy(InIter(ic), Sent(ic+sc), OutIter(jc), count_equal());
CHECK(base(r.in) == ic + sc);
CHECK(base(r.out) == jc + 1);
CHECK(jc[0] == 0);
CHECK(count_equal::count == sc-1);
const int id[] = {0, 0, 1};
const unsigned sd = sizeof(id)/sizeof(id[0]);
int jd[sd] = {-1};
count_equal::count = 0;
r = ranges::unique_copy(InIter(id), Sent(id+sd), OutIter(jd), count_equal());
CHECK(base(r.in) == id + sd);
CHECK(base(r.out) == jd + 2);
CHECK(jd[0] == 0);
CHECK(jd[1] == 1);
CHECK(count_equal::count == sd-1);
const int ie[] = {0, 0, 1, 0};
const unsigned se = sizeof(ie)/sizeof(ie[0]);
int je[se] = {-1};
count_equal::count = 0;
r = ranges::unique_copy(InIter(ie), Sent(ie+se), OutIter(je), count_equal());
CHECK(base(r.in) == ie + se);
CHECK(base(r.out) == je + 3);
CHECK(je[0] == 0);
CHECK(je[1] == 1);
CHECK(je[2] == 0);
CHECK(count_equal::count == se-1);
const int ig[] = {0, 0, 1, 1};
const unsigned sg = sizeof(ig)/sizeof(ig[0]);
int jg[sg] = {-1};
count_equal::count = 0;
r = ranges::unique_copy(InIter(ig), Sent(ig+sg), OutIter(jg), count_equal());
CHECK(base(r.in) == ig + sg);
CHECK(base(r.out) == jg + 2);
CHECK(jg[0] == 0);
CHECK(jg[1] == 1);
CHECK(count_equal::count == sg-1);
const int ih[] = {0, 1, 1};
const unsigned sh = sizeof(ih)/sizeof(ih[0]);
int jh[sh] = {-1};
count_equal::count = 0;
r = ranges::unique_copy(InIter(ih), Sent(ih+sh), OutIter(jh), count_equal());
CHECK(base(r.in) == ih + sh);
CHECK(base(r.out) == jh + 2);
CHECK(jh[0] == 0);
CHECK(jh[1] == 1);
CHECK(count_equal::count == sh-1);
const int ii[] = {0, 1, 1, 1, 2, 2, 2};
const unsigned si = sizeof(ii)/sizeof(ii[0]);
int ji[si] = {-1};
count_equal::count = 0;
r = ranges::unique_copy(InIter(ii), Sent(ii+si), OutIter(ji), count_equal());
CHECK(base(r.in) == ii + si);
CHECK(base(r.out) == ji + 3);
CHECK(ji[0] == 0);
CHECK(ji[1] == 1);
CHECK(ji[2] == 2);
CHECK(count_equal::count == si-1);
}
template<class InIter, class OutIter, typename Sent = InIter>
void
test_range()
{
const int ia[] = {0};
const unsigned sa = sizeof(ia)/sizeof(ia[0]);
int ja[sa] = {-1};
count_equal::count = 0;
ranges::unique_copy_result<InIter, OutIter> r = ranges::unique_copy(::as_lvalue(ranges::make_subrange(InIter(ia), Sent(ia+sa))), OutIter(ja), count_equal());
CHECK(base(r.in) == ia + sa);
CHECK(base(r.out) == ja + sa);
CHECK(ja[0] == 0);
CHECK(count_equal::count == sa-1);
const int ib[] = {0, 1};
const unsigned sb = sizeof(ib)/sizeof(ib[0]);
int jb[sb] = {-1};
count_equal::count = 0;
r = ranges::unique_copy(::as_lvalue(ranges::make_subrange(InIter(ib), Sent(ib+sb))), OutIter(jb), count_equal());
CHECK(base(r.in) == ib + sb);
CHECK(base(r.out) == jb + sb);
CHECK(jb[0] == 0);
CHECK(jb[1] == 1);
CHECK(count_equal::count == sb-1);
const int ic[] = {0, 0};
const unsigned sc = sizeof(ic)/sizeof(ic[0]);
int jc[sc] = {-1};
count_equal::count = 0;
r = ranges::unique_copy(::as_lvalue(ranges::make_subrange(InIter(ic), Sent(ic+sc))), OutIter(jc), count_equal());
CHECK(base(r.in) == ic + sc);
CHECK(base(r.out) == jc + 1);
CHECK(jc[0] == 0);
CHECK(count_equal::count == sc-1);
const int id[] = {0, 0, 1};
const unsigned sd = sizeof(id)/sizeof(id[0]);
int jd[sd] = {-1};
count_equal::count = 0;
r = ranges::unique_copy(::as_lvalue(ranges::make_subrange(InIter(id), Sent(id+sd))), OutIter(jd), count_equal());
CHECK(base(r.in) == id + sd);
CHECK(base(r.out) == jd + 2);
CHECK(jd[0] == 0);
CHECK(jd[1] == 1);
CHECK(count_equal::count == sd-1);
const int ie[] = {0, 0, 1, 0};
const unsigned se = sizeof(ie)/sizeof(ie[0]);
int je[se] = {-1};
count_equal::count = 0;
r = ranges::unique_copy(::as_lvalue(ranges::make_subrange(InIter(ie), Sent(ie+se))), OutIter(je), count_equal());
CHECK(base(r.in) == ie + se);
CHECK(base(r.out) == je + 3);
CHECK(je[0] == 0);
CHECK(je[1] == 1);
CHECK(je[2] == 0);
CHECK(count_equal::count == se-1);
const int ig[] = {0, 0, 1, 1};
const unsigned sg = sizeof(ig)/sizeof(ig[0]);
int jg[sg] = {-1};
count_equal::count = 0;
r = ranges::unique_copy(::as_lvalue(ranges::make_subrange(InIter(ig), Sent(ig+sg))), OutIter(jg), count_equal());
CHECK(base(r.in) == ig + sg);
CHECK(base(r.out) == jg + 2);
CHECK(jg[0] == 0);
CHECK(jg[1] == 1);
CHECK(count_equal::count == sg-1);
const int ih[] = {0, 1, 1};
const unsigned sh = sizeof(ih)/sizeof(ih[0]);
int jh[sh] = {-1};
count_equal::count = 0;
r = ranges::unique_copy(::as_lvalue(ranges::make_subrange(InIter(ih), Sent(ih+sh))), OutIter(jh), count_equal());
CHECK(base(r.in) == ih + sh);
CHECK(base(r.out) == jh + 2);
CHECK(jh[0] == 0);
CHECK(jh[1] == 1);
CHECK(count_equal::count == sh-1);
const int ii[] = {0, 1, 1, 1, 2, 2, 2};
const unsigned si = sizeof(ii)/sizeof(ii[0]);
int ji[si] = {-1};
count_equal::count = 0;
r = ranges::unique_copy(::as_lvalue(ranges::make_subrange(InIter(ii), Sent(ii+si))), OutIter(ji), count_equal());
CHECK(base(r.in) == ii + si);
CHECK(base(r.out) == ji + 3);
CHECK(ji[0] == 0);
CHECK(ji[1] == 1);
CHECK(ji[2] == 2);
CHECK(count_equal::count == si-1);
}
template<class InIter, class OutIter>
void test()
{
using Sent = typename sentinel_type<InIter>::type;
test_iter<InIter, OutIter>();
test_iter<InIter, OutIter, Sent>();
test_range<InIter, OutIter>();
test_range<InIter, OutIter, Sent>();
}
struct S
{
int i,j;
};
bool operator==(S l, S r)
{
return l.i == r.i && l.j == r.j;
}
constexpr bool test_constexpr()
{
using namespace ranges;
int a[] = {0, 1, 1, 1, 2, 2, 2};
int b[] = {0, 0, 0};
const unsigned sa = sizeof(a) / sizeof(a[0]);
const unsigned sb = sizeof(b) / sizeof(b[0]);
const auto r = unique_copy(a, b);
STATIC_CHECK_RETURN(r.in == a + sa);
STATIC_CHECK_RETURN(r.out == b + sb);
STATIC_CHECK_RETURN(a[0] == 0);
STATIC_CHECK_RETURN(a[1] == 1);
STATIC_CHECK_RETURN(a[2] == 1);
STATIC_CHECK_RETURN(a[3] == 1);
STATIC_CHECK_RETURN(a[4] == 2);
STATIC_CHECK_RETURN(a[5] == 2);
STATIC_CHECK_RETURN(a[6] == 2);
STATIC_CHECK_RETURN(b[0] == 0);
STATIC_CHECK_RETURN(b[1] == 1);
STATIC_CHECK_RETURN(b[2] == 2);
return true;
}
int main()
{
test<InputIterator<const int*>, OutputIterator<int*> >();
test<InputIterator<const int*>, ForwardIterator<int*> >();
test<InputIterator<const int*>, BidirectionalIterator<int*> >();
test<InputIterator<const int*>, RandomAccessIterator<int*> >();
test<InputIterator<const int*>, int*>();
test<ForwardIterator<const int*>, OutputIterator<int*> >();
test<ForwardIterator<const int*>, ForwardIterator<int*> >();
test<ForwardIterator<const int*>, BidirectionalIterator<int*> >();
test<ForwardIterator<const int*>, RandomAccessIterator<int*> >();
test<ForwardIterator<const int*>, int*>();
test<BidirectionalIterator<const int*>, OutputIterator<int*> >();
test<BidirectionalIterator<const int*>, ForwardIterator<int*> >();
test<BidirectionalIterator<const int*>, BidirectionalIterator<int*> >();
test<BidirectionalIterator<const int*>, RandomAccessIterator<int*> >();
test<BidirectionalIterator<const int*>, int*>();
test<RandomAccessIterator<const int*>, OutputIterator<int*> >();
test<RandomAccessIterator<const int*>, ForwardIterator<int*> >();
test<RandomAccessIterator<const int*>, BidirectionalIterator<int*> >();
test<RandomAccessIterator<const int*>, RandomAccessIterator<int*> >();
test<RandomAccessIterator<const int*>, int*>();
test<const int*, OutputIterator<int*> >();
test<const int*, ForwardIterator<int*> >();
test<const int*, BidirectionalIterator<int*> >();
test<const int*, RandomAccessIterator<int*> >();
test<const int*, int*>();
// Test projections:
{
S const ia[] = {{1,1},{2,2},{3,3},{3,4},{4,5},{5,6},{5,7},{5,8},{6,9},{7,10}};
S ib[ranges::size(ia)];
ranges::unique_copy_result<S const *, S *> r = ranges::unique_copy(ia, ib, ranges::equal_to(), &S::i);
CHECK(r.in == ranges::end(ia));
CHECK(r.out == ib + 7);
check_equal(ranges::make_subrange(ib, ib+7), {S{1,1},S{2,2},S{3,3},S{4,5},S{5,6},S{6,9},S{7,10}});
}
// Test rvalue ranges:
{
S const ia[] = {{1,1},{2,2},{3,3},{3,4},{4,5},{5,6},{5,7},{5,8},{6,9},{7,10}};
S ib[ranges::size(ia)];
auto r = ranges::unique_copy(ranges::views::all(ia), ib, ranges::equal_to(), &S::i);
CHECK(r.in == ranges::end(ia));
CHECK(r.out == ib + 7);
check_equal(ranges::make_subrange(ib, ib+7), {S{1,1},S{2,2},S{3,3},S{4,5},S{5,6},S{6,9},S{7,10}});
}
#ifndef RANGES_WORKAROUND_MSVC_573728
{
S const ia[] = {{1,1},{2,2},{3,3},{3,4},{4,5},{5,6},{5,7},{5,8},{6,9},{7,10}};
S ib[ranges::size(ia)];
auto r = ranges::unique_copy(std::move(ia), ib, ranges::equal_to(), &S::i);
CHECK(::is_dangling(r.in));
CHECK(r.out == ib + 7);
check_equal(ranges::make_subrange(ib, ib+7), {S{1,1},S{2,2},S{3,3},S{4,5},S{5,6},S{6,9},S{7,10}});
}
#endif // RANGES_WORKAROUND_MSVC_573728
{
std::vector<S> const ia{{1,1},{2,2},{3,3},{3,4},{4,5},{5,6},{5,7},{5,8},{6,9},{7,10}};
S ib[10];
RANGES_ENSURE(ranges::size(ia) == ranges::size(ib));
auto r = ranges::unique_copy(std::move(ia), ib, ranges::equal_to(), &S::i);
CHECK(::is_dangling(r.in));
CHECK(r.out == ib + 7);
check_equal(ranges::make_subrange(ib, ib+7), {S{1,1},S{2,2},S{3,3},S{4,5},S{5,6},S{6,9},S{7,10}});
}
{
STATIC_CHECK(test_constexpr());
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/set_symmetric_difference1.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#define SET_SYMMETRIC_DIFFERENCE_1
#include "./set_symmetric_difference.hpp"
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/fill.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <cstring>
#include <string>
#include <vector>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/fill.hpp>
#include <range/v3/algorithm/equal.hpp>
#include "../array.hpp"
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
template<class Iter, class Sent = Iter>
void
test_char()
{
const unsigned n = 4;
char ca[n] = {0};
auto i = ranges::fill(Iter(ca), Sent(ca+n), char(1));
CHECK(ca[0] == 1);
CHECK(ca[1] == 1);
CHECK(ca[2] == 1);
CHECK(ca[3] == 1);
CHECK(i == Iter(ca + 4));
auto rng = ranges::make_subrange(Iter(ca), Sent(ca+n));
i = ranges::fill(rng, char(2));
CHECK(ca[0] == 2);
CHECK(ca[1] == 2);
CHECK(ca[2] == 2);
CHECK(ca[3] == 2);
CHECK(i == Iter(ca + 4));
auto j = ranges::fill(::MakeTestRange(Iter(ca), Sent(ca+n)), char(3));
CHECK(ca[0] == 3);
CHECK(ca[1] == 3);
CHECK(ca[2] == 3);
CHECK(ca[3] == 3);
CHECK(::is_dangling(j));
}
template<class Iter, class Sent = Iter>
void
test_int()
{
const unsigned n = 4;
int ia[n] = {0};
ranges::fill(Iter(ia), Sent(ia+n), 1);
CHECK(ia[0] == 1);
CHECK(ia[1] == 1);
CHECK(ia[2] == 1);
CHECK(ia[3] == 1);
auto rng = ranges::make_subrange(Iter(ia), Sent(ia+n));
ranges::fill(rng, 2);
CHECK(ia[0] == 2);
CHECK(ia[2] == 2);
CHECK(ia[2] == 2);
CHECK(ia[3] == 2);
}
constexpr auto fives()
{
test::array<int, 4> a{{0}};
ranges::fill(a, 5);
return a;
}
constexpr auto fives(int n)
{
test::array<int, 4> a{{0}};
ranges::fill_n(ranges::begin(a), n, 5);
return a;
}
int main()
{
test_char<ForwardIterator<char*> >();
test_char<BidirectionalIterator<char*> >();
test_char<RandomAccessIterator<char*> >();
test_char<char*>();
test_char<ForwardIterator<char*>, Sentinel<char*> >();
test_char<BidirectionalIterator<char*>, Sentinel<char*> >();
test_char<RandomAccessIterator<char*>, Sentinel<char*> >();
test_int<ForwardIterator<int*> >();
test_int<BidirectionalIterator<int*> >();
test_int<RandomAccessIterator<int*> >();
test_int<int*>();
test_int<ForwardIterator<int*>, Sentinel<int*> >();
test_int<BidirectionalIterator<int*>, Sentinel<int*> >();
test_int<RandomAccessIterator<int*>, Sentinel<int*> >();
{
using IL = std::initializer_list<int>;
STATIC_CHECK(ranges::equal(fives(), IL{5, 5, 5, 5}));
STATIC_CHECK(ranges::equal(fives(2), IL{5, 5, 0, 0}));
STATIC_CHECK(!ranges::equal(fives(2), IL{5, 5, 5, 5}));
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/set_difference5.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#define SET_DIFFERENCE_5
#include "./set_difference.hpp"
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/any_of.cpp | // Range v3 library
//
// Copyright Andrew Sutton 2014
// Copyright Gonzalo Brito Gadeschi 2014
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#include <vector>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/any_of.hpp>
#include "../simple_test.hpp"
constexpr bool even(int n)
{
return n % 2 == 0;
}
struct S {
S(bool p) : test(p) { }
bool p() const { return test; }
bool test;
};
constexpr bool test_constexpr(std::initializer_list<int> il)
{
return ranges::any_of(il, even);
}
int main()
{
std::vector<int> all_even { 0, 2, 4, 6 };
std::vector<int> one_even { 1, 3, 4, 7 };
std::vector<int> none_even { 1, 3, 5, 7 };
CHECK(ranges::any_of(all_even.begin(), all_even.end(), even));
CHECK(ranges::any_of(one_even.begin(), one_even.end(), even));
CHECK(!ranges::any_of(none_even.begin(), none_even.end(), even));
CHECK(ranges::any_of(all_even, even));
CHECK(ranges::any_of(one_even, even));
CHECK(!ranges::any_of(none_even, even));
using ILI = std::initializer_list<int>;
CHECK(ranges::any_of(ILI{0, 2, 4, 6}, [](int n) { return n % 2 == 0; }));
CHECK(ranges::any_of(ILI{1, 3, 4, 7}, [](int n) { return n % 2 == 0; }));
CHECK(!ranges::any_of(ILI{1, 3, 5, 7}, [](int n) { return n % 2 == 0; }));
std::vector<S> all_true { true, true, true };
std::vector<S> one_true { false, false, true };
std::vector<S> none_true { false, false, false };
CHECK(ranges::any_of(all_true.begin(), all_true.end(), &S::p));
CHECK(ranges::any_of(one_true.begin(), one_true.end(), &S::p));
CHECK(!ranges::any_of(none_true.begin(), none_true.end(), &S::p));
CHECK(ranges::any_of(all_true, &S::p));
CHECK(ranges::any_of(one_true, &S::p));
CHECK(!ranges::any_of(none_true, &S::p));
using ILS = std::initializer_list<S>;
CHECK(ranges::any_of(ILS{S(true), S(true), S(true)}, &S::p));
CHECK(ranges::any_of(ILS{S(false), S(true), S(false)}, &S::p));
CHECK(!ranges::any_of(ILS{S(false), S(false), S(false)}, &S::p));
STATIC_CHECK(test_constexpr({0, 2, 4, 6}));
STATIC_CHECK(test_constexpr({1, 3, 4, 7}));
STATIC_CHECK(!test_constexpr({1, 3, 5, 7}));
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/contains.cpp | // Range v3 library
//
// Copyright Johel Guerrero 2019
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#include <range/v3/algorithm/contains.hpp>
#include "../simple_test.hpp"
int main()
{
using ranges::contains;
constexpr int rng[] = {4, 2};
const auto first = rng;
const auto last = rng + 2;
CHECK(!contains(first, first, 0));
CHECK(!contains(first, last, 1));
CHECK(contains(first, last, 2));
CHECK(!contains(first, last, 3));
CHECK(contains(first, last, 4));
#ifndef RANGES_WORKAROUND_CLANG_23135
static_assert(!contains(rng, 1), "");
static_assert(contains(rng, 2), "");
static_assert(!contains(rng, 3), "");
static_assert(contains(rng, 4), "");
#endif
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/search_n.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright 2005 - 2007 Adobe Systems Incorporated
// Distributed under the MIT License(see accompanying file LICENSE_1_0_0.txt
// or a copy at http://stlab.adobe.com/licenses.html)
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <vector>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/search_n.hpp>
#include <range/v3/view/counted.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
template<class Iter, typename Sent = Iter>
void
test_iter_impl()
{
int ia[] = {0, 1, 2, 3, 4, 5};
const unsigned sa = sizeof(ia)/sizeof(ia[0]);
CHECK(ranges::search_n(Iter(ia), Sent(ia+sa), 0, 0).begin() == Iter(ia));
CHECK(ranges::search_n(Iter(ia), Sent(ia+sa), 0, 0).end() == Iter(ia));
CHECK(ranges::search_n(Iter(ia), Sent(ia+sa), 1, 0).begin() == Iter(ia+0));
CHECK(ranges::search_n(Iter(ia), Sent(ia+sa), 1, 0).end() == Iter(ia+1));
CHECK(ranges::search_n(Iter(ia), Sent(ia+sa), 2, 0).begin() == Iter(ia+sa));
CHECK(ranges::search_n(Iter(ia), Sent(ia+sa), 2, 0).end() == Iter(ia+sa));
CHECK(ranges::search_n(Iter(ia), Sent(ia+sa), sa, 0).begin() == Iter(ia+sa));
CHECK(ranges::search_n(Iter(ia), Sent(ia+sa), sa, 0).end() == Iter(ia+sa));
CHECK(ranges::search_n(Iter(ia), Sent(ia+sa), 0, 3).begin() == Iter(ia));
CHECK(ranges::search_n(Iter(ia), Sent(ia+sa), 0, 3).end() == Iter(ia));
CHECK(ranges::search_n(Iter(ia), Sent(ia+sa), 1, 3).begin() == Iter(ia+3));
CHECK(ranges::search_n(Iter(ia), Sent(ia+sa), 1, 3).end() == Iter(ia+4));
CHECK(ranges::search_n(Iter(ia), Sent(ia+sa), 2, 3).begin() == Iter(ia+sa));
CHECK(ranges::search_n(Iter(ia), Sent(ia+sa), 2, 3).end() == Iter(ia+sa));
CHECK(ranges::search_n(Iter(ia), Sent(ia+sa), sa, 3).begin() == Iter(ia+sa));
CHECK(ranges::search_n(Iter(ia), Sent(ia+sa), sa, 3).end() == Iter(ia+sa));
CHECK(ranges::search_n(Iter(ia), Sent(ia+sa), 0, 5).begin() == Iter(ia));
CHECK(ranges::search_n(Iter(ia), Sent(ia+sa), 0, 5).end() == Iter(ia));
CHECK(ranges::search_n(Iter(ia), Sent(ia+sa), 1, 5).begin() == Iter(ia+5));
CHECK(ranges::search_n(Iter(ia), Sent(ia+sa), 1, 5).end() == Iter(ia+6));
CHECK(ranges::search_n(Iter(ia), Sent(ia+sa), 2, 5).begin() == Iter(ia+sa));
CHECK(ranges::search_n(Iter(ia), Sent(ia+sa), 2, 5).end() == Iter(ia+sa));
CHECK(ranges::search_n(Iter(ia), Sent(ia+sa), sa, 5).begin() == Iter(ia+sa));
CHECK(ranges::search_n(Iter(ia), Sent(ia+sa), sa, 5).end() == Iter(ia+sa));
int ib[] = {0, 0, 1, 1, 2, 2};
const unsigned sb = sizeof(ib)/sizeof(ib[0]);
CHECK(ranges::search_n(Iter(ib), Sent(ib+sb), 0, 0).begin() == Iter(ib));
CHECK(ranges::search_n(Iter(ib), Sent(ib+sb), 0, 0).end() == Iter(ib));
CHECK(ranges::search_n(Iter(ib), Sent(ib+sb), 1, 0).begin() == Iter(ib+0));
CHECK(ranges::search_n(Iter(ib), Sent(ib+sb), 1, 0).end() == Iter(ib+1));
CHECK(ranges::search_n(Iter(ib), Sent(ib+sb), 2, 0).begin() == Iter(ib+0));
CHECK(ranges::search_n(Iter(ib), Sent(ib+sb), 2, 0).end() == Iter(ib+2));
CHECK(ranges::search_n(Iter(ib), Sent(ib+sb), 3, 0).begin() == Iter(ib+sb));
CHECK(ranges::search_n(Iter(ib), Sent(ib+sb), 3, 0).end() == Iter(ib+sb));
CHECK(ranges::search_n(Iter(ib), Sent(ib+sb), sb, 0).begin() == Iter(ib+sb));
CHECK(ranges::search_n(Iter(ib), Sent(ib+sb), sb, 0).end() == Iter(ib+sb));
CHECK(ranges::search_n(Iter(ib), Sent(ib+sb), 0, 1).begin() == Iter(ib));
CHECK(ranges::search_n(Iter(ib), Sent(ib+sb), 0, 1).end() == Iter(ib));
CHECK(ranges::search_n(Iter(ib), Sent(ib+sb), 1, 1).begin() == Iter(ib+2));
CHECK(ranges::search_n(Iter(ib), Sent(ib+sb), 1, 1).end() == Iter(ib+3));
CHECK(ranges::search_n(Iter(ib), Sent(ib+sb), 2, 1).begin() == Iter(ib+2));
CHECK(ranges::search_n(Iter(ib), Sent(ib+sb), 2, 1).end() == Iter(ib+4));
CHECK(ranges::search_n(Iter(ib), Sent(ib+sb), 3, 1).begin() == Iter(ib+sb));
CHECK(ranges::search_n(Iter(ib), Sent(ib+sb), 3, 1).end() == Iter(ib+sb));
CHECK(ranges::search_n(Iter(ib), Sent(ib+sb), sb, 1).begin() == Iter(ib+sb));
CHECK(ranges::search_n(Iter(ib), Sent(ib+sb), sb, 1).end() == Iter(ib+sb));
CHECK(ranges::search_n(Iter(ib), Sent(ib+sb), 0, 2).begin() == Iter(ib));
CHECK(ranges::search_n(Iter(ib), Sent(ib+sb), 0, 2).end() == Iter(ib));
CHECK(ranges::search_n(Iter(ib), Sent(ib+sb), 1, 2).begin() == Iter(ib+4));
CHECK(ranges::search_n(Iter(ib), Sent(ib+sb), 1, 2).end() == Iter(ib+5));
CHECK(ranges::search_n(Iter(ib), Sent(ib+sb), 2, 2).begin() == Iter(ib+4));
CHECK(ranges::search_n(Iter(ib), Sent(ib+sb), 2, 2).end() == Iter(ib+6));
CHECK(ranges::search_n(Iter(ib), Sent(ib+sb), 3, 2).begin() == Iter(ib+sb));
CHECK(ranges::search_n(Iter(ib), Sent(ib+sb), 3, 2).end() == Iter(ib+sb));
CHECK(ranges::search_n(Iter(ib), Sent(ib+sb), sb, 2).begin() == Iter(ib+sb));
CHECK(ranges::search_n(Iter(ib), Sent(ib+sb), sb, 2).end() == Iter(ib+sb));
int ic[] = {0, 0, 0};
const unsigned sc = sizeof(ic)/sizeof(ic[0]);
CHECK(ranges::search_n(Iter(ic), Sent(ic+sc), 0, 0).begin() == Iter(ic));
CHECK(ranges::search_n(Iter(ic), Sent(ic+sc), 0, 0).end() == Iter(ic));
CHECK(ranges::search_n(Iter(ic), Sent(ic+sc), 1, 0).begin() == Iter(ic));
CHECK(ranges::search_n(Iter(ic), Sent(ic+sc), 1, 0).end() == Iter(ic+1));
CHECK(ranges::search_n(Iter(ic), Sent(ic+sc), 2, 0).begin() == Iter(ic));
CHECK(ranges::search_n(Iter(ic), Sent(ic+sc), 2, 0).end() == Iter(ic+2));
CHECK(ranges::search_n(Iter(ic), Sent(ic+sc), 3, 0).begin() == Iter(ic));
CHECK(ranges::search_n(Iter(ic), Sent(ic+sc), 3, 0).end() == Iter(ic+3));
CHECK(ranges::search_n(Iter(ic), Sent(ic+sc), 4, 0).begin() == Iter(ic+sc));
CHECK(ranges::search_n(Iter(ic), Sent(ic+sc), 4, 0).end() == Iter(ic+sc));
}
template<class Iter, class Iter2>
void
test_iter()
{
using Sent = typename sentinel_type<Iter>::type;
test_iter_impl<Iter>();
test_iter_impl<Iter, Sent>();
using SizedSent1 = typename sentinel_type<Iter, true>::type;
test_iter_impl<Iter, SizedSent1>();
}
template<class Iter, typename Sent = Iter>
void
test_range_impl()
{
int ia[] = {0, 1, 2, 3, 4, 5};
const unsigned sa = sizeof(ia)/sizeof(ia[0]);
CHECK(ranges::search_n(ranges::make_subrange(Iter(ia), Sent(ia+sa)), 0, 0).begin() == Iter(ia));
CHECK(ranges::search_n(ranges::make_subrange(Iter(ia), Sent(ia+sa)), 1, 0).begin() == Iter(ia+0));
CHECK(ranges::search_n(ranges::make_subrange(Iter(ia), Sent(ia+sa)), 2, 0).begin() == Iter(ia+sa));
CHECK(ranges::search_n(ranges::make_subrange(Iter(ia), Sent(ia+sa)), sa, 0).begin() == Iter(ia+sa));
CHECK(ranges::search_n(ranges::make_subrange(Iter(ia), Sent(ia+sa)), 0, 3).begin() == Iter(ia));
CHECK(ranges::search_n(ranges::make_subrange(Iter(ia), Sent(ia+sa)), 1, 3).begin() == Iter(ia+3));
CHECK(ranges::search_n(ranges::make_subrange(Iter(ia), Sent(ia+sa)), 2, 3).begin() == Iter(ia+sa));
CHECK(ranges::search_n(ranges::make_subrange(Iter(ia), Sent(ia+sa)), sa, 3).begin() == Iter(ia+sa));
CHECK(ranges::search_n(ranges::make_subrange(Iter(ia), Sent(ia+sa)), 0, 5).begin() == Iter(ia));
CHECK(ranges::search_n(ranges::make_subrange(Iter(ia), Sent(ia+sa)), 1, 5).begin() == Iter(ia+5));
CHECK(ranges::search_n(ranges::make_subrange(Iter(ia), Sent(ia+sa)), 2, 5).begin() == Iter(ia+sa));
CHECK(ranges::search_n(ranges::make_subrange(Iter(ia), Sent(ia+sa)), sa, 5).begin() == Iter(ia+sa));
int ib[] = {0, 0, 1, 1, 2, 2};
const unsigned sb = sizeof(ib)/sizeof(ib[0]);
CHECK(ranges::search_n(ranges::make_subrange(Iter(ib), Sent(ib+sb)), 0, 0).begin() == Iter(ib));
CHECK(ranges::search_n(ranges::make_subrange(Iter(ib), Sent(ib+sb)), 1, 0).begin() == Iter(ib+0));
CHECK(ranges::search_n(ranges::make_subrange(Iter(ib), Sent(ib+sb)), 2, 0).begin() == Iter(ib+0));
CHECK(ranges::search_n(ranges::make_subrange(Iter(ib), Sent(ib+sb)), 3, 0).begin() == Iter(ib+sb));
CHECK(ranges::search_n(ranges::make_subrange(Iter(ib), Sent(ib+sb)), sb, 0).begin() == Iter(ib+sb));
CHECK(ranges::search_n(ranges::make_subrange(Iter(ib), Sent(ib+sb)), 0, 1).begin() == Iter(ib));
CHECK(ranges::search_n(ranges::make_subrange(Iter(ib), Sent(ib+sb)), 1, 1).begin() == Iter(ib+2));
CHECK(ranges::search_n(ranges::make_subrange(Iter(ib), Sent(ib+sb)), 2, 1).begin() == Iter(ib+2));
CHECK(ranges::search_n(ranges::make_subrange(Iter(ib), Sent(ib+sb)), 3, 1).begin() == Iter(ib+sb));
CHECK(ranges::search_n(ranges::make_subrange(Iter(ib), Sent(ib+sb)), sb, 1).begin() == Iter(ib+sb));
CHECK(ranges::search_n(ranges::make_subrange(Iter(ib), Sent(ib+sb)), 0, 2).begin() == Iter(ib));
CHECK(ranges::search_n(ranges::make_subrange(Iter(ib), Sent(ib+sb)), 1, 2).begin() == Iter(ib+4));
CHECK(ranges::search_n(ranges::make_subrange(Iter(ib), Sent(ib+sb)), 2, 2).begin() == Iter(ib+4));
CHECK(ranges::search_n(ranges::make_subrange(Iter(ib), Sent(ib+sb)), 3, 2).begin() == Iter(ib+sb));
CHECK(ranges::search_n(ranges::make_subrange(Iter(ib), Sent(ib+sb)), sb, 2).begin() == Iter(ib+sb));
int ic[] = {0, 0, 0};
const unsigned sc = sizeof(ic)/sizeof(ic[0]);
CHECK(ranges::search_n(ranges::make_subrange(Iter(ic), Sent(ic+sc)), 0, 0).begin() == Iter(ic));
CHECK(ranges::search_n(ranges::make_subrange(Iter(ic), Sent(ic+sc)), 1, 0).begin() == Iter(ic));
CHECK(ranges::search_n(ranges::make_subrange(Iter(ic), Sent(ic+sc)), 2, 0).begin() == Iter(ic));
CHECK(ranges::search_n(ranges::make_subrange(Iter(ic), Sent(ic+sc)), 3, 0).begin() == Iter(ic));
CHECK(ranges::search_n(ranges::make_subrange(Iter(ic), Sent(ic+sc)), 4, 0).begin() == Iter(ic+sc));
}
template<class Iter, class Iter2>
void
test_range()
{
using Sent = typename sentinel_type<Iter>::type;
test_range_impl<Iter>();
test_range_impl<Iter, Sent>();
using SizedSent1 = typename sentinel_type<Iter, true>::type;
test_range_impl<Iter, SizedSent1>();
}
template<class Iter, class Iter2>
void
test()
{
test_iter<Iter, Iter2>();
test_range<Iter, Iter2>();
}
struct S
{
int i;
};
constexpr bool test_constexpr()
{
using namespace ranges;
int ia[] = {0, 1, 2, 2, 4, 5};
auto r = search_n(ia, 2, 2, equal_to{});
STATIC_CHECK_RETURN(r.begin() == ia + 2);
return true;
}
int main()
{
test<ForwardIterator<const int*>, ForwardIterator<const int*> >();
test<ForwardIterator<const int*>, BidirectionalIterator<const int*> >();
test<ForwardIterator<const int*>, RandomAccessIterator<const int*> >();
test<BidirectionalIterator<const int*>, ForwardIterator<const int*> >();
test<BidirectionalIterator<const int*>, BidirectionalIterator<const int*> >();
test<BidirectionalIterator<const int*>, RandomAccessIterator<const int*> >();
test<RandomAccessIterator<const int*>, ForwardIterator<const int*> >();
test<RandomAccessIterator<const int*>, BidirectionalIterator<const int*> >();
test<RandomAccessIterator<const int*>, RandomAccessIterator<const int*> >();
// Test projections:
{
S const in[] = {{0}, {1}, {2}, {2}, {4}, {5}};
auto sub = ranges::search_n(in, 2, 2, std::equal_to<int>{}, &S::i);
CHECK(sub.begin() == in+2);
CHECK(sub.end() == in+4);
}
// Test counted ranges
{
int in[] = {0,1,2,2,4,5};
auto rng = ranges::views::counted(BidirectionalIterator<int*>(in), 6);
auto sub = ranges::search_n(rng, 2, 2);
CHECK(base(sub.begin().base()) == in+2);
CHECK(base(sub.end().base()) == in+4);
CHECK(sub.begin().count() == 4);
CHECK(sub.end().count() == 2);
auto sub2 = ranges::search_n(rng, 3, 2);
CHECK(base(sub2.begin().base()) == in+6);
CHECK(base(sub2.end().base()) == in+6);
CHECK(sub2.begin().count() == 0);
CHECK(sub2.end().count() == 0);
}
// Test rvalue ranges
{
int ib[] = {0, 0, 1, 1, 2, 2};
CHECK(ranges::search_n(ranges::views::all(ib), 2, 1).begin() == ib+2);
}
#ifndef RANGES_WORKAROUND_MSVC_573728
{
int ib[] = {0, 0, 1, 1, 2, 2};
CHECK(::is_dangling(ranges::search_n(std::move(ib), 2, 1)));
}
#endif // RANGES_WORKAROUND_MSVC_573728
{
std::vector<int> ib{0, 0, 1, 1, 2, 2};
CHECK(::is_dangling(ranges::search_n(std::move(ib), 2, 1)));
}
{
STATIC_CHECK(test_constexpr());
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/partition.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright 2005 - 2007 Adobe Systems Incorporated
// Distributed under the MIT License(see accompanying file LICENSE_1_0_0.txt
// or a copy at http://stlab.adobe.com/licenses.html)
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <memory>
#include <utility>
#include <vector>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/partition.hpp>
#include "../array.hpp"
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
RANGES_DIAGNOSTIC_IGNORE_SIGN_CONVERSION
namespace
{
struct is_odd
{
constexpr bool operator()(const int & i) const
{
return i & 1;
}
};
template<class Iter, class Sent = Iter>
void
test_iter()
{
// check mixed
int ia[] = {1, 2, 3, 4, 5, 6, 7, 8 ,9};
const unsigned sa = sizeof(ia)/sizeof(ia[0]);
Iter r = ranges::partition(Iter(ia), Sent(ia + sa), is_odd());
CHECK(base(r) == ia + 5);
for (int* i = ia; i < base(r); ++i)
CHECK(is_odd()(*i));
for (int* i = base(r); i < ia+sa; ++i)
CHECK(!is_odd()(*i));
// check empty
r = ranges::partition(Iter(ia), Sent(ia), is_odd());
CHECK(base(r) == ia);
// check all false
for (unsigned i = 0; i < sa; ++i)
ia[i] = 2*i;
r = ranges::partition(Iter(ia), Sent(ia+sa), is_odd());
CHECK(base(r) == ia);
// check all true
for (unsigned i = 0; i < sa; ++i)
ia[i] = 2*i+1;
r = ranges::partition(Iter(ia), Sent(ia+sa), is_odd());
CHECK(base(r) == ia+sa);
// check all true but last
for (unsigned i = 0; i < sa; ++i)
ia[i] = 2*i+1;
ia[sa-1] = 10;
r = ranges::partition(Iter(ia), Sent(ia+sa), is_odd());
CHECK(base(r) == ia+sa-1);
for (int* i = ia; i < base(r); ++i)
CHECK(is_odd()(*i));
for (int* i = base(r); i < ia+sa; ++i)
CHECK(!is_odd()(*i));
// check all true but first
for (unsigned i = 0; i < sa; ++i)
ia[i] = 2*i+1;
ia[0] = 10;
r = ranges::partition(Iter(ia), Sent(ia+sa), is_odd());
CHECK(base(r) == ia+sa-1);
for (int* i = ia; i < base(r); ++i)
CHECK(is_odd()(*i));
for (int* i = base(r); i < ia+sa; ++i)
CHECK(!is_odd()(*i));
// check all false but last
for (unsigned i = 0; i < sa; ++i)
ia[i] = 2*i;
ia[sa-1] = 11;
r = ranges::partition(Iter(ia), Sent(ia+sa), is_odd());
CHECK(base(r) == ia+1);
for (int* i = ia; i < base(r); ++i)
CHECK(is_odd()(*i));
for (int* i = base(r); i < ia+sa; ++i)
CHECK(!is_odd()(*i));
// check all false but first
for (unsigned i = 0; i < sa; ++i)
ia[i] = 2*i;
ia[0] = 11;
r = ranges::partition(Iter(ia), Sent(ia+sa), is_odd());
CHECK(base(r) == ia+1);
for (int* i = ia; i < base(r); ++i)
CHECK(is_odd()(*i));
for (int* i = base(r); i < ia+sa; ++i)
CHECK(!is_odd()(*i));
}
template<class Iter, class Sent = Iter>
void
test_range()
{
// check mixed
int ia[] = {1, 2, 3, 4, 5, 6, 7, 8 ,9};
const unsigned sa = sizeof(ia)/sizeof(ia[0]);
Iter r = ranges::partition(::as_lvalue(ranges::make_subrange(Iter(ia), Sent(ia + sa))), is_odd());
CHECK(base(r) == ia + 5);
for (int* i = ia; i < base(r); ++i)
CHECK(is_odd()(*i));
for (int* i = base(r); i < ia+sa; ++i)
CHECK(!is_odd()(*i));
// check empty
r = ranges::partition(::as_lvalue(ranges::make_subrange(Iter(ia), Sent(ia))), is_odd());
CHECK(base(r) == ia);
// check all false
for (unsigned i = 0; i < sa; ++i)
ia[i] = 2*i;
r = ranges::partition(::as_lvalue(ranges::make_subrange(Iter(ia), Sent(ia+sa))), is_odd());
CHECK(base(r) == ia);
// check all true
for (unsigned i = 0; i < sa; ++i)
ia[i] = 2*i+1;
r = ranges::partition(::as_lvalue(ranges::make_subrange(Iter(ia), Sent(ia+sa))), is_odd());
CHECK(base(r) == ia+sa);
// check all true but last
for (unsigned i = 0; i < sa; ++i)
ia[i] = 2*i+1;
ia[sa-1] = 10;
r = ranges::partition(::as_lvalue(ranges::make_subrange(Iter(ia), Sent(ia+sa))), is_odd());
CHECK(base(r) == ia+sa-1);
for (int* i = ia; i < base(r); ++i)
CHECK(is_odd()(*i));
for (int* i = base(r); i < ia+sa; ++i)
CHECK(!is_odd()(*i));
// check all true but first
for (unsigned i = 0; i < sa; ++i)
ia[i] = 2*i+1;
ia[0] = 10;
r = ranges::partition(::as_lvalue(ranges::make_subrange(Iter(ia), Sent(ia+sa))), is_odd());
CHECK(base(r) == ia+sa-1);
for (int* i = ia; i < base(r); ++i)
CHECK(is_odd()(*i));
for (int* i = base(r); i < ia+sa; ++i)
CHECK(!is_odd()(*i));
// check all false but last
for (unsigned i = 0; i < sa; ++i)
ia[i] = 2*i;
ia[sa-1] = 11;
r = ranges::partition(::as_lvalue(ranges::make_subrange(Iter(ia), Sent(ia+sa))), is_odd());
CHECK(base(r) == ia+1);
for (int* i = ia; i < base(r); ++i)
CHECK(is_odd()(*i));
for (int* i = base(r); i < ia+sa; ++i)
CHECK(!is_odd()(*i));
// check all false but first
for (unsigned i = 0; i < sa; ++i)
ia[i] = 2*i;
ia[0] = 11;
r = ranges::partition(::as_lvalue(ranges::make_subrange(Iter(ia), Sent(ia+sa))), is_odd());
CHECK(base(r) == ia+1);
for (int* i = ia; i < base(r); ++i)
CHECK(is_odd()(*i));
for (int* i = base(r); i < ia+sa; ++i)
CHECK(!is_odd()(*i));
}
struct S
{
int i;
};
}
constexpr bool test_constexpr()
{
using namespace ranges;
test::array<int, 9> ia{{1, 2, 3, 4, 5, 6, 7, 8, 9}};
int * r = partition(ia, is_odd());
STATIC_CHECK_RETURN(r == begin(ia) + 5);
for(int * i = begin(ia); i < r; ++i)
{
STATIC_CHECK_RETURN(is_odd()(*i));
}
for(int * i = r; i < end(ia); ++i)
{
STATIC_CHECK_RETURN(!is_odd()(*i));
}
// Test rvalue range
auto r2 = partition(make_subrange(begin(ia), end(ia)), is_odd());
STATIC_CHECK_RETURN(r2 == begin(ia) + 5);
for(int * i = begin(ia); i < r2; ++i)
{
STATIC_CHECK_RETURN(is_odd()(*i));
}
for(int * i = r2; i < end(ia); ++i)
{
STATIC_CHECK_RETURN(!is_odd()(*i));
}
return true;
}
int main()
{
test_iter<ForwardIterator<int*> >();
test_iter<BidirectionalIterator<int*> >();
test_iter<RandomAccessIterator<int*> >();
test_iter<int*>();
test_iter<ForwardIterator<int*>, Sentinel<int*> >();
test_iter<BidirectionalIterator<int*>, Sentinel<int*> >();
test_iter<RandomAccessIterator<int*>, Sentinel<int*> >();
test_range<ForwardIterator<int*> >();
test_range<BidirectionalIterator<int*> >();
test_range<RandomAccessIterator<int*> >();
test_range<int*>();
test_range<ForwardIterator<int*>, Sentinel<int*> >();
test_range<BidirectionalIterator<int*>, Sentinel<int*> >();
test_range<RandomAccessIterator<int*>, Sentinel<int*> >();
// Test projections
S ia[] = {S{1}, S{2}, S{3}, S{4}, S{5}, S{6}, S{7}, S{8} ,S{9}};
const unsigned sa = sizeof(ia)/sizeof(ia[0]);
S* r = ranges::partition(ia, is_odd(), &S::i);
CHECK(r == ia + 5);
for (S* i = ia; i < r; ++i)
CHECK(is_odd()(i->i));
for (S* i = r; i < ia+sa; ++i)
CHECK(!is_odd()(i->i));
// Test rvalue range
auto r2 = ranges::partition(std::move(ia), is_odd(), &S::i);
#ifndef RANGES_WORKAROUND_MSVC_573728
CHECK(::is_dangling(r2));
#endif // RANGES_WORKAROUND_MSVC_573728
std::vector<S> vec(ranges::begin(ia), ranges::end(ia));
auto r3 = ranges::partition(std::move(vec), is_odd(), &S::i);
CHECK(::is_dangling(r3));
{
STATIC_CHECK(test_constexpr());
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/max.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
// Copyright Casey Carter 2015
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <range/v3/algorithm/max.hpp>
#include <range/v3/view/subrange.hpp>
#include <memory>
#include <numeric>
#include <random>
#include <algorithm>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
RANGES_DIAGNOSTIC_IGNORE_GLOBAL_CONSTRUCTORS
namespace
{
std::mt19937 gen;
template<class Iter, class Sent = Iter>
void
test_iter(Iter first, Sent last)
{
RANGES_ENSURE(first != last);
auto rng = ranges::make_subrange(first, last);
auto v = ranges::max(rng);
for (Iter i = first; i != last; ++i)
CHECK(!(v < *i));
}
template<class Iter, class Sent = Iter>
void
test_iter(unsigned N)
{
RANGES_ENSURE(N > 0);
std::unique_ptr<int[]> a{new int[N]};
std::iota(a.get(), a.get()+N, 0);
std::shuffle(a.get(), a.get()+N, gen);
test_iter(Iter(a.get()), Sent(a.get()+N));
}
template<class Iter, class Sent = Iter>
void
test_iter()
{
test_iter<Iter, Sent>(1);
test_iter<Iter, Sent>(2);
test_iter<Iter, Sent>(3);
test_iter<Iter, Sent>(10);
test_iter<Iter, Sent>(1000);
}
template<class Iter, class Sent = Iter>
void
test_iter_comp(Iter first, Sent last)
{
RANGES_ENSURE(first != last);
auto rng = ranges::make_subrange(first, last);
auto comp = std::greater<int>();
auto v = ranges::max(rng, comp);
for (Iter i = first; i != last; ++i)
CHECK(!comp(v, *i));
}
template<class Iter, class Sent = Iter>
void
test_iter_comp(unsigned N)
{
RANGES_ENSURE(N > 0);
std::unique_ptr<int[]> a{new int[N]};
std::iota(a.get(), a.get()+N, 0);
std::shuffle(a.get(), a.get()+N, gen);
test_iter_comp(Iter(a.get()), Sent(a.get()+N));
}
template<class Iter, class Sent = Iter>
void
test_iter_comp()
{
test_iter_comp<Iter, Sent>(1);
test_iter_comp<Iter, Sent>(2);
test_iter_comp<Iter, Sent>(3);
test_iter_comp<Iter, Sent>(10);
test_iter_comp<Iter, Sent>(1000);
}
struct S
{
int i;
};
}
int main()
{
test_iter<InputIterator<const int*> >();
test_iter<ForwardIterator<const int*> >();
test_iter<BidirectionalIterator<const int*> >();
test_iter<RandomAccessIterator<const int*> >();
test_iter<const int*>();
test_iter<InputIterator<const int*>, Sentinel<const int*>>();
test_iter<ForwardIterator<const int*>, Sentinel<const int*>>();
test_iter<BidirectionalIterator<const int*>, Sentinel<const int*>>();
test_iter<RandomAccessIterator<const int*>, Sentinel<const int*>>();
test_iter_comp<InputIterator<const int*> >();
test_iter_comp<ForwardIterator<const int*> >();
test_iter_comp<BidirectionalIterator<const int*> >();
test_iter_comp<RandomAccessIterator<const int*> >();
test_iter_comp<const int*>();
test_iter_comp<InputIterator<const int*>, Sentinel<const int*>>();
test_iter_comp<ForwardIterator<const int*>, Sentinel<const int*>>();
test_iter_comp<BidirectionalIterator<const int*>, Sentinel<const int*>>();
test_iter_comp<RandomAccessIterator<const int*>, Sentinel<const int*>>();
// Works with projections?
S s[] = {S{1},S{2},S{3},S{4},S{40},S{5},S{6},S{7},S{8},S{9}};
S v = ranges::max(s, std::less<int>{}, &S::i);
CHECK(v.i == 40);
// Works with initializer_lists? (Regression test for #1004)
CHECK(ranges::max({4,3,1,2,6,5}) == 6);
return test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/is_heap.hpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright 2005 - 2007 Adobe Systems Incorporated
// Distributed under the MIT License(see accompanying file LICENSE_1_0_0.txt
// or a copy at http://stlab.adobe.com/licenses.html)
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Implementation based on the code in libc++
// http://http://libcxx.llvm.org/
#include <algorithm>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/heap_algorithm.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
void test()
{
#if defined(IS_HEAP_1) || defined(IS_HEAP_2)
auto is_heap = make_testable_1(ranges::is_heap);
#endif
#ifdef IS_HEAP_1
int i1[] = {0, 0};
is_heap(i1, i1).check([&](bool r){ CHECK(r); });
is_heap(i1, i1+1).check([&](bool r){ CHECK(r == (std::is_heap_until(i1, i1+1) == i1+1)); });
int i2[] = {0, 1};
int i3[] = {1, 0};
is_heap(i1, i1+2).check([&](bool r){ CHECK(r == (std::is_heap_until(i1, i1+2) == i1+2)); });
is_heap(i2, i2+2).check([&](bool r){ CHECK(r == (std::is_heap_until(i2, i2+2) == i2+2)); });
is_heap(i3, i3+2).check([&](bool r){ CHECK(r == (std::is_heap_until(i3, i3+2) == i3+2)); });
int i4[] = {0, 0, 0};
int i5[] = {0, 0, 1};
int i6[] = {0, 1, 0};
int i7[] = {0, 1, 1};
int i8[] = {1, 0, 0};
int i9[] = {1, 0, 1};
int i10[] = {1, 1, 0};
is_heap(i4, i4+3).check([&](bool r){ CHECK(r == (std::is_heap_until(i4, i4+3) == i4+3)); });
is_heap(i5, i5+3).check([&](bool r){ CHECK(r == (std::is_heap_until(i5, i5+3) == i5+3)); });
is_heap(i6, i6+3).check([&](bool r){ CHECK(r == (std::is_heap_until(i6, i6+3) == i6+3)); });
is_heap(i7, i7+3).check([&](bool r){ CHECK(r == (std::is_heap_until(i7, i7+3) == i7+3)); });
is_heap(i8, i8+3).check([&](bool r){ CHECK(r == (std::is_heap_until(i8, i8+3) == i8+3)); });
is_heap(i9, i9+3).check([&](bool r){ CHECK(r == (std::is_heap_until(i9, i9+3) == i9+3)); });
is_heap(i10, i10+3).check([&](bool r){ CHECK(r == (std::is_heap_until(i10, i10+3) == i10+3)); });
int i11[] = {0, 0, 0, 0};
int i12[] = {0, 0, 0, 1};
int i13[] = {0, 0, 1, 0};
int i14[] = {0, 0, 1, 1};
int i15[] = {0, 1, 0, 0};
int i16[] = {0, 1, 0, 1};
int i17[] = {0, 1, 1, 0};
int i18[] = {0, 1, 1, 1};
int i19[] = {1, 0, 0, 0};
int i20[] = {1, 0, 0, 1};
int i21[] = {1, 0, 1, 0};
int i22[] = {1, 0, 1, 1};
int i23[] = {1, 1, 0, 0};
int i24[] = {1, 1, 0, 1};
int i25[] = {1, 1, 1, 0};
is_heap(i11, i11+4).check([&](bool r){ CHECK(r == (std::is_heap_until(i11, i11+4) == i11+4)); });
is_heap(i12, i12+4).check([&](bool r){ CHECK(r == (std::is_heap_until(i12, i12+4) == i12+4)); });
is_heap(i13, i13+4).check([&](bool r){ CHECK(r == (std::is_heap_until(i13, i13+4) == i13+4)); });
is_heap(i14, i14+4).check([&](bool r){ CHECK(r == (std::is_heap_until(i14, i14+4) == i14+4)); });
is_heap(i15, i15+4).check([&](bool r){ CHECK(r == (std::is_heap_until(i15, i15+4) == i15+4)); });
is_heap(i16, i16+4).check([&](bool r){ CHECK(r == (std::is_heap_until(i16, i16+4) == i16+4)); });
is_heap(i17, i17+4).check([&](bool r){ CHECK(r == (std::is_heap_until(i17, i17+4) == i17+4)); });
is_heap(i18, i18+4).check([&](bool r){ CHECK(r == (std::is_heap_until(i18, i18+4) == i18+4)); });
is_heap(i19, i19+4).check([&](bool r){ CHECK(r == (std::is_heap_until(i19, i19+4) == i19+4)); });
is_heap(i20, i20+4).check([&](bool r){ CHECK(r == (std::is_heap_until(i20, i20+4) == i20+4)); });
is_heap(i21, i21+4).check([&](bool r){ CHECK(r == (std::is_heap_until(i21, i21+4) == i21+4)); });
is_heap(i22, i22+4).check([&](bool r){ CHECK(r == (std::is_heap_until(i22, i22+4) == i22+4)); });
is_heap(i23, i23+4).check([&](bool r){ CHECK(r == (std::is_heap_until(i23, i23+4) == i23+4)); });
is_heap(i24, i24+4).check([&](bool r){ CHECK(r == (std::is_heap_until(i24, i24+4) == i24+4)); });
is_heap(i25, i25+4).check([&](bool r){ CHECK(r == (std::is_heap_until(i25, i25+4) == i25+4)); });
int i26[] = {0, 0, 0, 0, 0};
int i27[] = {0, 0, 0, 0, 1};
int i28[] = {0, 0, 0, 1, 0};
int i29[] = {0, 0, 0, 1, 1};
int i30[] = {0, 0, 1, 0, 0};
int i31[] = {0, 0, 1, 0, 1};
int i32[] = {0, 0, 1, 1, 0};
int i33[] = {0, 0, 1, 1, 1};
int i34[] = {0, 1, 0, 0, 0};
int i35[] = {0, 1, 0, 0, 1};
int i36[] = {0, 1, 0, 1, 0};
int i37[] = {0, 1, 0, 1, 1};
int i38[] = {0, 1, 1, 0, 0};
int i39[] = {0, 1, 1, 0, 1};
int i40[] = {0, 1, 1, 1, 0};
int i41[] = {0, 1, 1, 1, 1};
int i42[] = {1, 0, 0, 0, 0};
int i43[] = {1, 0, 0, 0, 1};
int i44[] = {1, 0, 0, 1, 0};
int i45[] = {1, 0, 0, 1, 1};
int i46[] = {1, 0, 1, 0, 0};
int i47[] = {1, 0, 1, 0, 1};
int i48[] = {1, 0, 1, 1, 0};
int i49[] = {1, 0, 1, 1, 1};
int i50[] = {1, 1, 0, 0, 0};
int i51[] = {1, 1, 0, 0, 1};
int i52[] = {1, 1, 0, 1, 0};
int i53[] = {1, 1, 0, 1, 1};
int i54[] = {1, 1, 1, 0, 0};
int i55[] = {1, 1, 1, 0, 1};
int i56[] = {1, 1, 1, 1, 0};
is_heap(i26, i26+5).check([&](bool r){ CHECK(r == (std::is_heap_until(i26, i26+5) == i26+5)); });
is_heap(i27, i27+5).check([&](bool r){ CHECK(r == (std::is_heap_until(i27, i27+5) == i27+5)); });
is_heap(i28, i28+5).check([&](bool r){ CHECK(r == (std::is_heap_until(i28, i28+5) == i28+5)); });
is_heap(i29, i29+5).check([&](bool r){ CHECK(r == (std::is_heap_until(i29, i29+5) == i29+5)); });
is_heap(i30, i30+5).check([&](bool r){ CHECK(r == (std::is_heap_until(i30, i30+5) == i30+5)); });
is_heap(i31, i31+5).check([&](bool r){ CHECK(r == (std::is_heap_until(i31, i31+5) == i31+5)); });
is_heap(i32, i32+5).check([&](bool r){ CHECK(r == (std::is_heap_until(i32, i32+5) == i32+5)); });
is_heap(i33, i33+5).check([&](bool r){ CHECK(r == (std::is_heap_until(i33, i33+5) == i33+5)); });
is_heap(i34, i34+5).check([&](bool r){ CHECK(r == (std::is_heap_until(i34, i34+5) == i34+5)); });
is_heap(i35, i35+5).check([&](bool r){ CHECK(r == (std::is_heap_until(i35, i35+5) == i35+5)); });
is_heap(i36, i36+5).check([&](bool r){ CHECK(r == (std::is_heap_until(i36, i36+5) == i36+5)); });
is_heap(i37, i37+5).check([&](bool r){ CHECK(r == (std::is_heap_until(i37, i37+5) == i37+5)); });
is_heap(i38, i38+5).check([&](bool r){ CHECK(r == (std::is_heap_until(i38, i38+5) == i38+5)); });
is_heap(i39, i39+5).check([&](bool r){ CHECK(r == (std::is_heap_until(i39, i39+5) == i39+5)); });
is_heap(i40, i40+5).check([&](bool r){ CHECK(r == (std::is_heap_until(i40, i40+5) == i40+5)); });
is_heap(i41, i41+5).check([&](bool r){ CHECK(r == (std::is_heap_until(i41, i41+5) == i41+5)); });
is_heap(i42, i42+5).check([&](bool r){ CHECK(r == (std::is_heap_until(i42, i42+5) == i42+5)); });
is_heap(i43, i43+5).check([&](bool r){ CHECK(r == (std::is_heap_until(i43, i43+5) == i43+5)); });
is_heap(i44, i44+5).check([&](bool r){ CHECK(r == (std::is_heap_until(i44, i44+5) == i44+5)); });
is_heap(i45, i45+5).check([&](bool r){ CHECK(r == (std::is_heap_until(i45, i45+5) == i45+5)); });
is_heap(i46, i46+5).check([&](bool r){ CHECK(r == (std::is_heap_until(i46, i46+5) == i46+5)); });
is_heap(i47, i47+5).check([&](bool r){ CHECK(r == (std::is_heap_until(i47, i47+5) == i47+5)); });
is_heap(i48, i48+5).check([&](bool r){ CHECK(r == (std::is_heap_until(i48, i48+5) == i48+5)); });
is_heap(i49, i49+5).check([&](bool r){ CHECK(r == (std::is_heap_until(i49, i49+5) == i49+5)); });
is_heap(i50, i50+5).check([&](bool r){ CHECK(r == (std::is_heap_until(i50, i50+5) == i50+5)); });
is_heap(i51, i51+5).check([&](bool r){ CHECK(r == (std::is_heap_until(i51, i51+5) == i51+5)); });
is_heap(i52, i52+5).check([&](bool r){ CHECK(r == (std::is_heap_until(i52, i52+5) == i52+5)); });
is_heap(i53, i53+5).check([&](bool r){ CHECK(r == (std::is_heap_until(i53, i53+5) == i53+5)); });
is_heap(i54, i54+5).check([&](bool r){ CHECK(r == (std::is_heap_until(i54, i54+5) == i54+5)); });
is_heap(i55, i55+5).check([&](bool r){ CHECK(r == (std::is_heap_until(i55, i55+5) == i55+5)); });
is_heap(i56, i56+5).check([&](bool r){ CHECK(r == (std::is_heap_until(i56, i56+5) == i56+5)); });
int i57[] = {0, 0, 0, 0, 0, 0};
int i58[] = {0, 0, 0, 0, 0, 1};
int i59[] = {0, 0, 0, 0, 1, 0};
int i60[] = {0, 0, 0, 0, 1, 1};
int i61[] = {0, 0, 0, 1, 0, 0};
int i62[] = {0, 0, 0, 1, 0, 1};
int i63[] = {0, 0, 0, 1, 1, 0};
int i64[] = {0, 0, 0, 1, 1, 1};
int i65[] = {0, 0, 1, 0, 0, 0};
int i66[] = {0, 0, 1, 0, 0, 1};
int i67[] = {0, 0, 1, 0, 1, 0};
int i68[] = {0, 0, 1, 0, 1, 1};
int i69[] = {0, 0, 1, 1, 0, 0};
int i70[] = {0, 0, 1, 1, 0, 1};
int i71[] = {0, 0, 1, 1, 1, 0};
int i72[] = {0, 0, 1, 1, 1, 1};
int i73[] = {0, 1, 0, 0, 0, 0};
int i74[] = {0, 1, 0, 0, 0, 1};
int i75[] = {0, 1, 0, 0, 1, 0};
int i76[] = {0, 1, 0, 0, 1, 1};
int i77[] = {0, 1, 0, 1, 0, 0};
int i78[] = {0, 1, 0, 1, 0, 1};
int i79[] = {0, 1, 0, 1, 1, 0};
int i80[] = {0, 1, 0, 1, 1, 1};
int i81[] = {0, 1, 1, 0, 0, 0};
int i82[] = {0, 1, 1, 0, 0, 1};
int i83[] = {0, 1, 1, 0, 1, 0};
int i84[] = {0, 1, 1, 0, 1, 1};
int i85[] = {0, 1, 1, 1, 0, 0};
int i86[] = {0, 1, 1, 1, 0, 1};
int i87[] = {0, 1, 1, 1, 1, 0};
int i88[] = {0, 1, 1, 1, 1, 1};
int i89[] = {1, 0, 0, 0, 0, 0};
int i90[] = {1, 0, 0, 0, 0, 1};
int i91[] = {1, 0, 0, 0, 1, 0};
int i92[] = {1, 0, 0, 0, 1, 1};
int i93[] = {1, 0, 0, 1, 0, 0};
int i94[] = {1, 0, 0, 1, 0, 1};
int i95[] = {1, 0, 0, 1, 1, 0};
int i96[] = {1, 0, 0, 1, 1, 1};
int i97[] = {1, 0, 1, 0, 0, 0};
int i98[] = {1, 0, 1, 0, 0, 1};
int i99[] = {1, 0, 1, 0, 1, 0};
int i100[] = {1, 0, 1, 0, 1, 1};
int i101[] = {1, 0, 1, 1, 0, 0};
int i102[] = {1, 0, 1, 1, 0, 1};
int i103[] = {1, 0, 1, 1, 1, 0};
int i104[] = {1, 0, 1, 1, 1, 1};
int i105[] = {1, 1, 0, 0, 0, 0};
int i106[] = {1, 1, 0, 0, 0, 1};
int i107[] = {1, 1, 0, 0, 1, 0};
int i108[] = {1, 1, 0, 0, 1, 1};
int i109[] = {1, 1, 0, 1, 0, 0};
int i110[] = {1, 1, 0, 1, 0, 1};
int i111[] = {1, 1, 0, 1, 1, 0};
int i112[] = {1, 1, 0, 1, 1, 1};
int i113[] = {1, 1, 1, 0, 0, 0};
int i114[] = {1, 1, 1, 0, 0, 1};
int i115[] = {1, 1, 1, 0, 1, 0};
int i116[] = {1, 1, 1, 0, 1, 1};
int i117[] = {1, 1, 1, 1, 0, 0};
int i118[] = {1, 1, 1, 1, 0, 1};
int i119[] = {1, 1, 1, 1, 1, 0};
is_heap(i57, i57+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i57, i57+6) == i57+6)); });
is_heap(i58, i58+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i58, i58+6) == i58+6)); });
is_heap(i59, i59+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i59, i59+6) == i59+6)); });
is_heap(i60, i60+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i60, i60+6) == i60+6)); });
is_heap(i61, i61+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i61, i61+6) == i61+6)); });
is_heap(i62, i62+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i62, i62+6) == i62+6)); });
is_heap(i63, i63+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i63, i63+6) == i63+6)); });
is_heap(i64, i64+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i64, i64+6) == i64+6)); });
is_heap(i65, i65+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i65, i65+6) == i65+6)); });
is_heap(i66, i66+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i66, i66+6) == i66+6)); });
is_heap(i67, i67+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i67, i67+6) == i67+6)); });
is_heap(i68, i68+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i68, i68+6) == i68+6)); });
is_heap(i69, i69+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i69, i69+6) == i69+6)); });
is_heap(i70, i70+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i70, i70+6) == i70+6)); });
is_heap(i71, i71+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i71, i71+6) == i71+6)); });
is_heap(i72, i72+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i72, i72+6) == i72+6)); });
is_heap(i73, i73+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i73, i73+6) == i73+6)); });
is_heap(i74, i74+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i74, i74+6) == i74+6)); });
is_heap(i75, i75+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i75, i75+6) == i75+6)); });
is_heap(i76, i76+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i76, i76+6) == i76+6)); });
is_heap(i77, i77+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i77, i77+6) == i77+6)); });
is_heap(i78, i78+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i78, i78+6) == i78+6)); });
is_heap(i79, i79+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i79, i79+6) == i79+6)); });
is_heap(i80, i80+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i80, i80+6) == i80+6)); });
is_heap(i81, i81+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i81, i81+6) == i81+6)); });
is_heap(i82, i82+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i82, i82+6) == i82+6)); });
is_heap(i83, i83+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i83, i83+6) == i83+6)); });
is_heap(i84, i84+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i84, i84+6) == i84+6)); });
is_heap(i85, i85+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i85, i85+6) == i85+6)); });
is_heap(i86, i86+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i86, i86+6) == i86+6)); });
is_heap(i87, i87+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i87, i87+6) == i87+6)); });
is_heap(i88, i88+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i88, i88+6) == i88+6)); });
is_heap(i89, i89+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i89, i89+6) == i89+6)); });
is_heap(i90, i90+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i90, i90+6) == i90+6)); });
is_heap(i91, i91+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i91, i91+6) == i91+6)); });
is_heap(i92, i92+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i92, i92+6) == i92+6)); });
is_heap(i93, i93+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i93, i93+6) == i93+6)); });
is_heap(i94, i94+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i94, i94+6) == i94+6)); });
is_heap(i95, i95+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i95, i95+6) == i95+6)); });
is_heap(i96, i96+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i96, i96+6) == i96+6)); });
is_heap(i97, i97+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i97, i97+6) == i97+6)); });
is_heap(i98, i98+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i98, i98+6) == i98+6)); });
is_heap(i99, i99+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i99, i99+6) == i99+6)); });
is_heap(i100, i100+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i100, i100+6) == i100+6)); });
is_heap(i101, i101+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i101, i101+6) == i101+6)); });
is_heap(i102, i102+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i102, i102+6) == i102+6)); });
is_heap(i103, i103+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i103, i103+6) == i103+6)); });
is_heap(i104, i104+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i104, i104+6) == i104+6)); });
is_heap(i105, i105+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i105, i105+6) == i105+6)); });
is_heap(i106, i106+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i106, i106+6) == i106+6)); });
is_heap(i107, i107+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i107, i107+6) == i107+6)); });
is_heap(i108, i108+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i108, i108+6) == i108+6)); });
is_heap(i109, i109+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i109, i109+6) == i109+6)); });
is_heap(i110, i110+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i110, i110+6) == i110+6)); });
is_heap(i111, i111+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i111, i111+6) == i111+6)); });
is_heap(i112, i112+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i112, i112+6) == i112+6)); });
is_heap(i113, i113+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i113, i113+6) == i113+6)); });
is_heap(i114, i114+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i114, i114+6) == i114+6)); });
is_heap(i115, i115+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i115, i115+6) == i115+6)); });
is_heap(i116, i116+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i116, i116+6) == i116+6)); });
is_heap(i117, i117+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i117, i117+6) == i117+6)); });
is_heap(i118, i118+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i118, i118+6) == i118+6)); });
is_heap(i119, i119+6).check([&](bool r){ CHECK(r == (std::is_heap_until(i119, i119+6) == i119+6)); });
#endif
#ifdef IS_HEAP_2
int i120[] = {0, 0, 0, 0, 0, 0, 0};
int i121[] = {0, 0, 0, 0, 0, 0, 1};
int i122[] = {0, 0, 0, 0, 0, 1, 0};
int i123[] = {0, 0, 0, 0, 0, 1, 1};
int i124[] = {0, 0, 0, 0, 1, 0, 0};
int i125[] = {0, 0, 0, 0, 1, 0, 1};
int i126[] = {0, 0, 0, 0, 1, 1, 0};
int i127[] = {0, 0, 0, 0, 1, 1, 1};
int i128[] = {0, 0, 0, 1, 0, 0, 0};
int i129[] = {0, 0, 0, 1, 0, 0, 1};
int i130[] = {0, 0, 0, 1, 0, 1, 0};
int i131[] = {0, 0, 0, 1, 0, 1, 1};
int i132[] = {0, 0, 0, 1, 1, 0, 0};
int i133[] = {0, 0, 0, 1, 1, 0, 1};
int i134[] = {0, 0, 0, 1, 1, 1, 0};
int i135[] = {0, 0, 0, 1, 1, 1, 1};
int i136[] = {0, 0, 1, 0, 0, 0, 0};
int i137[] = {0, 0, 1, 0, 0, 0, 1};
int i138[] = {0, 0, 1, 0, 0, 1, 0};
int i139[] = {0, 0, 1, 0, 0, 1, 1};
int i140[] = {0, 0, 1, 0, 1, 0, 0};
int i141[] = {0, 0, 1, 0, 1, 0, 1};
int i142[] = {0, 0, 1, 0, 1, 1, 0};
int i143[] = {0, 0, 1, 0, 1, 1, 1};
int i144[] = {0, 0, 1, 1, 0, 0, 0};
int i145[] = {0, 0, 1, 1, 0, 0, 1};
int i146[] = {0, 0, 1, 1, 0, 1, 0};
int i147[] = {0, 0, 1, 1, 0, 1, 1};
int i148[] = {0, 0, 1, 1, 1, 0, 0};
int i149[] = {0, 0, 1, 1, 1, 0, 1};
int i150[] = {0, 0, 1, 1, 1, 1, 0};
int i151[] = {0, 0, 1, 1, 1, 1, 1};
int i152[] = {0, 1, 0, 0, 0, 0, 0};
int i153[] = {0, 1, 0, 0, 0, 0, 1};
int i154[] = {0, 1, 0, 0, 0, 1, 0};
int i155[] = {0, 1, 0, 0, 0, 1, 1};
int i156[] = {0, 1, 0, 0, 1, 0, 0};
int i157[] = {0, 1, 0, 0, 1, 0, 1};
int i158[] = {0, 1, 0, 0, 1, 1, 0};
int i159[] = {0, 1, 0, 0, 1, 1, 1};
int i160[] = {0, 1, 0, 1, 0, 0, 0};
int i161[] = {0, 1, 0, 1, 0, 0, 1};
int i162[] = {0, 1, 0, 1, 0, 1, 0};
int i163[] = {0, 1, 0, 1, 0, 1, 1};
int i164[] = {0, 1, 0, 1, 1, 0, 0};
int i165[] = {0, 1, 0, 1, 1, 0, 1};
int i166[] = {0, 1, 0, 1, 1, 1, 0};
int i167[] = {0, 1, 0, 1, 1, 1, 1};
int i168[] = {0, 1, 1, 0, 0, 0, 0};
int i169[] = {0, 1, 1, 0, 0, 0, 1};
int i170[] = {0, 1, 1, 0, 0, 1, 0};
int i171[] = {0, 1, 1, 0, 0, 1, 1};
int i172[] = {0, 1, 1, 0, 1, 0, 0};
int i173[] = {0, 1, 1, 0, 1, 0, 1};
int i174[] = {0, 1, 1, 0, 1, 1, 0};
int i175[] = {0, 1, 1, 0, 1, 1, 1};
int i176[] = {0, 1, 1, 1, 0, 0, 0};
int i177[] = {0, 1, 1, 1, 0, 0, 1};
int i178[] = {0, 1, 1, 1, 0, 1, 0};
int i179[] = {0, 1, 1, 1, 0, 1, 1};
int i180[] = {0, 1, 1, 1, 1, 0, 0};
int i181[] = {0, 1, 1, 1, 1, 0, 1};
int i182[] = {0, 1, 1, 1, 1, 1, 0};
int i183[] = {0, 1, 1, 1, 1, 1, 1};
int i184[] = {1, 0, 0, 0, 0, 0, 0};
int i185[] = {1, 0, 0, 0, 0, 0, 1};
int i186[] = {1, 0, 0, 0, 0, 1, 0};
int i187[] = {1, 0, 0, 0, 0, 1, 1};
int i188[] = {1, 0, 0, 0, 1, 0, 0};
int i189[] = {1, 0, 0, 0, 1, 0, 1};
int i190[] = {1, 0, 0, 0, 1, 1, 0};
int i191[] = {1, 0, 0, 0, 1, 1, 1};
int i192[] = {1, 0, 0, 1, 0, 0, 0};
int i193[] = {1, 0, 0, 1, 0, 0, 1};
int i194[] = {1, 0, 0, 1, 0, 1, 0};
int i195[] = {1, 0, 0, 1, 0, 1, 1};
int i196[] = {1, 0, 0, 1, 1, 0, 0};
int i197[] = {1, 0, 0, 1, 1, 0, 1};
int i198[] = {1, 0, 0, 1, 1, 1, 0};
int i199[] = {1, 0, 0, 1, 1, 1, 1};
int i200[] = {1, 0, 1, 0, 0, 0, 0};
int i201[] = {1, 0, 1, 0, 0, 0, 1};
int i202[] = {1, 0, 1, 0, 0, 1, 0};
int i203[] = {1, 0, 1, 0, 0, 1, 1};
int i204[] = {1, 0, 1, 0, 1, 0, 0};
int i205[] = {1, 0, 1, 0, 1, 0, 1};
int i206[] = {1, 0, 1, 0, 1, 1, 0};
int i207[] = {1, 0, 1, 0, 1, 1, 1};
int i208[] = {1, 0, 1, 1, 0, 0, 0};
int i209[] = {1, 0, 1, 1, 0, 0, 1};
int i210[] = {1, 0, 1, 1, 0, 1, 0};
int i211[] = {1, 0, 1, 1, 0, 1, 1};
int i212[] = {1, 0, 1, 1, 1, 0, 0};
int i213[] = {1, 0, 1, 1, 1, 0, 1};
int i214[] = {1, 0, 1, 1, 1, 1, 0};
int i215[] = {1, 0, 1, 1, 1, 1, 1};
int i216[] = {1, 1, 0, 0, 0, 0, 0};
int i217[] = {1, 1, 0, 0, 0, 0, 1};
int i218[] = {1, 1, 0, 0, 0, 1, 0};
int i219[] = {1, 1, 0, 0, 0, 1, 1};
int i220[] = {1, 1, 0, 0, 1, 0, 0};
int i221[] = {1, 1, 0, 0, 1, 0, 1};
int i222[] = {1, 1, 0, 0, 1, 1, 0};
int i223[] = {1, 1, 0, 0, 1, 1, 1};
int i224[] = {1, 1, 0, 1, 0, 0, 0};
int i225[] = {1, 1, 0, 1, 0, 0, 1};
int i226[] = {1, 1, 0, 1, 0, 1, 0};
int i227[] = {1, 1, 0, 1, 0, 1, 1};
int i228[] = {1, 1, 0, 1, 1, 0, 0};
int i229[] = {1, 1, 0, 1, 1, 0, 1};
int i230[] = {1, 1, 0, 1, 1, 1, 0};
int i231[] = {1, 1, 0, 1, 1, 1, 1};
int i232[] = {1, 1, 1, 0, 0, 0, 0};
int i233[] = {1, 1, 1, 0, 0, 0, 1};
int i234[] = {1, 1, 1, 0, 0, 1, 0};
int i235[] = {1, 1, 1, 0, 0, 1, 1};
int i236[] = {1, 1, 1, 0, 1, 0, 0};
int i237[] = {1, 1, 1, 0, 1, 0, 1};
int i238[] = {1, 1, 1, 0, 1, 1, 0};
int i239[] = {1, 1, 1, 0, 1, 1, 1};
int i240[] = {1, 1, 1, 1, 0, 0, 0};
int i241[] = {1, 1, 1, 1, 0, 0, 1};
int i242[] = {1, 1, 1, 1, 0, 1, 0};
int i243[] = {1, 1, 1, 1, 0, 1, 1};
int i244[] = {1, 1, 1, 1, 1, 0, 0};
int i245[] = {1, 1, 1, 1, 1, 0, 1};
int i246[] = {1, 1, 1, 1, 1, 1, 0};
is_heap(i120, i120+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i120, i120+7) == i120+7)); });
is_heap(i121, i121+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i121, i121+7) == i121+7)); });
is_heap(i122, i122+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i122, i122+7) == i122+7)); });
is_heap(i123, i123+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i123, i123+7) == i123+7)); });
is_heap(i124, i124+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i124, i124+7) == i124+7)); });
is_heap(i125, i125+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i125, i125+7) == i125+7)); });
is_heap(i126, i126+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i126, i126+7) == i126+7)); });
is_heap(i127, i127+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i127, i127+7) == i127+7)); });
is_heap(i128, i128+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i128, i128+7) == i128+7)); });
is_heap(i129, i129+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i129, i129+7) == i129+7)); });
is_heap(i130, i130+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i130, i130+7) == i130+7)); });
is_heap(i131, i131+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i131, i131+7) == i131+7)); });
is_heap(i132, i132+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i132, i132+7) == i132+7)); });
is_heap(i133, i133+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i133, i133+7) == i133+7)); });
is_heap(i134, i134+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i134, i134+7) == i134+7)); });
is_heap(i135, i135+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i135, i135+7) == i135+7)); });
is_heap(i136, i136+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i136, i136+7) == i136+7)); });
is_heap(i137, i137+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i137, i137+7) == i137+7)); });
is_heap(i138, i138+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i138, i138+7) == i138+7)); });
is_heap(i139, i139+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i139, i139+7) == i139+7)); });
is_heap(i140, i140+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i140, i140+7) == i140+7)); });
is_heap(i141, i141+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i141, i141+7) == i141+7)); });
is_heap(i142, i142+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i142, i142+7) == i142+7)); });
is_heap(i143, i143+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i143, i143+7) == i143+7)); });
is_heap(i144, i144+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i144, i144+7) == i144+7)); });
is_heap(i145, i145+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i145, i145+7) == i145+7)); });
is_heap(i146, i146+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i146, i146+7) == i146+7)); });
is_heap(i147, i147+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i147, i147+7) == i147+7)); });
is_heap(i148, i148+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i148, i148+7) == i148+7)); });
is_heap(i149, i149+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i149, i149+7) == i149+7)); });
is_heap(i150, i150+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i150, i150+7) == i150+7)); });
is_heap(i151, i151+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i151, i151+7) == i151+7)); });
is_heap(i152, i152+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i152, i152+7) == i152+7)); });
is_heap(i153, i153+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i153, i153+7) == i153+7)); });
is_heap(i154, i154+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i154, i154+7) == i154+7)); });
is_heap(i155, i155+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i155, i155+7) == i155+7)); });
is_heap(i156, i156+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i156, i156+7) == i156+7)); });
is_heap(i157, i157+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i157, i157+7) == i157+7)); });
is_heap(i158, i158+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i158, i158+7) == i158+7)); });
is_heap(i159, i159+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i159, i159+7) == i159+7)); });
is_heap(i160, i160+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i160, i160+7) == i160+7)); });
is_heap(i161, i161+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i161, i161+7) == i161+7)); });
is_heap(i162, i162+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i162, i162+7) == i162+7)); });
is_heap(i163, i163+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i163, i163+7) == i163+7)); });
is_heap(i164, i164+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i164, i164+7) == i164+7)); });
is_heap(i165, i165+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i165, i165+7) == i165+7)); });
is_heap(i166, i166+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i166, i166+7) == i166+7)); });
is_heap(i167, i167+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i167, i167+7) == i167+7)); });
is_heap(i168, i168+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i168, i168+7) == i168+7)); });
is_heap(i169, i169+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i169, i169+7) == i169+7)); });
is_heap(i170, i170+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i170, i170+7) == i170+7)); });
is_heap(i171, i171+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i171, i171+7) == i171+7)); });
is_heap(i172, i172+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i172, i172+7) == i172+7)); });
is_heap(i173, i173+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i173, i173+7) == i173+7)); });
is_heap(i174, i174+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i174, i174+7) == i174+7)); });
is_heap(i175, i175+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i175, i175+7) == i175+7)); });
is_heap(i176, i176+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i176, i176+7) == i176+7)); });
is_heap(i177, i177+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i177, i177+7) == i177+7)); });
is_heap(i178, i178+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i178, i178+7) == i178+7)); });
is_heap(i179, i179+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i179, i179+7) == i179+7)); });
is_heap(i180, i180+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i180, i180+7) == i180+7)); });
is_heap(i181, i181+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i181, i181+7) == i181+7)); });
is_heap(i182, i182+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i182, i182+7) == i182+7)); });
is_heap(i183, i183+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i183, i183+7) == i183+7)); });
is_heap(i184, i184+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i184, i184+7) == i184+7)); });
is_heap(i185, i185+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i185, i185+7) == i185+7)); });
is_heap(i186, i186+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i186, i186+7) == i186+7)); });
is_heap(i187, i187+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i187, i187+7) == i187+7)); });
is_heap(i188, i188+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i188, i188+7) == i188+7)); });
is_heap(i189, i189+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i189, i189+7) == i189+7)); });
is_heap(i190, i190+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i190, i190+7) == i190+7)); });
is_heap(i191, i191+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i191, i191+7) == i191+7)); });
is_heap(i192, i192+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i192, i192+7) == i192+7)); });
is_heap(i193, i193+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i193, i193+7) == i193+7)); });
is_heap(i194, i194+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i194, i194+7) == i194+7)); });
is_heap(i195, i195+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i195, i195+7) == i195+7)); });
is_heap(i196, i196+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i196, i196+7) == i196+7)); });
is_heap(i197, i197+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i197, i197+7) == i197+7)); });
is_heap(i198, i198+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i198, i198+7) == i198+7)); });
is_heap(i199, i199+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i199, i199+7) == i199+7)); });
is_heap(i200, i200+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i200, i200+7) == i200+7)); });
is_heap(i201, i201+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i201, i201+7) == i201+7)); });
is_heap(i202, i202+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i202, i202+7) == i202+7)); });
is_heap(i203, i203+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i203, i203+7) == i203+7)); });
is_heap(i204, i204+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i204, i204+7) == i204+7)); });
is_heap(i205, i205+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i205, i205+7) == i205+7)); });
is_heap(i206, i206+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i206, i206+7) == i206+7)); });
is_heap(i207, i207+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i207, i207+7) == i207+7)); });
is_heap(i208, i208+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i208, i208+7) == i208+7)); });
is_heap(i209, i209+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i209, i209+7) == i209+7)); });
is_heap(i210, i210+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i210, i210+7) == i210+7)); });
is_heap(i211, i211+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i211, i211+7) == i211+7)); });
is_heap(i212, i212+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i212, i212+7) == i212+7)); });
is_heap(i213, i213+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i213, i213+7) == i213+7)); });
is_heap(i214, i214+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i214, i214+7) == i214+7)); });
is_heap(i215, i215+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i215, i215+7) == i215+7)); });
is_heap(i216, i216+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i216, i216+7) == i216+7)); });
is_heap(i217, i217+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i217, i217+7) == i217+7)); });
is_heap(i218, i218+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i218, i218+7) == i218+7)); });
is_heap(i219, i219+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i219, i219+7) == i219+7)); });
is_heap(i220, i220+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i220, i220+7) == i220+7)); });
is_heap(i221, i221+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i221, i221+7) == i221+7)); });
is_heap(i222, i222+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i222, i222+7) == i222+7)); });
is_heap(i223, i223+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i223, i223+7) == i223+7)); });
is_heap(i224, i224+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i224, i224+7) == i224+7)); });
is_heap(i225, i225+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i225, i225+7) == i225+7)); });
is_heap(i226, i226+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i226, i226+7) == i226+7)); });
is_heap(i227, i227+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i227, i227+7) == i227+7)); });
is_heap(i228, i228+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i228, i228+7) == i228+7)); });
is_heap(i229, i229+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i229, i229+7) == i229+7)); });
is_heap(i230, i230+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i230, i230+7) == i230+7)); });
is_heap(i231, i231+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i231, i231+7) == i231+7)); });
is_heap(i232, i232+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i232, i232+7) == i232+7)); });
is_heap(i233, i233+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i233, i233+7) == i233+7)); });
is_heap(i234, i234+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i234, i234+7) == i234+7)); });
is_heap(i235, i235+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i235, i235+7) == i235+7)); });
is_heap(i236, i236+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i236, i236+7) == i236+7)); });
is_heap(i237, i237+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i237, i237+7) == i237+7)); });
is_heap(i238, i238+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i238, i238+7) == i238+7)); });
is_heap(i239, i239+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i239, i239+7) == i239+7)); });
is_heap(i240, i240+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i240, i240+7) == i240+7)); });
is_heap(i241, i241+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i241, i241+7) == i241+7)); });
is_heap(i242, i242+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i242, i242+7) == i242+7)); });
is_heap(i243, i243+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i243, i243+7) == i243+7)); });
is_heap(i244, i244+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i244, i244+7) == i244+7)); });
is_heap(i245, i245+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i245, i245+7) == i245+7)); });
is_heap(i246, i246+7).check([&](bool r){ CHECK(r == (std::is_heap_until(i246, i246+7) == i246+7)); });
#endif
}
void test_comp()
{
#if defined(IS_HEAP_3) || defined(IS_HEAP_4)
auto is_heap = make_testable_1(ranges::is_heap);
#endif
#ifdef IS_HEAP_3
int i1[] = {0, 0};
is_heap(i1, i1, std::greater<int>()).check([&](bool r){ CHECK(r); });
is_heap(i1, i1+1, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i1, i1+1, std::greater<int>()) == i1+1)); });
int i2[] = {0, 1};
int i3[] = {1, 0};
is_heap(i1, i1+2, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i1, i1+2, std::greater<int>()) == i1+2)); });
is_heap(i2, i2+2, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i2, i2+2, std::greater<int>()) == i2+2)); });
is_heap(i3, i3+2, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i3, i3+2, std::greater<int>()) == i3+2)); });
int i4[] = {0, 0, 0};
int i5[] = {0, 0, 1};
int i6[] = {0, 1, 0};
int i7[] = {0, 1, 1};
int i8[] = {1, 0, 0};
int i9[] = {1, 0, 1};
int i10[] = {1, 1, 0};
is_heap(i4, i4+3, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i4, i4+3, std::greater<int>()) == i4+3)); });
is_heap(i5, i5+3, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i5, i5+3, std::greater<int>()) == i5+3)); });
is_heap(i6, i6+3, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i6, i6+3, std::greater<int>()) == i6+3)); });
is_heap(i7, i7+3, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i7, i7+3, std::greater<int>()) == i7+3)); });
is_heap(i8, i8+3, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i8, i8+3, std::greater<int>()) == i8+3)); });
is_heap(i9, i9+3, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i9, i9+3, std::greater<int>()) == i9+3)); });
is_heap(i10, i10+3, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i10, i10+3, std::greater<int>()) == i10+3)); });
int i11[] = {0, 0, 0, 0};
int i12[] = {0, 0, 0, 1};
int i13[] = {0, 0, 1, 0};
int i14[] = {0, 0, 1, 1};
int i15[] = {0, 1, 0, 0};
int i16[] = {0, 1, 0, 1};
int i17[] = {0, 1, 1, 0};
int i18[] = {0, 1, 1, 1};
int i19[] = {1, 0, 0, 0};
int i20[] = {1, 0, 0, 1};
int i21[] = {1, 0, 1, 0};
int i22[] = {1, 0, 1, 1};
int i23[] = {1, 1, 0, 0};
int i24[] = {1, 1, 0, 1};
int i25[] = {1, 1, 1, 0};
is_heap(i11, i11+4, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i11, i11+4, std::greater<int>()) == i11+4)); });
is_heap(i12, i12+4, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i12, i12+4, std::greater<int>()) == i12+4)); });
is_heap(i13, i13+4, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i13, i13+4, std::greater<int>()) == i13+4)); });
is_heap(i14, i14+4, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i14, i14+4, std::greater<int>()) == i14+4)); });
is_heap(i15, i15+4, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i15, i15+4, std::greater<int>()) == i15+4)); });
is_heap(i16, i16+4, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i16, i16+4, std::greater<int>()) == i16+4)); });
is_heap(i17, i17+4, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i17, i17+4, std::greater<int>()) == i17+4)); });
is_heap(i18, i18+4, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i18, i18+4, std::greater<int>()) == i18+4)); });
is_heap(i19, i19+4, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i19, i19+4, std::greater<int>()) == i19+4)); });
is_heap(i20, i20+4, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i20, i20+4, std::greater<int>()) == i20+4)); });
is_heap(i21, i21+4, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i21, i21+4, std::greater<int>()) == i21+4)); });
is_heap(i22, i22+4, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i22, i22+4, std::greater<int>()) == i22+4)); });
is_heap(i23, i23+4, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i23, i23+4, std::greater<int>()) == i23+4)); });
is_heap(i24, i24+4, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i24, i24+4, std::greater<int>()) == i24+4)); });
is_heap(i25, i25+4, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i25, i25+4, std::greater<int>()) == i25+4)); });
int i26[] = {0, 0, 0, 0, 0};
int i27[] = {0, 0, 0, 0, 1};
int i28[] = {0, 0, 0, 1, 0};
int i29[] = {0, 0, 0, 1, 1};
int i30[] = {0, 0, 1, 0, 0};
int i31[] = {0, 0, 1, 0, 1};
int i32[] = {0, 0, 1, 1, 0};
int i33[] = {0, 0, 1, 1, 1};
int i34[] = {0, 1, 0, 0, 0};
int i35[] = {0, 1, 0, 0, 1};
int i36[] = {0, 1, 0, 1, 0};
int i37[] = {0, 1, 0, 1, 1};
int i38[] = {0, 1, 1, 0, 0};
int i39[] = {0, 1, 1, 0, 1};
int i40[] = {0, 1, 1, 1, 0};
int i41[] = {0, 1, 1, 1, 1};
int i42[] = {1, 0, 0, 0, 0};
int i43[] = {1, 0, 0, 0, 1};
int i44[] = {1, 0, 0, 1, 0};
int i45[] = {1, 0, 0, 1, 1};
int i46[] = {1, 0, 1, 0, 0};
int i47[] = {1, 0, 1, 0, 1};
int i48[] = {1, 0, 1, 1, 0};
int i49[] = {1, 0, 1, 1, 1};
int i50[] = {1, 1, 0, 0, 0};
int i51[] = {1, 1, 0, 0, 1};
int i52[] = {1, 1, 0, 1, 0};
int i53[] = {1, 1, 0, 1, 1};
int i54[] = {1, 1, 1, 0, 0};
int i55[] = {1, 1, 1, 0, 1};
int i56[] = {1, 1, 1, 1, 0};
is_heap(i26, i26+5, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i26, i26+5, std::greater<int>()) == i26+5)); });
is_heap(i27, i27+5, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i27, i27+5, std::greater<int>()) == i27+5)); });
is_heap(i28, i28+5, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i28, i28+5, std::greater<int>()) == i28+5)); });
is_heap(i29, i29+5, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i29, i29+5, std::greater<int>()) == i29+5)); });
is_heap(i30, i30+5, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i30, i30+5, std::greater<int>()) == i30+5)); });
is_heap(i31, i31+5, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i31, i31+5, std::greater<int>()) == i31+5)); });
is_heap(i32, i32+5, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i32, i32+5, std::greater<int>()) == i32+5)); });
is_heap(i33, i33+5, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i33, i33+5, std::greater<int>()) == i33+5)); });
is_heap(i34, i34+5, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i34, i34+5, std::greater<int>()) == i34+5)); });
is_heap(i35, i35+5, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i35, i35+5, std::greater<int>()) == i35+5)); });
is_heap(i36, i36+5, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i36, i36+5, std::greater<int>()) == i36+5)); });
is_heap(i37, i37+5, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i37, i37+5, std::greater<int>()) == i37+5)); });
is_heap(i38, i38+5, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i38, i38+5, std::greater<int>()) == i38+5)); });
is_heap(i39, i39+5, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i39, i39+5, std::greater<int>()) == i39+5)); });
is_heap(i40, i40+5, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i40, i40+5, std::greater<int>()) == i40+5)); });
is_heap(i41, i41+5, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i41, i41+5, std::greater<int>()) == i41+5)); });
is_heap(i42, i42+5, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i42, i42+5, std::greater<int>()) == i42+5)); });
is_heap(i43, i43+5, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i43, i43+5, std::greater<int>()) == i43+5)); });
is_heap(i44, i44+5, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i44, i44+5, std::greater<int>()) == i44+5)); });
is_heap(i45, i45+5, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i45, i45+5, std::greater<int>()) == i45+5)); });
is_heap(i46, i46+5, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i46, i46+5, std::greater<int>()) == i46+5)); });
is_heap(i47, i47+5, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i47, i47+5, std::greater<int>()) == i47+5)); });
is_heap(i48, i48+5, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i48, i48+5, std::greater<int>()) == i48+5)); });
is_heap(i49, i49+5, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i49, i49+5, std::greater<int>()) == i49+5)); });
is_heap(i50, i50+5, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i50, i50+5, std::greater<int>()) == i50+5)); });
is_heap(i51, i51+5, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i51, i51+5, std::greater<int>()) == i51+5)); });
is_heap(i52, i52+5, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i52, i52+5, std::greater<int>()) == i52+5)); });
is_heap(i53, i53+5, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i53, i53+5, std::greater<int>()) == i53+5)); });
is_heap(i54, i54+5, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i54, i54+5, std::greater<int>()) == i54+5)); });
is_heap(i55, i55+5, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i55, i55+5, std::greater<int>()) == i55+5)); });
is_heap(i56, i56+5, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i56, i56+5, std::greater<int>()) == i56+5)); });
int i57[] = {0, 0, 0, 0, 0, 0};
int i58[] = {0, 0, 0, 0, 0, 1};
int i59[] = {0, 0, 0, 0, 1, 0};
int i60[] = {0, 0, 0, 0, 1, 1};
int i61[] = {0, 0, 0, 1, 0, 0};
int i62[] = {0, 0, 0, 1, 0, 1};
int i63[] = {0, 0, 0, 1, 1, 0};
int i64[] = {0, 0, 0, 1, 1, 1};
int i65[] = {0, 0, 1, 0, 0, 0};
int i66[] = {0, 0, 1, 0, 0, 1};
int i67[] = {0, 0, 1, 0, 1, 0};
int i68[] = {0, 0, 1, 0, 1, 1};
int i69[] = {0, 0, 1, 1, 0, 0};
int i70[] = {0, 0, 1, 1, 0, 1};
int i71[] = {0, 0, 1, 1, 1, 0};
int i72[] = {0, 0, 1, 1, 1, 1};
int i73[] = {0, 1, 0, 0, 0, 0};
int i74[] = {0, 1, 0, 0, 0, 1};
int i75[] = {0, 1, 0, 0, 1, 0};
int i76[] = {0, 1, 0, 0, 1, 1};
int i77[] = {0, 1, 0, 1, 0, 0};
int i78[] = {0, 1, 0, 1, 0, 1};
int i79[] = {0, 1, 0, 1, 1, 0};
int i80[] = {0, 1, 0, 1, 1, 1};
int i81[] = {0, 1, 1, 0, 0, 0};
int i82[] = {0, 1, 1, 0, 0, 1};
int i83[] = {0, 1, 1, 0, 1, 0};
int i84[] = {0, 1, 1, 0, 1, 1};
int i85[] = {0, 1, 1, 1, 0, 0};
int i86[] = {0, 1, 1, 1, 0, 1};
int i87[] = {0, 1, 1, 1, 1, 0};
int i88[] = {0, 1, 1, 1, 1, 1};
int i89[] = {1, 0, 0, 0, 0, 0};
int i90[] = {1, 0, 0, 0, 0, 1};
int i91[] = {1, 0, 0, 0, 1, 0};
int i92[] = {1, 0, 0, 0, 1, 1};
int i93[] = {1, 0, 0, 1, 0, 0};
int i94[] = {1, 0, 0, 1, 0, 1};
int i95[] = {1, 0, 0, 1, 1, 0};
int i96[] = {1, 0, 0, 1, 1, 1};
int i97[] = {1, 0, 1, 0, 0, 0};
int i98[] = {1, 0, 1, 0, 0, 1};
int i99[] = {1, 0, 1, 0, 1, 0};
int i100[] = {1, 0, 1, 0, 1, 1};
int i101[] = {1, 0, 1, 1, 0, 0};
int i102[] = {1, 0, 1, 1, 0, 1};
int i103[] = {1, 0, 1, 1, 1, 0};
int i104[] = {1, 0, 1, 1, 1, 1};
int i105[] = {1, 1, 0, 0, 0, 0};
int i106[] = {1, 1, 0, 0, 0, 1};
int i107[] = {1, 1, 0, 0, 1, 0};
int i108[] = {1, 1, 0, 0, 1, 1};
int i109[] = {1, 1, 0, 1, 0, 0};
int i110[] = {1, 1, 0, 1, 0, 1};
int i111[] = {1, 1, 0, 1, 1, 0};
int i112[] = {1, 1, 0, 1, 1, 1};
int i113[] = {1, 1, 1, 0, 0, 0};
int i114[] = {1, 1, 1, 0, 0, 1};
int i115[] = {1, 1, 1, 0, 1, 0};
int i116[] = {1, 1, 1, 0, 1, 1};
int i117[] = {1, 1, 1, 1, 0, 0};
int i118[] = {1, 1, 1, 1, 0, 1};
int i119[] = {1, 1, 1, 1, 1, 0};
is_heap(i57, i57+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i57, i57+6, std::greater<int>()) == i57+6)); });
is_heap(i58, i58+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i58, i58+6, std::greater<int>()) == i58+6)); });
is_heap(i59, i59+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i59, i59+6, std::greater<int>()) == i59+6)); });
is_heap(i60, i60+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i60, i60+6, std::greater<int>()) == i60+6)); });
is_heap(i61, i61+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i61, i61+6, std::greater<int>()) == i61+6)); });
is_heap(i62, i62+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i62, i62+6, std::greater<int>()) == i62+6)); });
is_heap(i63, i63+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i63, i63+6, std::greater<int>()) == i63+6)); });
is_heap(i64, i64+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i64, i64+6, std::greater<int>()) == i64+6)); });
is_heap(i65, i65+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i65, i65+6, std::greater<int>()) == i65+6)); });
is_heap(i66, i66+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i66, i66+6, std::greater<int>()) == i66+6)); });
is_heap(i67, i67+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i67, i67+6, std::greater<int>()) == i67+6)); });
is_heap(i68, i68+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i68, i68+6, std::greater<int>()) == i68+6)); });
is_heap(i69, i69+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i69, i69+6, std::greater<int>()) == i69+6)); });
is_heap(i70, i70+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i70, i70+6, std::greater<int>()) == i70+6)); });
is_heap(i71, i71+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i71, i71+6, std::greater<int>()) == i71+6)); });
is_heap(i72, i72+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i72, i72+6, std::greater<int>()) == i72+6)); });
is_heap(i73, i73+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i73, i73+6, std::greater<int>()) == i73+6)); });
is_heap(i74, i74+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i74, i74+6, std::greater<int>()) == i74+6)); });
is_heap(i75, i75+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i75, i75+6, std::greater<int>()) == i75+6)); });
is_heap(i76, i76+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i76, i76+6, std::greater<int>()) == i76+6)); });
is_heap(i77, i77+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i77, i77+6, std::greater<int>()) == i77+6)); });
is_heap(i78, i78+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i78, i78+6, std::greater<int>()) == i78+6)); });
is_heap(i79, i79+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i79, i79+6, std::greater<int>()) == i79+6)); });
is_heap(i80, i80+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i80, i80+6, std::greater<int>()) == i80+6)); });
is_heap(i81, i81+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i81, i81+6, std::greater<int>()) == i81+6)); });
is_heap(i82, i82+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i82, i82+6, std::greater<int>()) == i82+6)); });
is_heap(i83, i83+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i83, i83+6, std::greater<int>()) == i83+6)); });
is_heap(i84, i84+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i84, i84+6, std::greater<int>()) == i84+6)); });
is_heap(i85, i85+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i85, i85+6, std::greater<int>()) == i85+6)); });
is_heap(i86, i86+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i86, i86+6, std::greater<int>()) == i86+6)); });
is_heap(i87, i87+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i87, i87+6, std::greater<int>()) == i87+6)); });
is_heap(i88, i88+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i88, i88+6, std::greater<int>()) == i88+6)); });
is_heap(i89, i89+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i89, i89+6, std::greater<int>()) == i89+6)); });
is_heap(i90, i90+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i90, i90+6, std::greater<int>()) == i90+6)); });
is_heap(i91, i91+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i91, i91+6, std::greater<int>()) == i91+6)); });
is_heap(i92, i92+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i92, i92+6, std::greater<int>()) == i92+6)); });
is_heap(i93, i93+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i93, i93+6, std::greater<int>()) == i93+6)); });
is_heap(i94, i94+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i94, i94+6, std::greater<int>()) == i94+6)); });
is_heap(i95, i95+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i95, i95+6, std::greater<int>()) == i95+6)); });
is_heap(i96, i96+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i96, i96+6, std::greater<int>()) == i96+6)); });
is_heap(i97, i97+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i97, i97+6, std::greater<int>()) == i97+6)); });
is_heap(i98, i98+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i98, i98+6, std::greater<int>()) == i98+6)); });
is_heap(i99, i99+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i99, i99+6, std::greater<int>()) == i99+6)); });
is_heap(i100, i100+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i100, i100+6, std::greater<int>()) == i100+6)); });
is_heap(i101, i101+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i101, i101+6, std::greater<int>()) == i101+6)); });
is_heap(i102, i102+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i102, i102+6, std::greater<int>()) == i102+6)); });
is_heap(i103, i103+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i103, i103+6, std::greater<int>()) == i103+6)); });
is_heap(i104, i104+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i104, i104+6, std::greater<int>()) == i104+6)); });
is_heap(i105, i105+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i105, i105+6, std::greater<int>()) == i105+6)); });
is_heap(i106, i106+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i106, i106+6, std::greater<int>()) == i106+6)); });
is_heap(i107, i107+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i107, i107+6, std::greater<int>()) == i107+6)); });
is_heap(i108, i108+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i108, i108+6, std::greater<int>()) == i108+6)); });
is_heap(i109, i109+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i109, i109+6, std::greater<int>()) == i109+6)); });
is_heap(i110, i110+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i110, i110+6, std::greater<int>()) == i110+6)); });
is_heap(i111, i111+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i111, i111+6, std::greater<int>()) == i111+6)); });
is_heap(i112, i112+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i112, i112+6, std::greater<int>()) == i112+6)); });
is_heap(i113, i113+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i113, i113+6, std::greater<int>()) == i113+6)); });
is_heap(i114, i114+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i114, i114+6, std::greater<int>()) == i114+6)); });
is_heap(i115, i115+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i115, i115+6, std::greater<int>()) == i115+6)); });
is_heap(i116, i116+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i116, i116+6, std::greater<int>()) == i116+6)); });
is_heap(i117, i117+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i117, i117+6, std::greater<int>()) == i117+6)); });
is_heap(i118, i118+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i118, i118+6, std::greater<int>()) == i118+6)); });
is_heap(i119, i119+6, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i119, i119+6, std::greater<int>()) == i119+6)); });
#endif
#ifdef IS_HEAP_4
int i120[] = {0, 0, 0, 0, 0, 0, 0};
int i121[] = {0, 0, 0, 0, 0, 0, 1};
int i122[] = {0, 0, 0, 0, 0, 1, 0};
int i123[] = {0, 0, 0, 0, 0, 1, 1};
int i124[] = {0, 0, 0, 0, 1, 0, 0};
int i125[] = {0, 0, 0, 0, 1, 0, 1};
int i126[] = {0, 0, 0, 0, 1, 1, 0};
int i127[] = {0, 0, 0, 0, 1, 1, 1};
int i128[] = {0, 0, 0, 1, 0, 0, 0};
int i129[] = {0, 0, 0, 1, 0, 0, 1};
int i130[] = {0, 0, 0, 1, 0, 1, 0};
int i131[] = {0, 0, 0, 1, 0, 1, 1};
int i132[] = {0, 0, 0, 1, 1, 0, 0};
int i133[] = {0, 0, 0, 1, 1, 0, 1};
int i134[] = {0, 0, 0, 1, 1, 1, 0};
int i135[] = {0, 0, 0, 1, 1, 1, 1};
int i136[] = {0, 0, 1, 0, 0, 0, 0};
int i137[] = {0, 0, 1, 0, 0, 0, 1};
int i138[] = {0, 0, 1, 0, 0, 1, 0};
int i139[] = {0, 0, 1, 0, 0, 1, 1};
int i140[] = {0, 0, 1, 0, 1, 0, 0};
int i141[] = {0, 0, 1, 0, 1, 0, 1};
int i142[] = {0, 0, 1, 0, 1, 1, 0};
int i143[] = {0, 0, 1, 0, 1, 1, 1};
int i144[] = {0, 0, 1, 1, 0, 0, 0};
int i145[] = {0, 0, 1, 1, 0, 0, 1};
int i146[] = {0, 0, 1, 1, 0, 1, 0};
int i147[] = {0, 0, 1, 1, 0, 1, 1};
int i148[] = {0, 0, 1, 1, 1, 0, 0};
int i149[] = {0, 0, 1, 1, 1, 0, 1};
int i150[] = {0, 0, 1, 1, 1, 1, 0};
int i151[] = {0, 0, 1, 1, 1, 1, 1};
int i152[] = {0, 1, 0, 0, 0, 0, 0};
int i153[] = {0, 1, 0, 0, 0, 0, 1};
int i154[] = {0, 1, 0, 0, 0, 1, 0};
int i155[] = {0, 1, 0, 0, 0, 1, 1};
int i156[] = {0, 1, 0, 0, 1, 0, 0};
int i157[] = {0, 1, 0, 0, 1, 0, 1};
int i158[] = {0, 1, 0, 0, 1, 1, 0};
int i159[] = {0, 1, 0, 0, 1, 1, 1};
int i160[] = {0, 1, 0, 1, 0, 0, 0};
int i161[] = {0, 1, 0, 1, 0, 0, 1};
int i162[] = {0, 1, 0, 1, 0, 1, 0};
int i163[] = {0, 1, 0, 1, 0, 1, 1};
int i164[] = {0, 1, 0, 1, 1, 0, 0};
int i165[] = {0, 1, 0, 1, 1, 0, 1};
int i166[] = {0, 1, 0, 1, 1, 1, 0};
int i167[] = {0, 1, 0, 1, 1, 1, 1};
int i168[] = {0, 1, 1, 0, 0, 0, 0};
int i169[] = {0, 1, 1, 0, 0, 0, 1};
int i170[] = {0, 1, 1, 0, 0, 1, 0};
int i171[] = {0, 1, 1, 0, 0, 1, 1};
int i172[] = {0, 1, 1, 0, 1, 0, 0};
int i173[] = {0, 1, 1, 0, 1, 0, 1};
int i174[] = {0, 1, 1, 0, 1, 1, 0};
int i175[] = {0, 1, 1, 0, 1, 1, 1};
int i176[] = {0, 1, 1, 1, 0, 0, 0};
int i177[] = {0, 1, 1, 1, 0, 0, 1};
int i178[] = {0, 1, 1, 1, 0, 1, 0};
int i179[] = {0, 1, 1, 1, 0, 1, 1};
int i180[] = {0, 1, 1, 1, 1, 0, 0};
int i181[] = {0, 1, 1, 1, 1, 0, 1};
int i182[] = {0, 1, 1, 1, 1, 1, 0};
int i183[] = {0, 1, 1, 1, 1, 1, 1};
int i184[] = {1, 0, 0, 0, 0, 0, 0};
int i185[] = {1, 0, 0, 0, 0, 0, 1};
int i186[] = {1, 0, 0, 0, 0, 1, 0};
int i187[] = {1, 0, 0, 0, 0, 1, 1};
int i188[] = {1, 0, 0, 0, 1, 0, 0};
int i189[] = {1, 0, 0, 0, 1, 0, 1};
int i190[] = {1, 0, 0, 0, 1, 1, 0};
int i191[] = {1, 0, 0, 0, 1, 1, 1};
int i192[] = {1, 0, 0, 1, 0, 0, 0};
int i193[] = {1, 0, 0, 1, 0, 0, 1};
int i194[] = {1, 0, 0, 1, 0, 1, 0};
int i195[] = {1, 0, 0, 1, 0, 1, 1};
int i196[] = {1, 0, 0, 1, 1, 0, 0};
int i197[] = {1, 0, 0, 1, 1, 0, 1};
int i198[] = {1, 0, 0, 1, 1, 1, 0};
int i199[] = {1, 0, 0, 1, 1, 1, 1};
int i200[] = {1, 0, 1, 0, 0, 0, 0};
int i201[] = {1, 0, 1, 0, 0, 0, 1};
int i202[] = {1, 0, 1, 0, 0, 1, 0};
int i203[] = {1, 0, 1, 0, 0, 1, 1};
int i204[] = {1, 0, 1, 0, 1, 0, 0};
int i205[] = {1, 0, 1, 0, 1, 0, 1};
int i206[] = {1, 0, 1, 0, 1, 1, 0};
int i207[] = {1, 0, 1, 0, 1, 1, 1};
int i208[] = {1, 0, 1, 1, 0, 0, 0};
int i209[] = {1, 0, 1, 1, 0, 0, 1};
int i210[] = {1, 0, 1, 1, 0, 1, 0};
int i211[] = {1, 0, 1, 1, 0, 1, 1};
int i212[] = {1, 0, 1, 1, 1, 0, 0};
int i213[] = {1, 0, 1, 1, 1, 0, 1};
int i214[] = {1, 0, 1, 1, 1, 1, 0};
int i215[] = {1, 0, 1, 1, 1, 1, 1};
int i216[] = {1, 1, 0, 0, 0, 0, 0};
int i217[] = {1, 1, 0, 0, 0, 0, 1};
int i218[] = {1, 1, 0, 0, 0, 1, 0};
int i219[] = {1, 1, 0, 0, 0, 1, 1};
int i220[] = {1, 1, 0, 0, 1, 0, 0};
int i221[] = {1, 1, 0, 0, 1, 0, 1};
int i222[] = {1, 1, 0, 0, 1, 1, 0};
int i223[] = {1, 1, 0, 0, 1, 1, 1};
int i224[] = {1, 1, 0, 1, 0, 0, 0};
int i225[] = {1, 1, 0, 1, 0, 0, 1};
int i226[] = {1, 1, 0, 1, 0, 1, 0};
int i227[] = {1, 1, 0, 1, 0, 1, 1};
int i228[] = {1, 1, 0, 1, 1, 0, 0};
int i229[] = {1, 1, 0, 1, 1, 0, 1};
int i230[] = {1, 1, 0, 1, 1, 1, 0};
int i231[] = {1, 1, 0, 1, 1, 1, 1};
int i232[] = {1, 1, 1, 0, 0, 0, 0};
int i233[] = {1, 1, 1, 0, 0, 0, 1};
int i234[] = {1, 1, 1, 0, 0, 1, 0};
int i235[] = {1, 1, 1, 0, 0, 1, 1};
int i236[] = {1, 1, 1, 0, 1, 0, 0};
int i237[] = {1, 1, 1, 0, 1, 0, 1};
int i238[] = {1, 1, 1, 0, 1, 1, 0};
int i239[] = {1, 1, 1, 0, 1, 1, 1};
int i240[] = {1, 1, 1, 1, 0, 0, 0};
int i241[] = {1, 1, 1, 1, 0, 0, 1};
int i242[] = {1, 1, 1, 1, 0, 1, 0};
int i243[] = {1, 1, 1, 1, 0, 1, 1};
int i244[] = {1, 1, 1, 1, 1, 0, 0};
int i245[] = {1, 1, 1, 1, 1, 0, 1};
int i246[] = {1, 1, 1, 1, 1, 1, 0};
is_heap(i120, i120+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i120, i120+7, std::greater<int>()) == i120+7)); });
is_heap(i121, i121+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i121, i121+7, std::greater<int>()) == i121+7)); });
is_heap(i122, i122+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i122, i122+7, std::greater<int>()) == i122+7)); });
is_heap(i123, i123+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i123, i123+7, std::greater<int>()) == i123+7)); });
is_heap(i124, i124+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i124, i124+7, std::greater<int>()) == i124+7)); });
is_heap(i125, i125+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i125, i125+7, std::greater<int>()) == i125+7)); });
is_heap(i126, i126+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i126, i126+7, std::greater<int>()) == i126+7)); });
is_heap(i127, i127+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i127, i127+7, std::greater<int>()) == i127+7)); });
is_heap(i128, i128+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i128, i128+7, std::greater<int>()) == i128+7)); });
is_heap(i129, i129+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i129, i129+7, std::greater<int>()) == i129+7)); });
is_heap(i130, i130+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i130, i130+7, std::greater<int>()) == i130+7)); });
is_heap(i131, i131+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i131, i131+7, std::greater<int>()) == i131+7)); });
is_heap(i132, i132+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i132, i132+7, std::greater<int>()) == i132+7)); });
is_heap(i133, i133+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i133, i133+7, std::greater<int>()) == i133+7)); });
is_heap(i134, i134+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i134, i134+7, std::greater<int>()) == i134+7)); });
is_heap(i135, i135+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i135, i135+7, std::greater<int>()) == i135+7)); });
is_heap(i136, i136+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i136, i136+7, std::greater<int>()) == i136+7)); });
is_heap(i137, i137+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i137, i137+7, std::greater<int>()) == i137+7)); });
is_heap(i138, i138+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i138, i138+7, std::greater<int>()) == i138+7)); });
is_heap(i139, i139+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i139, i139+7, std::greater<int>()) == i139+7)); });
is_heap(i140, i140+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i140, i140+7, std::greater<int>()) == i140+7)); });
is_heap(i141, i141+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i141, i141+7, std::greater<int>()) == i141+7)); });
is_heap(i142, i142+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i142, i142+7, std::greater<int>()) == i142+7)); });
is_heap(i143, i143+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i143, i143+7, std::greater<int>()) == i143+7)); });
is_heap(i144, i144+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i144, i144+7, std::greater<int>()) == i144+7)); });
is_heap(i145, i145+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i145, i145+7, std::greater<int>()) == i145+7)); });
is_heap(i146, i146+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i146, i146+7, std::greater<int>()) == i146+7)); });
is_heap(i147, i147+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i147, i147+7, std::greater<int>()) == i147+7)); });
is_heap(i148, i148+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i148, i148+7, std::greater<int>()) == i148+7)); });
is_heap(i149, i149+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i149, i149+7, std::greater<int>()) == i149+7)); });
is_heap(i150, i150+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i150, i150+7, std::greater<int>()) == i150+7)); });
is_heap(i151, i151+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i151, i151+7, std::greater<int>()) == i151+7)); });
is_heap(i152, i152+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i152, i152+7, std::greater<int>()) == i152+7)); });
is_heap(i153, i153+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i153, i153+7, std::greater<int>()) == i153+7)); });
is_heap(i154, i154+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i154, i154+7, std::greater<int>()) == i154+7)); });
is_heap(i155, i155+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i155, i155+7, std::greater<int>()) == i155+7)); });
is_heap(i156, i156+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i156, i156+7, std::greater<int>()) == i156+7)); });
is_heap(i157, i157+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i157, i157+7, std::greater<int>()) == i157+7)); });
is_heap(i158, i158+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i158, i158+7, std::greater<int>()) == i158+7)); });
is_heap(i159, i159+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i159, i159+7, std::greater<int>()) == i159+7)); });
is_heap(i160, i160+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i160, i160+7, std::greater<int>()) == i160+7)); });
is_heap(i161, i161+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i161, i161+7, std::greater<int>()) == i161+7)); });
is_heap(i162, i162+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i162, i162+7, std::greater<int>()) == i162+7)); });
is_heap(i163, i163+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i163, i163+7, std::greater<int>()) == i163+7)); });
is_heap(i164, i164+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i164, i164+7, std::greater<int>()) == i164+7)); });
is_heap(i165, i165+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i165, i165+7, std::greater<int>()) == i165+7)); });
is_heap(i166, i166+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i166, i166+7, std::greater<int>()) == i166+7)); });
is_heap(i167, i167+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i167, i167+7, std::greater<int>()) == i167+7)); });
is_heap(i168, i168+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i168, i168+7, std::greater<int>()) == i168+7)); });
is_heap(i169, i169+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i169, i169+7, std::greater<int>()) == i169+7)); });
is_heap(i170, i170+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i170, i170+7, std::greater<int>()) == i170+7)); });
is_heap(i171, i171+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i171, i171+7, std::greater<int>()) == i171+7)); });
is_heap(i172, i172+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i172, i172+7, std::greater<int>()) == i172+7)); });
is_heap(i173, i173+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i173, i173+7, std::greater<int>()) == i173+7)); });
is_heap(i174, i174+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i174, i174+7, std::greater<int>()) == i174+7)); });
is_heap(i175, i175+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i175, i175+7, std::greater<int>()) == i175+7)); });
is_heap(i176, i176+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i176, i176+7, std::greater<int>()) == i176+7)); });
is_heap(i177, i177+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i177, i177+7, std::greater<int>()) == i177+7)); });
is_heap(i178, i178+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i178, i178+7, std::greater<int>()) == i178+7)); });
is_heap(i179, i179+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i179, i179+7, std::greater<int>()) == i179+7)); });
is_heap(i180, i180+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i180, i180+7, std::greater<int>()) == i180+7)); });
is_heap(i181, i181+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i181, i181+7, std::greater<int>()) == i181+7)); });
is_heap(i182, i182+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i182, i182+7, std::greater<int>()) == i182+7)); });
is_heap(i183, i183+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i183, i183+7, std::greater<int>()) == i183+7)); });
is_heap(i184, i184+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i184, i184+7, std::greater<int>()) == i184+7)); });
is_heap(i185, i185+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i185, i185+7, std::greater<int>()) == i185+7)); });
is_heap(i186, i186+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i186, i186+7, std::greater<int>()) == i186+7)); });
is_heap(i187, i187+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i187, i187+7, std::greater<int>()) == i187+7)); });
is_heap(i188, i188+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i188, i188+7, std::greater<int>()) == i188+7)); });
is_heap(i189, i189+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i189, i189+7, std::greater<int>()) == i189+7)); });
is_heap(i190, i190+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i190, i190+7, std::greater<int>()) == i190+7)); });
is_heap(i191, i191+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i191, i191+7, std::greater<int>()) == i191+7)); });
is_heap(i192, i192+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i192, i192+7, std::greater<int>()) == i192+7)); });
is_heap(i193, i193+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i193, i193+7, std::greater<int>()) == i193+7)); });
is_heap(i194, i194+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i194, i194+7, std::greater<int>()) == i194+7)); });
is_heap(i195, i195+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i195, i195+7, std::greater<int>()) == i195+7)); });
is_heap(i196, i196+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i196, i196+7, std::greater<int>()) == i196+7)); });
is_heap(i197, i197+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i197, i197+7, std::greater<int>()) == i197+7)); });
is_heap(i198, i198+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i198, i198+7, std::greater<int>()) == i198+7)); });
is_heap(i199, i199+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i199, i199+7, std::greater<int>()) == i199+7)); });
is_heap(i200, i200+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i200, i200+7, std::greater<int>()) == i200+7)); });
is_heap(i201, i201+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i201, i201+7, std::greater<int>()) == i201+7)); });
is_heap(i202, i202+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i202, i202+7, std::greater<int>()) == i202+7)); });
is_heap(i203, i203+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i203, i203+7, std::greater<int>()) == i203+7)); });
is_heap(i204, i204+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i204, i204+7, std::greater<int>()) == i204+7)); });
is_heap(i205, i205+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i205, i205+7, std::greater<int>()) == i205+7)); });
is_heap(i206, i206+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i206, i206+7, std::greater<int>()) == i206+7)); });
is_heap(i207, i207+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i207, i207+7, std::greater<int>()) == i207+7)); });
is_heap(i208, i208+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i208, i208+7, std::greater<int>()) == i208+7)); });
is_heap(i209, i209+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i209, i209+7, std::greater<int>()) == i209+7)); });
is_heap(i210, i210+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i210, i210+7, std::greater<int>()) == i210+7)); });
is_heap(i211, i211+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i211, i211+7, std::greater<int>()) == i211+7)); });
is_heap(i212, i212+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i212, i212+7, std::greater<int>()) == i212+7)); });
is_heap(i213, i213+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i213, i213+7, std::greater<int>()) == i213+7)); });
is_heap(i214, i214+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i214, i214+7, std::greater<int>()) == i214+7)); });
is_heap(i215, i215+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i215, i215+7, std::greater<int>()) == i215+7)); });
is_heap(i216, i216+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i216, i216+7, std::greater<int>()) == i216+7)); });
is_heap(i217, i217+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i217, i217+7, std::greater<int>()) == i217+7)); });
is_heap(i218, i218+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i218, i218+7, std::greater<int>()) == i218+7)); });
is_heap(i219, i219+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i219, i219+7, std::greater<int>()) == i219+7)); });
is_heap(i220, i220+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i220, i220+7, std::greater<int>()) == i220+7)); });
is_heap(i221, i221+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i221, i221+7, std::greater<int>()) == i221+7)); });
is_heap(i222, i222+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i222, i222+7, std::greater<int>()) == i222+7)); });
is_heap(i223, i223+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i223, i223+7, std::greater<int>()) == i223+7)); });
is_heap(i224, i224+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i224, i224+7, std::greater<int>()) == i224+7)); });
is_heap(i225, i225+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i225, i225+7, std::greater<int>()) == i225+7)); });
is_heap(i226, i226+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i226, i226+7, std::greater<int>()) == i226+7)); });
is_heap(i227, i227+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i227, i227+7, std::greater<int>()) == i227+7)); });
is_heap(i228, i228+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i228, i228+7, std::greater<int>()) == i228+7)); });
is_heap(i229, i229+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i229, i229+7, std::greater<int>()) == i229+7)); });
is_heap(i230, i230+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i230, i230+7, std::greater<int>()) == i230+7)); });
is_heap(i231, i231+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i231, i231+7, std::greater<int>()) == i231+7)); });
is_heap(i232, i232+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i232, i232+7, std::greater<int>()) == i232+7)); });
is_heap(i233, i233+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i233, i233+7, std::greater<int>()) == i233+7)); });
is_heap(i234, i234+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i234, i234+7, std::greater<int>()) == i234+7)); });
is_heap(i235, i235+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i235, i235+7, std::greater<int>()) == i235+7)); });
is_heap(i236, i236+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i236, i236+7, std::greater<int>()) == i236+7)); });
is_heap(i237, i237+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i237, i237+7, std::greater<int>()) == i237+7)); });
is_heap(i238, i238+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i238, i238+7, std::greater<int>()) == i238+7)); });
is_heap(i239, i239+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i239, i239+7, std::greater<int>()) == i239+7)); });
is_heap(i240, i240+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i240, i240+7, std::greater<int>()) == i240+7)); });
is_heap(i241, i241+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i241, i241+7, std::greater<int>()) == i241+7)); });
is_heap(i242, i242+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i242, i242+7, std::greater<int>()) == i242+7)); });
is_heap(i243, i243+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i243, i243+7, std::greater<int>()) == i243+7)); });
is_heap(i244, i244+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i244, i244+7, std::greater<int>()) == i244+7)); });
is_heap(i245, i245+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i245, i245+7, std::greater<int>()) == i245+7)); });
is_heap(i246, i246+7, std::greater<int>()).check([&](bool r){ CHECK(r == (std::is_heap_until(i246, i246+7, std::greater<int>()) == i246+7)); });
#endif
}
struct S
{
int i;
};
int main()
{
test();
test_comp();
// Test projections:
S i183[] = {S{0}, S{1}, S{1}, S{1}, S{1}, S{1}, S{1}};
CHECK(ranges::is_heap(i183, i183+7, std::greater<int>(), &S::i));
{
using IL = std::initializer_list<int>;
STATIC_CHECK(ranges::is_heap(IL{0, 1, 1, 1, 1, 1, 1}, ranges::greater{}));
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/is_heap2.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#define IS_HEAP_2
#include "./is_heap.hpp"
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/mismatch.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <memory>
#include <algorithm>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/mismatch.hpp>
#include "../array.hpp"
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
RANGES_DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS
template<typename Iter, typename Sent = Iter>
void test_iter()
{
int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
constexpr auto sa = ranges::size(ia);
int ib[] = {0, 1, 2, 3, 0, 1, 2, 3};
using Res = ranges::mismatch_result<Iter, Iter>;
CHECK(ranges::mismatch(Iter(ia), Sent(ia + sa), Iter(ib)) ==
Res{Iter(ia+3),Iter(ib+3)});
CHECK(ranges::mismatch(Iter(ia),Sent(ia + sa),Iter(ib),Sent(ib + sa)) ==
Res{Iter(ia+3),Iter(ib+3)});
CHECK(ranges::mismatch(Iter(ia),Sent(ia + sa),Iter(ib),Sent(ib + 2)) ==
Res{Iter(ia+2),Iter(ib+2)});
CHECK(ranges::mismatch(Iter(ia),Sent(ia + sa),Iter(ib),std::equal_to<int>()) ==
Res{Iter(ia+3),Iter(ib+3)});
CHECK(ranges::mismatch(Iter(ia),Sent(ia + sa),Iter(ib),Sent(ib + sa),std::equal_to<int>()) ==
Res{Iter(ia+3),Iter(ib+3)});
CHECK(ranges::mismatch(Iter(ia), Sent(ia + sa), Iter(ib), Sent(ib + 2), std::equal_to<int>()) ==
Res{Iter(ia+2),Iter(ib+2)});
}
template<typename Iter, typename Sent = Iter>
void test_range()
{
int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
constexpr auto sa = ranges::size(ia);
int ib[] = {0, 1, 2, 3, 0, 1, 2, 3};
using Res = ranges::mismatch_result<Iter, Iter>;
auto rng1 = ::MakeTestRange(Iter(ia), Sent(ia + sa));
CHECK(ranges::mismatch(rng1, Iter(ib)) ==
Res{Iter(ia+3),Iter(ib+3)});
auto r1 = ranges::mismatch(std::move(rng1), Iter(ib));
CHECK(::is_dangling(r1.in1));
CHECK(r1.in2 == Iter(ib+3));
auto rng2 = ::MakeTestRange(Iter(ia),Sent(ia + sa));
auto rng3 = ::MakeTestRange(Iter(ib),Sent(ib + sa));
CHECK(ranges::mismatch(rng2,rng3) ==
Res{Iter(ia+3),Iter(ib+3)});
auto r2 = ranges::mismatch(std::move(rng2), std::move(rng3));
CHECK(::is_dangling(r2.in1));
CHECK(::is_dangling(r2.in2));
auto r3 = ranges::mismatch(rng2, std::move(rng3));
CHECK(r3.in1 == Iter(ia+3));
CHECK(::is_dangling(r3.in2));
auto r4 = ranges::mismatch(std::move(rng2), rng3);
CHECK(::is_dangling(r4.in1));
CHECK(r4.in2 == Iter(ib+3));
auto rng4 = ::MakeTestRange(Iter(ia),Sent(ia + sa));
auto rng5 = ::MakeTestRange(Iter(ib),Sent(ib + 2));
CHECK(ranges::mismatch(rng4,rng5) ==
Res{Iter(ia+2),Iter(ib+2)});
auto rng6 = ::MakeTestRange(Iter(ia),Sent(ia + sa));
CHECK(ranges::mismatch(rng6,Iter(ib),std::equal_to<int>()) ==
Res{Iter(ia+3),Iter(ib+3)});
auto rng7 = ::MakeTestRange(Iter(ia),Sent(ia + sa));
auto rng8 = ::MakeTestRange(Iter(ib),Sent(ib + sa));
CHECK(ranges::mismatch(rng7,rng8,std::equal_to<int>()) ==
Res{Iter(ia+3),Iter(ib+3)});
auto rng9 = ::MakeTestRange(Iter(ia), Sent(ia + sa));
auto rng10 = ::MakeTestRange(Iter(ib), Sent(ib + 2));
CHECK(ranges::mismatch(rng9,rng10,std::equal_to<int>()) ==
Res{Iter(ia+2),Iter(ib+2)});
}
struct S
{
int i;
};
int main()
{
test_iter<InputIterator<const int*>>();
test_iter<ForwardIterator<const int*>>();
test_iter<BidirectionalIterator<const int*>>();
test_iter<RandomAccessIterator<const int*>>();
test_iter<const int*>();
test_iter<InputIterator<const int*>, Sentinel<const int*>>();
test_iter<ForwardIterator<const int*>, Sentinel<const int*>>();
test_iter<BidirectionalIterator<const int*>, Sentinel<const int*>>();
test_iter<RandomAccessIterator<const int*>, Sentinel<const int*>>();
test_range<InputIterator<const int*>>();
test_range<ForwardIterator<const int*>>();
test_range<BidirectionalIterator<const int*>>();
test_range<RandomAccessIterator<const int*>>();
test_range<const int*>();
test_range<InputIterator<const int*>, Sentinel<const int*>>();
test_range<ForwardIterator<const int*>, Sentinel<const int*>>();
test_range<BidirectionalIterator<const int*>, Sentinel<const int*>>();
test_range<RandomAccessIterator<const int*>, Sentinel<const int*>>();
// Works with projections?
S s1[] = {S{1},S{2},S{3},S{4},S{-4},S{5},S{6},S{40},S{7},S{8},S{9}};
int const i1[] = {1,2,3,4,5,6,7,8,9};
ranges::mismatch_result<S const *, int const *> ps1
= ranges::mismatch(s1, i1, std::equal_to<int>(), &S::i);
CHECK(ps1.in1->i == -4);
CHECK(*ps1.in2 == 5);
S s2[] = {S{1},S{2},S{3},S{4},S{5},S{6},S{40},S{7},S{8},S{9}};
ranges::mismatch_result<S const *, S const *> ps2
= ranges::mismatch(s1, s2, std::equal_to<int>(), &S::i, &S::i);
CHECK(ps2.in1->i == -4);
CHECK(ps2.in2->i == 5);
constexpr auto r1 = test::array<int, 11>{{1, 2, 3, 4, -4, 5, 6, 40, 7, 8, 9}};
constexpr auto r11 = test::array<int, 9>{{1, 2, 3, 4, 5, 6, 7, 8, 9}};
constexpr auto r2 = test::array<int, 10>{{1, 2, 3, 4, 5, 6, 40, 7, 8, 9}};
STATIC_CHECK(*ranges::mismatch(r1, r11, std::equal_to<int>{}).in1 == -4);
STATIC_CHECK(*ranges::mismatch(r1, r11, std::equal_to<int>{}).in2 == 5);
STATIC_CHECK(*ranges::mismatch(r1, r2, std::equal_to<int>{}).in1 == -4);
STATIC_CHECK(*ranges::mismatch(r1, r2, std::equal_to<int>{}).in2 == 5);
return test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/move_backward.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <memory>
#include <algorithm>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/move_backward.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
template<typename InIter, typename OutIter>
void
test()
{
{
const int N = 1000;
int ia[N];
for(int i = 0; i < N; ++i)
ia[i] = i;
int ib[N] = {0};
ranges::move_backward_result<InIter, OutIter> r =
ranges::move_backward(InIter(ia), InIter(ia+N), OutIter(ib+N));
CHECK(base(r.in) == ia+N);
CHECK(base(r.out) == ib);
for(int i = 0; i < N; ++i)
CHECK(ia[i] == ib[i]);
}
{
const int N = 1000;
int ia[N];
for(int i = 0; i < N; ++i)
ia[i] = i;
int ib[N] = {0};
ranges::move_backward_result<InIter, OutIter> r =
ranges::move_backward(ranges::make_subrange(InIter(ia), InIter(ia+N)), OutIter(ib+N));
CHECK(base(r.in) == ia+N);
CHECK(base(r.out) == ib);
for(int i = 0; i < N; ++i)
CHECK(ia[i] == ib[i]);
}
}
template<typename InIter, typename OutIter, typename Sent = InIter>
constexpr bool test_constexpr()
{
{
constexpr int N = 1000;
int ia[N]{1};
for(int i = 0; i < N; ++i)
ia[i] = i;
int ib[N] = {0};
const auto r = ranges::move_backward(InIter(ia), Sent(ia + N), OutIter(ib + N));
if(base(r.in) != ia + N)
{
return false;
}
if(base(r.out) != ib)
{
return false;
}
for(int i = 0; i < N; ++i)
if(ia[i] != ib[i])
{
return false;
}
}
{
constexpr int N = 1000;
int ia[N]{1};
for(int i = 0; i < N; ++i)
ia[i] = i;
int ib[N] = {0};
const auto r = ranges::move_backward(
as_lvalue(ranges::make_subrange(InIter(ia), Sent(ia + N))), OutIter(ib + N));
if(base(r.in) != ia + N)
{
return false;
}
if(base(r.out) != ib)
{
return false;
}
for(int i = 0; i < N; ++i)
if(ia[i] != ib[i])
{
return false;
}
}
return true;
}
struct S
{
std::unique_ptr<int> p;
};
template<typename InIter, typename OutIter>
void
test1()
{
{
const int N = 100;
std::unique_ptr<int> ia[N];
for(int i = 0; i < N; ++i)
ia[i].reset(new int(i));
std::unique_ptr<int> ib[N];
ranges::move_backward_result<InIter, OutIter> r =
ranges::move_backward(InIter(ia), InIter(ia+N), OutIter(ib+N));
CHECK(base(r.in) == ia+N);
CHECK(base(r.out) == ib);
for(int i = 0; i < N; ++i)
{
CHECK(ia[i].get() == nullptr);
CHECK(*ib[i] == i);
}
}
{
const int N = 100;
std::unique_ptr<int> ia[N];
for(int i = 0; i < N; ++i)
ia[i].reset(new int(i));
std::unique_ptr<int> ib[N];
ranges::move_backward_result<InIter, OutIter> r =
ranges::move_backward(ranges::make_subrange(InIter(ia), InIter(ia+N)), OutIter(ib+N));
CHECK(base(r.in) == ia+N);
CHECK(base(r.out) == ib);
for(int i = 0; i < N; ++i)
{
CHECK(ia[i].get() == nullptr);
CHECK(*ib[i] == i);
}
ranges::move_backward(ib, ib+N, ia+N);
auto r2 = ranges::move_backward(ranges::make_subrange(InIter(ia), InIter(ia+N)), OutIter(ib+N));
CHECK(base(r2.in) == ia+N);
CHECK(base(r2.out) == ib);
for(int i = 0; i < N; ++i)
{
CHECK(ia[i].get() == nullptr);
CHECK(*ib[i] == i);
}
}
}
int main()
{
test<BidirectionalIterator<const int*>, BidirectionalIterator<int*> >();
test<BidirectionalIterator<const int*>, RandomAccessIterator<int*> >();
test<BidirectionalIterator<const int*>, int*>();
test<RandomAccessIterator<const int*>, BidirectionalIterator<int*> >();
test<RandomAccessIterator<const int*>, RandomAccessIterator<int*> >();
test<RandomAccessIterator<const int*>, int*>();
test<const int*, BidirectionalIterator<int*> >();
test<const int*, RandomAccessIterator<int*> >();
test<const int*, int*>();
test1<BidirectionalIterator<std::unique_ptr<int>*>, BidirectionalIterator<std::unique_ptr<int>*> >();
test1<BidirectionalIterator<std::unique_ptr<int>*>, RandomAccessIterator<std::unique_ptr<int>*> >();
test1<BidirectionalIterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
test1<RandomAccessIterator<std::unique_ptr<int>*>, BidirectionalIterator<std::unique_ptr<int>*> >();
test1<RandomAccessIterator<std::unique_ptr<int>*>, RandomAccessIterator<std::unique_ptr<int>*> >();
test1<RandomAccessIterator<std::unique_ptr<int>*>, std::unique_ptr<int>*>();
test1<std::unique_ptr<int>*, BidirectionalIterator<std::unique_ptr<int>*> >();
test1<std::unique_ptr<int>*, RandomAccessIterator<std::unique_ptr<int>*> >();
test1<std::unique_ptr<int>*, std::unique_ptr<int>*>();
STATIC_CHECK(test_constexpr<BidirectionalIterator<const int *>,
BidirectionalIterator<int *>>());
STATIC_CHECK(test_constexpr<BidirectionalIterator<const int *>,
RandomAccessIterator<int *>>());
STATIC_CHECK(test_constexpr<BidirectionalIterator<const int *>, int *>());
STATIC_CHECK(test_constexpr<RandomAccessIterator<const int *>,
BidirectionalIterator<int *>>());
STATIC_CHECK(
test_constexpr<RandomAccessIterator<const int *>, RandomAccessIterator<int *>>());
STATIC_CHECK(test_constexpr<RandomAccessIterator<const int *>, int *>());
STATIC_CHECK(test_constexpr<const int *, BidirectionalIterator<int *>>());
STATIC_CHECK(test_constexpr<const int *, RandomAccessIterator<int *>>());
STATIC_CHECK(test_constexpr<const int *, int *>());
return test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/set_intersection6.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#define SET_INTERSECTION_6
#include "./set_intersection.hpp"
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/set_symmetric_difference5.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#define SET_SYMMETRIC_DIFFERENCE_5
#include "./set_symmetric_difference.hpp"
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/transform.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <functional>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/transform.hpp>
#include <range/v3/view/unbounded.hpp>
#include "../simple_test.hpp"
#include "../test_iterators.hpp"
using namespace std::placeholders;
RANGES_DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS
template<class InIter, class OutIter>
void
test1()
{
{
int ia[] = {0, 1, 2, 3, 4};
constexpr auto sa = ranges::size(ia);
int ib[sa] = {0};
ranges::unary_transform_result<InIter, OutIter> r =
ranges::transform(InIter(ia), Sentinel<int const *>(ia+sa), OutIter(ib),
std::bind(std::plus<int>(), _1, 1));
CHECK(base(r.in) == ia + sa);
CHECK(base(r.out) == ib + sa);
CHECK(ib[0] == 1);
CHECK(ib[1] == 2);
CHECK(ib[2] == 3);
CHECK(ib[3] == 4);
CHECK(ib[4] == 5);
}
{
int ia[] = {0, 1, 2, 3, 4};
constexpr auto sa = ranges::size(ia);
int ib[sa] = {0};
auto rng = ranges::make_subrange(InIter(ia), Sentinel<int const *>(ia + sa));
ranges::unary_transform_result<InIter, OutIter> r =
ranges::transform(rng, OutIter(ib),
std::bind(std::plus<int>(), _1, 1));
CHECK(base(r.in) == ia + sa);
CHECK(base(r.out) == ib + sa);
CHECK(ib[0] == 1);
CHECK(ib[1] == 2);
CHECK(ib[2] == 3);
CHECK(ib[3] == 4);
CHECK(ib[4] == 5);
}
{
int ia[] = {0, 1, 2, 3, 4};
constexpr auto sa = ranges::size(ia);
int ib[sa] = {0};
auto rng = ranges::make_subrange(InIter(ia), Sentinel<int const *>(ia + sa));
auto r =
ranges::transform(std::move(rng), OutIter(ib),
std::bind(std::plus<int>(), _1, 1));
CHECK(base(r.in) == ia + sa);
CHECK(base(r.out) == ib + sa);
CHECK(ib[0] == 1);
CHECK(ib[1] == 2);
CHECK(ib[2] == 3);
CHECK(ib[3] == 4);
CHECK(ib[4] == 5);
}
}
template<class InIter1, class InIter2, class OutIter>
void
test2()
{
{
int ia[] = {0, 1, 2, 3, 4};
constexpr auto sa = ranges::size(ia);
int ib[sa] = {1, 2, 3, 4, 5};
ranges::binary_transform_result<InIter1, InIter2, OutIter> r =
ranges::transform(InIter1(ib), Sentinel<int const *>(ib + sa), InIter2(ia),
OutIter(ib), std::minus<int>());
CHECK(base(r.in1) == ib + sa);
CHECK(base(r.in2) == ia + sa);
CHECK(base(r.out) == ib + sa);
CHECK(ib[0] == 1);
CHECK(ib[1] == 1);
CHECK(ib[2] == 1);
CHECK(ib[3] == 1);
CHECK(ib[4] == 1);
}
{
int ia[] = {0, 1, 2, 3, 4};
constexpr auto sa = ranges::size(ia);
int ib[sa] = {1, 2, 3, 4, 5};
ranges::binary_transform_result<InIter1, InIter2, OutIter> r =
ranges::transform(InIter1(ib), Sentinel<int const *>(ib + sa),
InIter2(ia), Sentinel<int const *>(ia + sa),
OutIter(ib), std::minus<int>());
CHECK(base(r.in1) == ib + sa);
CHECK(base(r.in2) == ia + sa);
CHECK(base(r.out) == ib + sa);
CHECK(ib[0] == 1);
CHECK(ib[1] == 1);
CHECK(ib[2] == 1);
CHECK(ib[3] == 1);
CHECK(ib[4] == 1);
}
{
int ia[] = {0, 1, 2, 3, 4};
constexpr auto sa = ranges::size(ia);
int ib[sa] = {1, 2, 3, 4, 5};
auto rng0 = ranges::make_subrange(InIter1(ib), Sentinel<int const *>(ib + sa));
ranges::binary_transform_result<InIter1, InIter2, OutIter> r =
ranges::transform(rng0, InIter2(ia),
OutIter(ib), std::minus<int>());
CHECK(base(r.in1) == ib + sa);
CHECK(base(r.in2) == ia + sa);
CHECK(base(r.out) == ib + sa);
CHECK(ib[0] == 1);
CHECK(ib[1] == 1);
CHECK(ib[2] == 1);
CHECK(ib[3] == 1);
CHECK(ib[4] == 1);
}
{
int ia[] = {0, 1, 2, 3, 4};
constexpr auto sa = ranges::size(ia);
int ib[sa] = {1, 2, 3, 4, 5};
auto rng0 = ranges::make_subrange(InIter1(ib), Sentinel<int const *>(ib + sa));
auto r =
ranges::transform(std::move(rng0), InIter2(ia),
OutIter(ib), std::minus<int>());
CHECK(base(r.in1) == ib + sa);
CHECK(base(r.in2) == ia + sa);
CHECK(base(r.out) == ib + sa);
CHECK(ib[0] == 1);
CHECK(ib[1] == 1);
CHECK(ib[2] == 1);
CHECK(ib[3] == 1);
CHECK(ib[4] == 1);
}
{
int ia[] = {0, 1, 2, 3, 4};
constexpr auto sa = ranges::size(ia);
int ib[sa] = {1, 2, 3, 4, 5};
auto rng0 = ranges::make_subrange(InIter1(ib), Sentinel<int const *>(ib + sa));
auto rng1 = ranges::make_subrange(InIter2(ia), Sentinel<int const *>(ia + sa));
ranges::binary_transform_result<InIter1, InIter2, OutIter> r =
ranges::transform(rng0, rng1, OutIter(ib), std::minus<int>());
CHECK(base(r.in1) == ib + sa);
CHECK(base(r.in2) == ia + sa);
CHECK(base(r.out) == ib + sa);
CHECK(ib[0] == 1);
CHECK(ib[1] == 1);
CHECK(ib[2] == 1);
CHECK(ib[3] == 1);
CHECK(ib[4] == 1);
}
{
int ia[] = {0, 1, 2, 3, 4};
constexpr auto sa = ranges::size(ia);
int ib[sa] = {1, 2, 3, 4, 5};
auto rng0 = ranges::make_subrange(InIter1(ib), Sentinel<int const *>(ib + sa));
auto rng1 = ranges::make_subrange(InIter2(ia), Sentinel<int const *>(ia + sa));
auto r =
ranges::transform(std::move(rng0), std::move(rng1), OutIter(ib), std::minus<int>());
CHECK(base(r.in1) == ib + sa);
CHECK(base(r.in2) == ia + sa);
CHECK(base(r.out) == ib + sa);
CHECK(ib[0] == 1);
CHECK(ib[1] == 1);
CHECK(ib[2] == 1);
CHECK(ib[3] == 1);
CHECK(ib[4] == 1);
}
}
struct S
{
int i;
};
constexpr int plus_one(int i)
{
return i + 1;
}
constexpr bool test_constexpr()
{
using namespace ranges;
int ia[] = {0, 1, 2, 3, 4};
constexpr auto sa = ranges::size(ia);
int ib[sa] = {0};
auto r = transform(ia, ib, plus_one);
STATIC_CHECK_RETURN(r.in == ia + sa);
STATIC_CHECK_RETURN(r.out == ib + sa);
STATIC_CHECK_RETURN(ib[0] == 1);
STATIC_CHECK_RETURN(ib[1] == 2);
STATIC_CHECK_RETURN(ib[2] == 3);
STATIC_CHECK_RETURN(ib[3] == 4);
STATIC_CHECK_RETURN(ib[4] == 5);
return true;
}
int main()
{
test1<InputIterator<const int*>, OutputIterator<int*> >();
test1<InputIterator<const int*>, InputIterator<int*> >();
test1<InputIterator<const int*>, ForwardIterator<int*> >();
test1<InputIterator<const int*>, BidirectionalIterator<int*> >();
test1<InputIterator<const int*>, RandomAccessIterator<int*> >();
test1<InputIterator<const int*>, int*>();
test1<ForwardIterator<const int*>, OutputIterator<int*> >();
test1<ForwardIterator<const int*>, InputIterator<int*> >();
test1<ForwardIterator<const int*>, ForwardIterator<int*> >();
test1<ForwardIterator<const int*>, BidirectionalIterator<int*> >();
test1<ForwardIterator<const int*>, RandomAccessIterator<int*> >();
test1<ForwardIterator<const int*>, int*>();
test1<BidirectionalIterator<const int*>, OutputIterator<int*> >();
test1<BidirectionalIterator<const int*>, InputIterator<int*> >();
test1<BidirectionalIterator<const int*>, ForwardIterator<int*> >();
test1<BidirectionalIterator<const int*>, BidirectionalIterator<int*> >();
test1<BidirectionalIterator<const int*>, RandomAccessIterator<int*> >();
test1<BidirectionalIterator<const int*>, int*>();
test1<RandomAccessIterator<const int*>, OutputIterator<int*> >();
test1<RandomAccessIterator<const int*>, InputIterator<int*> >();
test1<RandomAccessIterator<const int*>, ForwardIterator<int*> >();
test1<RandomAccessIterator<const int*>, BidirectionalIterator<int*> >();
test1<RandomAccessIterator<const int*>, RandomAccessIterator<int*> >();
test1<RandomAccessIterator<const int*>, int*>();
test1<const int*, OutputIterator<int*> >();
test1<const int*, InputIterator<int*> >();
test1<const int*, ForwardIterator<int*> >();
test1<const int*, BidirectionalIterator<int*> >();
test1<const int*, RandomAccessIterator<int*> >();
test1<const int*, int*>();
test2<InputIterator<const int*>, InputIterator<const int*>, OutputIterator<int*> >();
test2<InputIterator<const int*>, InputIterator<const int*>, InputIterator<int*> >();
test2<InputIterator<const int*>, InputIterator<const int*>, ForwardIterator<int*> >();
test2<InputIterator<const int*>, InputIterator<const int*>, BidirectionalIterator<int*> >();
test2<InputIterator<const int*>, InputIterator<const int*>, RandomAccessIterator<int*> >();
test2<InputIterator<const int*>, InputIterator<const int*>, int*>();
test2<InputIterator<const int*>, ForwardIterator<const int*>, OutputIterator<int*> >();
test2<InputIterator<const int*>, ForwardIterator<const int*>, InputIterator<int*> >();
test2<InputIterator<const int*>, ForwardIterator<const int*>, ForwardIterator<int*> >();
test2<InputIterator<const int*>, ForwardIterator<const int*>, BidirectionalIterator<int*> >();
test2<InputIterator<const int*>, ForwardIterator<const int*>, RandomAccessIterator<int*> >();
test2<InputIterator<const int*>, ForwardIterator<const int*>, int*>();
test2<InputIterator<const int*>, BidirectionalIterator<const int*>, OutputIterator<int*> >();
test2<InputIterator<const int*>, BidirectionalIterator<const int*>, InputIterator<int*> >();
test2<InputIterator<const int*>, BidirectionalIterator<const int*>, ForwardIterator<int*> >();
test2<InputIterator<const int*>, BidirectionalIterator<const int*>, BidirectionalIterator<int*> >();
test2<InputIterator<const int*>, BidirectionalIterator<const int*>, RandomAccessIterator<int*> >();
test2<InputIterator<const int*>, BidirectionalIterator<const int*>, int*>();
test2<InputIterator<const int*>, RandomAccessIterator<const int*>, OutputIterator<int*> >();
test2<InputIterator<const int*>, RandomAccessIterator<const int*>, InputIterator<int*> >();
test2<InputIterator<const int*>, RandomAccessIterator<const int*>, ForwardIterator<int*> >();
test2<InputIterator<const int*>, RandomAccessIterator<const int*>, BidirectionalIterator<int*> >();
test2<InputIterator<const int*>, RandomAccessIterator<const int*>, RandomAccessIterator<int*> >();
test2<InputIterator<const int*>, RandomAccessIterator<const int*>, int*>();
test2<InputIterator<const int*>, const int*, OutputIterator<int*> >();
test2<InputIterator<const int*>, const int*, InputIterator<int*> >();
test2<InputIterator<const int*>, const int*, ForwardIterator<int*> >();
test2<InputIterator<const int*>, const int*, BidirectionalIterator<int*> >();
test2<InputIterator<const int*>, const int*, RandomAccessIterator<int*> >();
test2<InputIterator<const int*>, const int*, int*>();
test2<ForwardIterator<const int*>, InputIterator<const int*>, OutputIterator<int*> >();
test2<ForwardIterator<const int*>, InputIterator<const int*>, InputIterator<int*> >();
test2<ForwardIterator<const int*>, InputIterator<const int*>, ForwardIterator<int*> >();
test2<ForwardIterator<const int*>, InputIterator<const int*>, BidirectionalIterator<int*> >();
test2<ForwardIterator<const int*>, InputIterator<const int*>, RandomAccessIterator<int*> >();
test2<ForwardIterator<const int*>, InputIterator<const int*>, int*>();
test2<ForwardIterator<const int*>, ForwardIterator<const int*>, OutputIterator<int*> >();
test2<ForwardIterator<const int*>, ForwardIterator<const int*>, InputIterator<int*> >();
test2<ForwardIterator<const int*>, ForwardIterator<const int*>, ForwardIterator<int*> >();
test2<ForwardIterator<const int*>, ForwardIterator<const int*>, BidirectionalIterator<int*> >();
test2<ForwardIterator<const int*>, ForwardIterator<const int*>, RandomAccessIterator<int*> >();
test2<ForwardIterator<const int*>, ForwardIterator<const int*>, int*>();
test2<ForwardIterator<const int*>, BidirectionalIterator<const int*>, OutputIterator<int*> >();
test2<ForwardIterator<const int*>, BidirectionalIterator<const int*>, InputIterator<int*> >();
test2<ForwardIterator<const int*>, BidirectionalIterator<const int*>, ForwardIterator<int*> >();
test2<ForwardIterator<const int*>, BidirectionalIterator<const int*>, BidirectionalIterator<int*> >();
test2<ForwardIterator<const int*>, BidirectionalIterator<const int*>, RandomAccessIterator<int*> >();
test2<ForwardIterator<const int*>, BidirectionalIterator<const int*>, int*>();
test2<ForwardIterator<const int*>, RandomAccessIterator<const int*>, OutputIterator<int*> >();
test2<ForwardIterator<const int*>, RandomAccessIterator<const int*>, InputIterator<int*> >();
test2<ForwardIterator<const int*>, RandomAccessIterator<const int*>, ForwardIterator<int*> >();
test2<ForwardIterator<const int*>, RandomAccessIterator<const int*>, BidirectionalIterator<int*> >();
test2<ForwardIterator<const int*>, RandomAccessIterator<const int*>, RandomAccessIterator<int*> >();
test2<ForwardIterator<const int*>, RandomAccessIterator<const int*>, int*>();
test2<ForwardIterator<const int*>, const int*, OutputIterator<int*> >();
test2<ForwardIterator<const int*>, const int*, InputIterator<int*> >();
test2<ForwardIterator<const int*>, const int*, ForwardIterator<int*> >();
test2<ForwardIterator<const int*>, const int*, BidirectionalIterator<int*> >();
test2<ForwardIterator<const int*>, const int*, RandomAccessIterator<int*> >();
test2<ForwardIterator<const int*>, const int*, int*>();
test2<BidirectionalIterator<const int*>, InputIterator<const int*>, OutputIterator<int*> >();
test2<BidirectionalIterator<const int*>, InputIterator<const int*>, InputIterator<int*> >();
test2<BidirectionalIterator<const int*>, InputIterator<const int*>, ForwardIterator<int*> >();
test2<BidirectionalIterator<const int*>, InputIterator<const int*>, BidirectionalIterator<int*> >();
test2<BidirectionalIterator<const int*>, InputIterator<const int*>, RandomAccessIterator<int*> >();
test2<BidirectionalIterator<const int*>, InputIterator<const int*>, int*>();
test2<BidirectionalIterator<const int*>, ForwardIterator<const int*>, OutputIterator<int*> >();
test2<BidirectionalIterator<const int*>, ForwardIterator<const int*>, InputIterator<int*> >();
test2<BidirectionalIterator<const int*>, ForwardIterator<const int*>, ForwardIterator<int*> >();
test2<BidirectionalIterator<const int*>, ForwardIterator<const int*>, BidirectionalIterator<int*> >();
test2<BidirectionalIterator<const int*>, ForwardIterator<const int*>, RandomAccessIterator<int*> >();
test2<BidirectionalIterator<const int*>, ForwardIterator<const int*>, int*>();
test2<BidirectionalIterator<const int*>, BidirectionalIterator<const int*>, OutputIterator<int*> >();
test2<BidirectionalIterator<const int*>, BidirectionalIterator<const int*>, InputIterator<int*> >();
test2<BidirectionalIterator<const int*>, BidirectionalIterator<const int*>, ForwardIterator<int*> >();
test2<BidirectionalIterator<const int*>, BidirectionalIterator<const int*>, BidirectionalIterator<int*> >();
test2<BidirectionalIterator<const int*>, BidirectionalIterator<const int*>, RandomAccessIterator<int*> >();
test2<BidirectionalIterator<const int*>, BidirectionalIterator<const int*>, int*>();
test2<BidirectionalIterator<const int*>, RandomAccessIterator<const int*>, OutputIterator<int*> >();
test2<BidirectionalIterator<const int*>, RandomAccessIterator<const int*>, InputIterator<int*> >();
test2<BidirectionalIterator<const int*>, RandomAccessIterator<const int*>, ForwardIterator<int*> >();
test2<BidirectionalIterator<const int*>, RandomAccessIterator<const int*>, BidirectionalIterator<int*> >();
test2<BidirectionalIterator<const int*>, RandomAccessIterator<const int*>, RandomAccessIterator<int*> >();
test2<BidirectionalIterator<const int*>, RandomAccessIterator<const int*>, int*>();
test2<BidirectionalIterator<const int*>, const int*, OutputIterator<int*> >();
test2<BidirectionalIterator<const int*>, const int*, InputIterator<int*> >();
test2<BidirectionalIterator<const int*>, const int*, ForwardIterator<int*> >();
test2<BidirectionalIterator<const int*>, const int*, BidirectionalIterator<int*> >();
test2<BidirectionalIterator<const int*>, const int*, RandomAccessIterator<int*> >();
test2<BidirectionalIterator<const int*>, const int*, int*>();
test2<RandomAccessIterator<const int*>, InputIterator<const int*>, OutputIterator<int*> >();
test2<RandomAccessIterator<const int*>, InputIterator<const int*>, InputIterator<int*> >();
test2<RandomAccessIterator<const int*>, InputIterator<const int*>, ForwardIterator<int*> >();
test2<RandomAccessIterator<const int*>, InputIterator<const int*>, BidirectionalIterator<int*> >();
test2<RandomAccessIterator<const int*>, InputIterator<const int*>, RandomAccessIterator<int*> >();
test2<RandomAccessIterator<const int*>, InputIterator<const int*>, int*>();
test2<RandomAccessIterator<const int*>, ForwardIterator<const int*>, OutputIterator<int*> >();
test2<RandomAccessIterator<const int*>, ForwardIterator<const int*>, InputIterator<int*> >();
test2<RandomAccessIterator<const int*>, ForwardIterator<const int*>, ForwardIterator<int*> >();
test2<RandomAccessIterator<const int*>, ForwardIterator<const int*>, BidirectionalIterator<int*> >();
test2<RandomAccessIterator<const int*>, ForwardIterator<const int*>, RandomAccessIterator<int*> >();
test2<RandomAccessIterator<const int*>, ForwardIterator<const int*>, int*>();
test2<RandomAccessIterator<const int*>, BidirectionalIterator<const int*>, OutputIterator<int*> >();
test2<RandomAccessIterator<const int*>, BidirectionalIterator<const int*>, InputIterator<int*> >();
test2<RandomAccessIterator<const int*>, BidirectionalIterator<const int*>, ForwardIterator<int*> >();
test2<RandomAccessIterator<const int*>, BidirectionalIterator<const int*>, BidirectionalIterator<int*> >();
test2<RandomAccessIterator<const int*>, BidirectionalIterator<const int*>, RandomAccessIterator<int*> >();
test2<RandomAccessIterator<const int*>, BidirectionalIterator<const int*>, int*>();
test2<RandomAccessIterator<const int*>, RandomAccessIterator<const int*>, OutputIterator<int*> >();
test2<RandomAccessIterator<const int*>, RandomAccessIterator<const int*>, InputIterator<int*> >();
test2<RandomAccessIterator<const int*>, RandomAccessIterator<const int*>, ForwardIterator<int*> >();
test2<RandomAccessIterator<const int*>, RandomAccessIterator<const int*>, BidirectionalIterator<int*> >();
test2<RandomAccessIterator<const int*>, RandomAccessIterator<const int*>, RandomAccessIterator<int*> >();
test2<RandomAccessIterator<const int*>, RandomAccessIterator<const int*>, int*>();
test2<RandomAccessIterator<const int*>, const int*, OutputIterator<int*> >();
test2<RandomAccessIterator<const int*>, const int*, InputIterator<int*> >();
test2<RandomAccessIterator<const int*>, const int*, ForwardIterator<int*> >();
test2<RandomAccessIterator<const int*>, const int*, BidirectionalIterator<int*> >();
test2<RandomAccessIterator<const int*>, const int*, RandomAccessIterator<int*> >();
test2<RandomAccessIterator<const int*>, const int*, int*>();
test2<const int*, InputIterator<const int*>, OutputIterator<int*> >();
test2<const int*, InputIterator<const int*>, InputIterator<int*> >();
test2<const int*, InputIterator<const int*>, ForwardIterator<int*> >();
test2<const int*, InputIterator<const int*>, BidirectionalIterator<int*> >();
test2<const int*, InputIterator<const int*>, RandomAccessIterator<int*> >();
test2<const int*, InputIterator<const int*>, int*>();
test2<const int*, ForwardIterator<const int*>, OutputIterator<int*> >();
test2<const int*, ForwardIterator<const int*>, InputIterator<int*> >();
test2<const int*, ForwardIterator<const int*>, ForwardIterator<int*> >();
test2<const int*, ForwardIterator<const int*>, BidirectionalIterator<int*> >();
test2<const int*, ForwardIterator<const int*>, RandomAccessIterator<int*> >();
test2<const int*, ForwardIterator<const int*>, int*>();
test2<const int*, BidirectionalIterator<const int*>, OutputIterator<int*> >();
test2<const int*, BidirectionalIterator<const int*>, InputIterator<int*> >();
test2<const int*, BidirectionalIterator<const int*>, ForwardIterator<int*> >();
test2<const int*, BidirectionalIterator<const int*>, BidirectionalIterator<int*> >();
test2<const int*, BidirectionalIterator<const int*>, RandomAccessIterator<int*> >();
test2<const int*, BidirectionalIterator<const int*>, int*>();
test2<const int*, RandomAccessIterator<const int*>, OutputIterator<int*> >();
test2<const int*, RandomAccessIterator<const int*>, InputIterator<int*> >();
test2<const int*, RandomAccessIterator<const int*>, ForwardIterator<int*> >();
test2<const int*, RandomAccessIterator<const int*>, BidirectionalIterator<int*> >();
test2<const int*, RandomAccessIterator<const int*>, RandomAccessIterator<int*> >();
test2<const int*, RandomAccessIterator<const int*>, int*>();
test2<const int*, const int*, OutputIterator<int*> >();
test2<const int*, const int*, InputIterator<int*> >();
test2<const int*, const int*, ForwardIterator<int*> >();
test2<const int*, const int*, BidirectionalIterator<int*> >();
test2<const int*, const int*, RandomAccessIterator<int*> >();
test2<const int*, const int*, int*>();
int *p = nullptr;
auto unary = [](int i){return i + 1; };
auto binary = [](int i, int j){return i + j; };
S const s[] = {S{1}, S{2}, S{3}, S{4}};
int const i[] = {1, 2, 3, 4};
static_assert(std::is_same<ranges::unary_transform_result<S const*, int*>,
decltype(ranges::transform(s, p, unary, &S::i))>::value, "");
static_assert(std::is_same<ranges::binary_transform_result<S const*, int const *, int*>,
decltype(ranges::transform(s, i, p, binary, &S::i))>::value, "");
static_assert(std::is_same<ranges::binary_transform_result<S const*, S const *, int*>,
decltype(ranges::transform(s, s, p, binary, &S::i, &S::i))>::value, "");
{
STATIC_CHECK(test_constexpr());
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/rotate_copy.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright 2005 - 2007 Adobe Systems Incorporated
// Distributed under the MIT License(see accompanying file LICENSE_1_0_0.txt
// or a copy at http://stlab.adobe.com/licenses.html)
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <utility>
#include <vector>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/rotate_copy.hpp>
#include "../simple_test.hpp"
#include "../test_iterators.hpp"
#include "../test_utils.hpp"
template<class InIter, class OutIter, typename Sent = InIter>
void test_iter()
{
int ia[] = {0, 1, 2, 3};
const unsigned sa = sizeof(ia)/sizeof(ia[0]);
int ib[sa] = {0};
ranges::rotate_copy_result<InIter, OutIter> r = ranges::rotate_copy(InIter(ia), InIter(ia), Sent(ia), OutIter(ib));
CHECK(base(r.in) == ia);
CHECK(base(r.out) == ib);
r = ranges::rotate_copy(InIter(ia), InIter(ia), Sent(ia+1), OutIter(ib));
CHECK(base(r.in) == ia+1);
CHECK(base(r.out) == ib+1);
CHECK(ib[0] == 0);
r = ranges::rotate_copy(InIter(ia), InIter(ia+1), Sent(ia+1), OutIter(ib));
CHECK(base(r.in) == ia+1);
CHECK(base(r.out) == ib+1);
CHECK(ib[0] == 0);
r = ranges::rotate_copy(InIter(ia), InIter(ia), Sent(ia+2), OutIter(ib));
CHECK(base(r.in) == ia+2);
CHECK(base(r.out) == ib+2);
CHECK(ib[0] == 0);
CHECK(ib[1] == 1);
r = ranges::rotate_copy(InIter(ia), InIter(ia+1), Sent(ia+2), OutIter(ib));
CHECK(base(r.in) == ia+2);
CHECK(base(r.out) == ib+2);
CHECK(ib[0] == 1);
CHECK(ib[1] == 0);
r = ranges::rotate_copy(InIter(ia), InIter(ia+2), Sent(ia+2), OutIter(ib));
CHECK(base(r.in) == ia+2);
CHECK(base(r.out) == ib+2);
CHECK(ib[0] == 0);
CHECK(ib[1] == 1);
r = ranges::rotate_copy(InIter(ia), InIter(ia), Sent(ia+3), OutIter(ib));
CHECK(base(r.in) == ia+3);
CHECK(base(r.out) == ib+3);
CHECK(ib[0] == 0);
CHECK(ib[1] == 1);
CHECK(ib[2] == 2);
r = ranges::rotate_copy(InIter(ia), InIter(ia+1), Sent(ia+3), OutIter(ib));
CHECK(base(r.in) == ia+3);
CHECK(base(r.out) == ib+3);
CHECK(ib[0] == 1);
CHECK(ib[1] == 2);
CHECK(ib[2] == 0);
r = ranges::rotate_copy(InIter(ia), InIter(ia+2), Sent(ia+3), OutIter(ib));
CHECK(base(r.in) == ia+3);
CHECK(base(r.out) == ib+3);
CHECK(ib[0] == 2);
CHECK(ib[1] == 0);
CHECK(ib[2] == 1);
r = ranges::rotate_copy(InIter(ia), InIter(ia+3), Sent(ia+3), OutIter(ib));
CHECK(base(r.in) == ia+3);
CHECK(base(r.out) == ib+3);
CHECK(ib[0] == 0);
CHECK(ib[1] == 1);
CHECK(ib[2] == 2);
r = ranges::rotate_copy(InIter(ia), InIter(ia), Sent(ia+4), OutIter(ib));
CHECK(base(r.in) == ia+4);
CHECK(base(r.out) == ib+4);
CHECK(ib[0] == 0);
CHECK(ib[1] == 1);
CHECK(ib[2] == 2);
CHECK(ib[3] == 3);
r = ranges::rotate_copy(InIter(ia), InIter(ia+1), Sent(ia+4), OutIter(ib));
CHECK(base(r.in) == ia+4);
CHECK(base(r.out) == ib+4);
CHECK(ib[0] == 1);
CHECK(ib[1] == 2);
CHECK(ib[2] == 3);
CHECK(ib[3] == 0);
r = ranges::rotate_copy(InIter(ia), InIter(ia+2), Sent(ia+4), OutIter(ib));
CHECK(base(r.in) == ia+4);
CHECK(base(r.out) == ib+4);
CHECK(ib[0] == 2);
CHECK(ib[1] == 3);
CHECK(ib[2] == 0);
CHECK(ib[3] == 1);
r = ranges::rotate_copy(InIter(ia), InIter(ia+3), Sent(ia+4), OutIter(ib));
CHECK(base(r.in) == ia+4);
CHECK(base(r.out) == ib+4);
CHECK(ib[0] == 3);
CHECK(ib[1] == 0);
CHECK(ib[2] == 1);
CHECK(ib[3] == 2);
r = ranges::rotate_copy(InIter(ia), InIter(ia+4), Sent(ia+4), OutIter(ib));
CHECK(base(r.in) == ia+4);
CHECK(base(r.out) == ib+4);
CHECK(ib[0] == 0);
CHECK(ib[1] == 1);
CHECK(ib[2] == 2);
CHECK(ib[3] == 3);
}
template<class InIter, class OutIter, typename Sent = InIter>
void test_rng()
{
int ia[] = {0, 1, 2, 3};
const unsigned sa = sizeof(ia)/sizeof(ia[0]);
int ib[sa] = {0};
ranges::rotate_copy_result<InIter, OutIter> r = ranges::rotate_copy(::as_lvalue(ranges::make_subrange(InIter(ia), Sent(ia))), InIter(ia), OutIter(ib));
CHECK(base(r.in) == ia);
CHECK(base(r.out) == ib);
r = ranges::rotate_copy(::as_lvalue(ranges::make_subrange(InIter(ia), Sent(ia+1))), InIter(ia), OutIter(ib));
CHECK(base(r.in) == ia+1);
CHECK(base(r.out) == ib+1);
CHECK(ib[0] == 0);
r = ranges::rotate_copy(::as_lvalue(ranges::make_subrange(InIter(ia), Sent(ia+1))), InIter(ia+1), OutIter(ib));
CHECK(base(r.in) == ia+1);
CHECK(base(r.out) == ib+1);
CHECK(ib[0] == 0);
r = ranges::rotate_copy(::as_lvalue(ranges::make_subrange(InIter(ia), Sent(ia+2))), InIter(ia), OutIter(ib));
CHECK(base(r.in) == ia+2);
CHECK(base(r.out) == ib+2);
CHECK(ib[0] == 0);
CHECK(ib[1] == 1);
r = ranges::rotate_copy(::as_lvalue(ranges::make_subrange(InIter(ia), Sent(ia+2))), InIter(ia+1), OutIter(ib));
CHECK(base(r.in) == ia+2);
CHECK(base(r.out) == ib+2);
CHECK(ib[0] == 1);
CHECK(ib[1] == 0);
r = ranges::rotate_copy(::as_lvalue(ranges::make_subrange(InIter(ia), Sent(ia+2))), InIter(ia+2), OutIter(ib));
CHECK(base(r.in) == ia+2);
CHECK(base(r.out) == ib+2);
CHECK(ib[0] == 0);
CHECK(ib[1] == 1);
r = ranges::rotate_copy(::as_lvalue(ranges::make_subrange(InIter(ia), Sent(ia+3))), InIter(ia), OutIter(ib));
CHECK(base(r.in) == ia+3);
CHECK(base(r.out) == ib+3);
CHECK(ib[0] == 0);
CHECK(ib[1] == 1);
CHECK(ib[2] == 2);
r = ranges::rotate_copy(::as_lvalue(ranges::make_subrange(InIter(ia), Sent(ia+3))), InIter(ia+1), OutIter(ib));
CHECK(base(r.in) == ia+3);
CHECK(base(r.out) == ib+3);
CHECK(ib[0] == 1);
CHECK(ib[1] == 2);
CHECK(ib[2] == 0);
r = ranges::rotate_copy(::as_lvalue(ranges::make_subrange(InIter(ia), Sent(ia+3))), InIter(ia+2), OutIter(ib));
CHECK(base(r.in) == ia+3);
CHECK(base(r.out) == ib+3);
CHECK(ib[0] == 2);
CHECK(ib[1] == 0);
CHECK(ib[2] == 1);
r = ranges::rotate_copy(::as_lvalue(ranges::make_subrange(InIter(ia), Sent(ia+3))), InIter(ia+3), OutIter(ib));
CHECK(base(r.in) == ia+3);
CHECK(base(r.out) == ib+3);
CHECK(ib[0] == 0);
CHECK(ib[1] == 1);
CHECK(ib[2] == 2);
r = ranges::rotate_copy(::as_lvalue(ranges::make_subrange(InIter(ia), Sent(ia+4))), InIter(ia), OutIter(ib));
CHECK(base(r.in) == ia+4);
CHECK(base(r.out) == ib+4);
CHECK(ib[0] == 0);
CHECK(ib[1] == 1);
CHECK(ib[2] == 2);
CHECK(ib[3] == 3);
r = ranges::rotate_copy(::as_lvalue(ranges::make_subrange(InIter(ia), Sent(ia+4))), InIter(ia+1), OutIter(ib));
CHECK(base(r.in) == ia+4);
CHECK(base(r.out) == ib+4);
CHECK(ib[0] == 1);
CHECK(ib[1] == 2);
CHECK(ib[2] == 3);
CHECK(ib[3] == 0);
r = ranges::rotate_copy(::as_lvalue(ranges::make_subrange(InIter(ia), Sent(ia+4))), InIter(ia+2), OutIter(ib));
CHECK(base(r.in) == ia+4);
CHECK(base(r.out) == ib+4);
CHECK(ib[0] == 2);
CHECK(ib[1] == 3);
CHECK(ib[2] == 0);
CHECK(ib[3] == 1);
r = ranges::rotate_copy(::as_lvalue(ranges::make_subrange(InIter(ia), Sent(ia+4))), InIter(ia+3), OutIter(ib));
CHECK(base(r.in) == ia+4);
CHECK(base(r.out) == ib+4);
CHECK(ib[0] == 3);
CHECK(ib[1] == 0);
CHECK(ib[2] == 1);
CHECK(ib[3] == 2);
r = ranges::rotate_copy(::as_lvalue(ranges::make_subrange(InIter(ia), Sent(ia+4))), InIter(ia+4), OutIter(ib));
CHECK(base(r.in) == ia+4);
CHECK(base(r.out) == ib+4);
CHECK(ib[0] == 0);
CHECK(ib[1] == 1);
CHECK(ib[2] == 2);
CHECK(ib[3] == 3);
}
template<class InIter, class OutIter, typename Sent = InIter>
void test()
{
test_iter<InIter, OutIter, Sent>();
test_rng<InIter, OutIter, Sent>();
}
struct S
{
int i;
};
constexpr bool test_constexpr()
{
using namespace ranges;
int rgi[] = {0, 1, 2, 3, 4, 5};
int rgo[6] = {0};
const auto r = ranges::rotate_copy(rgi, rgi + 2, rgo);
STATIC_CHECK_RETURN(r.in == ranges::end(rgi));
STATIC_CHECK_RETURN(r.out == ranges::end(rgo));
STATIC_CHECK_RETURN(rgo[0] == 2);
STATIC_CHECK_RETURN(rgo[1] == 3);
STATIC_CHECK_RETURN(rgo[2] == 4);
STATIC_CHECK_RETURN(rgo[3] == 5);
STATIC_CHECK_RETURN(rgo[4] == 0);
STATIC_CHECK_RETURN(rgo[5] == 1);
return true;
}
int main()
{
test<ForwardIterator<const int*>, OutputIterator<int*> >();
test<ForwardIterator<const int*>, ForwardIterator<int*> >();
test<ForwardIterator<const int*>, BidirectionalIterator<int*> >();
test<ForwardIterator<const int*>, RandomAccessIterator<int*> >();
test<ForwardIterator<const int*>, int*>();
test<BidirectionalIterator<const int*>, OutputIterator<int*> >();
test<BidirectionalIterator<const int*>, ForwardIterator<int*> >();
test<BidirectionalIterator<const int*>, BidirectionalIterator<int*> >();
test<BidirectionalIterator<const int*>, RandomAccessIterator<int*> >();
test<BidirectionalIterator<const int*>, int*>();
test<RandomAccessIterator<const int*>, OutputIterator<int*> >();
test<RandomAccessIterator<const int*>, ForwardIterator<int*> >();
test<RandomAccessIterator<const int*>, BidirectionalIterator<int*> >();
test<RandomAccessIterator<const int*>, RandomAccessIterator<int*> >();
test<RandomAccessIterator<const int*>, int*>();
test<ForwardIterator<const int*>, OutputIterator<int*>, Sentinel<const int*> >();
test<ForwardIterator<const int*>, ForwardIterator<int*>, Sentinel<const int*> >();
test<ForwardIterator<const int*>, BidirectionalIterator<int*>, Sentinel<const int*> >();
test<ForwardIterator<const int*>, RandomAccessIterator<int*>, Sentinel<const int*> >();
test<ForwardIterator<const int*>, int*, Sentinel<const int*> >();
test<BidirectionalIterator<const int*>, OutputIterator<int*>, Sentinel<const int*> >();
test<BidirectionalIterator<const int*>, ForwardIterator<int*>, Sentinel<const int*> >();
test<BidirectionalIterator<const int*>, BidirectionalIterator<int*>, Sentinel<const int*> >();
test<BidirectionalIterator<const int*>, RandomAccessIterator<int*>, Sentinel<const int*> >();
test<BidirectionalIterator<const int*>, int*, Sentinel<const int*> >();
test<RandomAccessIterator<const int*>, OutputIterator<int*>, Sentinel<const int*> >();
test<RandomAccessIterator<const int*>, ForwardIterator<int*>, Sentinel<const int*> >();
test<RandomAccessIterator<const int*>, BidirectionalIterator<int*>, Sentinel<const int*> >();
test<RandomAccessIterator<const int*>, RandomAccessIterator<int*>, Sentinel<const int*> >();
test<RandomAccessIterator<const int*>, int*, Sentinel<const int*> >();
test<const int*, OutputIterator<int*> >();
test<const int*, ForwardIterator<int*> >();
test<const int*, BidirectionalIterator<int*> >();
test<const int*, RandomAccessIterator<int*> >();
test<const int*, int*>();
// test rvalue ranges
{
int rgi[] = {0,1,2,3,4,5};
int rgo[6] = {0};
auto r = ranges::rotate_copy(std::move(rgi), rgi+2, rgo);
#ifndef RANGES_WORKAROUND_MSVC_573728
CHECK(::is_dangling(r.in));
#endif // RANGES_WORKAROUND_MSVC_573728
CHECK(r.out == ranges::end(rgo));
CHECK(rgo[0] == 2);
CHECK(rgo[1] == 3);
CHECK(rgo[2] == 4);
CHECK(rgo[3] == 5);
CHECK(rgo[4] == 0);
CHECK(rgo[5] == 1);
}
{
std::vector<int> rgi{0,1,2,3,4,5};
int rgo[6] = {0};
auto r = ranges::rotate_copy(std::move(rgi), rgi.begin()+2, rgo);
CHECK(::is_dangling(r.in));
CHECK(r.out == ranges::end(rgo));
CHECK(rgo[0] == 2);
CHECK(rgo[1] == 3);
CHECK(rgo[2] == 4);
CHECK(rgo[3] == 5);
CHECK(rgo[4] == 0);
CHECK(rgo[5] == 1);
}
{
STATIC_CHECK(test_constexpr());
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/merge.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright 2005 - 2007 Adobe Systems Incorporated
// Distributed under the MIT License(see accompanying file LICENSE_1_0_0.txt
// or a copy at http://stlab.adobe.com/licenses.html)
#include <memory>
#include <utility>
#include <algorithm>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/merge.hpp>
#include <range/v3/algorithm/is_sorted.hpp>
#include "../array.hpp"
#include "../simple_test.hpp"
#include "../test_iterators.hpp"
RANGES_DIAGNOSTIC_IGNORE_SIGN_CONVERSION
constexpr bool test_constexpr()
{
using namespace ranges;
constexpr unsigned N = 100;
test::array<int, N> ia{{0}};
test::array<int, N> ib{{0}};
test::array<int, 2 * N> ic{{0}};
for(unsigned i = 0; i < N; ++i)
ia[i] = 2 * i;
for(unsigned i = 0; i < N; ++i)
ib[i] = 2 * i + 1;
auto r = merge(ia, ib, begin(ic));
STATIC_CHECK_RETURN(r.in1 == end(ia));
STATIC_CHECK_RETURN(r.in2 == end(ib));
STATIC_CHECK_RETURN(r.out == end(ic));
STATIC_CHECK_RETURN(ic[0] == 0);
STATIC_CHECK_RETURN(ic[2 * N - 1] == (int)(2 * N - 1));
STATIC_CHECK_RETURN(is_sorted(ic));
return true;
}
int main()
{
{
int N = 100000;
std::unique_ptr<int[]> ia{new int[N]};
std::unique_ptr<int[]> ib{new int[N]};
std::unique_ptr<int[]> ic{new int[2 * N]};
for(int i = 0; i < N; ++i)
ia[i] = 2 * i;
for(int i = 0; i < N; ++i)
ib[i] = 2 * i + 1;
auto r = ranges::merge(ia.get(), ia.get() + N,
ib.get(), ib.get() + N, ic.get());
CHECK(r.in1 == ia.get() + N);
CHECK(r.in2 == ib.get() + N);
CHECK(r.out == ic.get() + 2 * N);
CHECK(ic[0] == 0);
CHECK(ic[2 * N - 1] == 2 * N - 1);
CHECK(std::is_sorted(ic.get(), ic.get() + 2 * N));
}
{
int N = 100000;
std::unique_ptr<int[]> ia{new int[N]};
std::unique_ptr<int[]> ib{new int[N]};
std::unique_ptr<int[]> ic{new int[2 * N]};
for(int i = 0; i < N; ++i)
ia[i] = 2 * i;
for(int i = 0; i < N; ++i)
ib[i] = 2 * i + 1;
auto r0 = ranges::make_subrange(ia.get(), ia.get() + N);
auto r1 = ranges::make_subrange(ib.get(), ib.get() + N);
auto r = ranges::merge(r0, r1, ic.get());
CHECK(r.in1 == ia.get() + N);
CHECK(r.in2 == ib.get() + N);
CHECK(r.out == ic.get() + 2 * N);
CHECK(ic[0] == 0);
CHECK(ic[2 * N - 1] == 2 * N - 1);
CHECK(std::is_sorted(ic.get(), ic.get() + 2 * N));
}
{
int N = 100000;
std::unique_ptr<int[]> ia{new int[N]};
std::unique_ptr<int[]> ib{new int[N]};
std::unique_ptr<int[]> ic{new int[2 * N]};
for(int i = 0; i < N; ++i)
ia[i] = 2 * i;
for(int i = 0; i < N; ++i)
ib[i] = 2 * i + 1;
auto r0 = ::MakeTestRange(ia.get(), ia.get() + N);
auto r1 = ::MakeTestRange(ib.get(), ib.get() + N);
auto r = ranges::merge(std::move(r0), std::move(r1), ic.get());
CHECK(::is_dangling(r.in1));
CHECK(::is_dangling(r.in2));
CHECK(r.out == ic.get() + 2 * N);
CHECK(ic[0] == 0);
CHECK(ic[2 * N - 1] == 2 * N - 1);
CHECK(std::is_sorted(ic.get(), ic.get() + 2 * N));
static_assert(std::is_same<decltype(r),
ranges::merge_result<ranges::dangling, ranges::dangling, int *>>::value, "");
}
{
STATIC_CHECK(test_constexpr());
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/unstable_remove_if.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#include <range/v3/algorithm/equal.hpp>
#include <range/v3/algorithm/unstable_remove_if.hpp>
#include <range/v3/view/subrange.hpp>
#include "../array.hpp"
#include "../simple_test.hpp"
constexpr bool is_even(int i)
{
return i % 2 == 0;
}
constexpr bool test_constexpr()
{
using IL = std::initializer_list<int>;
test::array<int, 5> arr{{1, 2, 3, 4, 5}};
const auto it = ranges::unstable_remove_if(arr, is_even);
STATIC_CHECK_RETURN(it == arr.begin() + 3);
STATIC_CHECK_RETURN(
ranges::equal(ranges::make_subrange(arr.begin(), it), IL{1, 5, 3}));
return true;
}
int main()
{
STATIC_CHECK(test_constexpr());
return test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/remove_copy_if.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright 2005 - 2007 Adobe Systems Incorporated
// Distributed under the MIT License(see accompanying file LICENSE_1_0_0.txt
// or a copy at http://stlab.adobe.com/licenses.html)
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <functional>
#include <memory>
#include <utility>
#include <vector>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/remove_copy_if.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
template<class InIter, class OutIter, class Sent = InIter>
void
test_iter()
{
int ia[] = {0, 1, 2, 3, 4, 2, 3, 4, 2};
constexpr auto sa = ranges::size(ia);
int ib[sa];
ranges::remove_copy_if_result<InIter, OutIter> r = ranges::remove_copy_if(InIter(ia), Sent(ia+sa), OutIter(ib), [](int i){return i == 2;});
CHECK(base(r.in) == ia + sa);
CHECK(base(r.out) == ib + sa-3);
CHECK(ib[0] == 0);
CHECK(ib[1] == 1);
CHECK(ib[2] == 3);
CHECK(ib[3] == 4);
CHECK(ib[4] == 3);
CHECK(ib[5] == 4);
}
template<class InIter, class OutIter, class Sent = InIter>
void
test_range()
{
int ia[] = {0, 1, 2, 3, 4, 2, 3, 4, 2};
constexpr auto sa = ranges::size(ia);
int ib[sa];
ranges::remove_copy_if_result<InIter, OutIter> r = ranges::remove_copy_if(::as_lvalue(ranges::make_subrange(InIter(ia), Sent(ia+sa))), OutIter(ib), [](int i){return i == 2;});
CHECK(base(r.in) == ia + sa);
CHECK(base(r.out) == ib + sa-3);
CHECK(ib[0] == 0);
CHECK(ib[1] == 1);
CHECK(ib[2] == 3);
CHECK(ib[3] == 4);
CHECK(ib[4] == 3);
CHECK(ib[5] == 4);
}
template<class InIter, class OutIter, class Sent = InIter>
void
test()
{
test_iter<InIter, OutIter, Sent>();
test_range<InIter, OutIter, Sent>();
}
struct S
{
int i;
};
constexpr bool equals_two(int i)
{
return i == 2;
}
constexpr bool test_constexpr()
{
using namespace ranges;
int ia[] = {0, 1, 2, 3, 4, 2, 3, 4, 2};
int ib[6] = {0};
constexpr auto sa = ranges::size(ia);
auto r = ranges::remove_copy_if(ia, ib, equals_two);
STATIC_CHECK_RETURN(r.in == ia + sa);
STATIC_CHECK_RETURN(r.out == ib + (sa - 3));
STATIC_CHECK_RETURN(ib[0] == 0);
STATIC_CHECK_RETURN(ib[1] == 1);
STATIC_CHECK_RETURN(ib[2] == 3);
STATIC_CHECK_RETURN(ib[3] == 4);
STATIC_CHECK_RETURN(ib[4] == 3);
STATIC_CHECK_RETURN(ib[5] == 4);
return true;
}
int main()
{
test<InputIterator<const int*>, OutputIterator<int*>>();
test<InputIterator<const int*>, ForwardIterator<int*>>();
test<InputIterator<const int*>, BidirectionalIterator<int*>>();
test<InputIterator<const int*>, RandomAccessIterator<int*>>();
test<InputIterator<const int*>, int*>();
test<ForwardIterator<const int*>, OutputIterator<int*>>();
test<ForwardIterator<const int*>, ForwardIterator<int*>>();
test<ForwardIterator<const int*>, BidirectionalIterator<int*>>();
test<ForwardIterator<const int*>, RandomAccessIterator<int*>>();
test<ForwardIterator<const int*>, int*>();
test<BidirectionalIterator<const int*>, OutputIterator<int*>>();
test<BidirectionalIterator<const int*>, ForwardIterator<int*>>();
test<BidirectionalIterator<const int*>, BidirectionalIterator<int*>>();
test<BidirectionalIterator<const int*>, RandomAccessIterator<int*>>();
test<BidirectionalIterator<const int*>, int*>();
test<RandomAccessIterator<const int*>, OutputIterator<int*>>();
test<RandomAccessIterator<const int*>, ForwardIterator<int*>>();
test<RandomAccessIterator<const int*>, BidirectionalIterator<int*>>();
test<RandomAccessIterator<const int*>, RandomAccessIterator<int*>>();
test<RandomAccessIterator<const int*>, int*>();
test<const int*, OutputIterator<int*>>();
test<const int*, ForwardIterator<int*>>();
test<const int*, BidirectionalIterator<int*>>();
test<const int*, RandomAccessIterator<int*>>();
test<const int*, int*>();
test<InputIterator<const int*>, OutputIterator<int*>, Sentinel<const int*>>();
test<InputIterator<const int*>, ForwardIterator<int*>, Sentinel<const int*>>();
test<InputIterator<const int*>, BidirectionalIterator<int*>, Sentinel<const int*>>();
test<InputIterator<const int*>, RandomAccessIterator<int*>, Sentinel<const int*>>();
test<InputIterator<const int*>, int*, Sentinel<const int*>>();
test<ForwardIterator<const int*>, OutputIterator<int*>, Sentinel<const int*>>();
test<ForwardIterator<const int*>, ForwardIterator<int*>, Sentinel<const int*>>();
test<ForwardIterator<const int*>, BidirectionalIterator<int*>, Sentinel<const int*>>();
test<ForwardIterator<const int*>, RandomAccessIterator<int*>, Sentinel<const int*>>();
test<ForwardIterator<const int*>, int*, Sentinel<const int*>>();
test<BidirectionalIterator<const int*>, OutputIterator<int*>, Sentinel<const int*>>();
test<BidirectionalIterator<const int*>, ForwardIterator<int*>, Sentinel<const int*>>();
test<BidirectionalIterator<const int*>, BidirectionalIterator<int*>, Sentinel<const int*>>();
test<BidirectionalIterator<const int*>, RandomAccessIterator<int*>, Sentinel<const int*>>();
test<BidirectionalIterator<const int*>, int*, Sentinel<const int*>>();
test<RandomAccessIterator<const int*>, OutputIterator<int*>, Sentinel<const int*>>();
test<RandomAccessIterator<const int*>, ForwardIterator<int*>, Sentinel<const int*>>();
test<RandomAccessIterator<const int*>, BidirectionalIterator<int*>, Sentinel<const int*>>();
test<RandomAccessIterator<const int*>, RandomAccessIterator<int*>, Sentinel<const int*>>();
test<RandomAccessIterator<const int*>, int*, Sentinel<const int*>>();
// Check projection
{
S ia[] = {S{0}, S{1}, S{2}, S{3}, S{4}, S{2}, S{3}, S{4}, S{2}};
constexpr auto sa = ranges::size(ia);
S ib[sa];
ranges::remove_copy_if_result<S*, S*> r = ranges::remove_copy_if(ia, ib, [](int i){return i == 2;}, &S::i);
CHECK(r.in == ia + sa);
CHECK(r.out == ib + sa-3);
CHECK(ib[0].i == 0);
CHECK(ib[1].i == 1);
CHECK(ib[2].i == 3);
CHECK(ib[3].i == 4);
CHECK(ib[4].i == 3);
CHECK(ib[5].i == 4);
}
// Check rvalue range
{
S ia[] = {S{0}, S{1}, S{2}, S{3}, S{4}, S{2}, S{3}, S{4}, S{2}};
constexpr auto sa = ranges::size(ia);
S ib[sa] = {};
auto r0 = ranges::remove_copy_if(std::move(ia), ib, [](int i){return i == 2;}, &S::i);
#ifndef RANGES_WORKAROUND_MSVC_573728
CHECK(::is_dangling(r0.in));
#endif // RANGES_WORKAROUND_MSVC_573728
CHECK(r0.out == ib + sa-3);
CHECK(ib[0].i == 0);
CHECK(ib[1].i == 1);
CHECK(ib[2].i == 3);
CHECK(ib[3].i == 4);
CHECK(ib[4].i == 3);
CHECK(ib[5].i == 4);
std::fill(ranges::begin(ib), ranges::end(ib), S{});
std::vector<S> vec(ranges::begin(ia), ranges::end(ia));
auto r1 = ranges::remove_copy_if(std::move(vec), ib, [](int i){return i == 2;}, &S::i);
CHECK(::is_dangling(r1.in));
CHECK(r1.out == ib + sa-3);
CHECK(ib[0].i == 0);
CHECK(ib[1].i == 1);
CHECK(ib[2].i == 3);
CHECK(ib[3].i == 4);
CHECK(ib[4].i == 3);
CHECK(ib[5].i == 4);
}
{
STATIC_CHECK(test_constexpr());
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/replace_if.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright 2005 - 2007 Adobe Systems Incorporated
// Distributed under the MIT License(see accompanying file LICENSE_1_0_0.txt
// or a copy at http://stlab.adobe.com/licenses.html)
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <utility>
#include <vector>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/replace_if.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
template<typename Iter, typename Sent = Iter>
void test_iter()
{
int ia[] = {0, 1, 2, 3, 4};
const unsigned sa = sizeof(ia)/sizeof(ia[0]);
Iter i = ranges::replace_if(Iter(ia), Sent(ia+sa), [](int j){return j==2;}, 5);
CHECK(ia[0] == 0);
CHECK(ia[1] == 1);
CHECK(ia[2] == 5);
CHECK(ia[3] == 3);
CHECK(ia[4] == 4);
CHECK(base(i) == ia + sa);
}
template<typename Iter, typename Sent = Iter>
void test_rng()
{
int ia[] = {0, 1, 2, 3, 4};
const unsigned sa = sizeof(ia)/sizeof(ia[0]);
auto rng = ranges::make_subrange(Iter(ia), Sent(ia+sa));
Iter i = ranges::replace_if(rng, [](int j){return j==2;}, 5);
CHECK(ia[0] == 0);
CHECK(ia[1] == 1);
CHECK(ia[2] == 5);
CHECK(ia[3] == 3);
CHECK(ia[4] == 4);
CHECK(base(i) == ia + sa);
}
constexpr bool equals_two(int i)
{
return i == 2;
}
constexpr bool test_constexpr()
{
using namespace ranges;
int ia[] = {0, 1, 2, 3, 4};
constexpr auto sa = ranges::size(ia);
auto r = ranges::replace_if(ia, equals_two, 42);
STATIC_CHECK_RETURN(r == ia + sa);
STATIC_CHECK_RETURN(ia[0] == 0);
STATIC_CHECK_RETURN(ia[1] == 1);
STATIC_CHECK_RETURN(ia[2] == 42);
STATIC_CHECK_RETURN(ia[3] == 3);
STATIC_CHECK_RETURN(ia[4] == 4);
return true;
}
int main()
{
test_iter<ForwardIterator<int*> >();
test_iter<BidirectionalIterator<int*> >();
test_iter<RandomAccessIterator<int*> >();
test_iter<int*>();
test_iter<ForwardIterator<int*>, Sentinel<int*> >();
test_iter<BidirectionalIterator<int*>, Sentinel<int*> >();
test_iter<RandomAccessIterator<int*>, Sentinel<int*> >();
test_rng<ForwardIterator<int*> >();
test_rng<BidirectionalIterator<int*> >();
test_rng<RandomAccessIterator<int*> >();
test_rng<int*>();
test_rng<ForwardIterator<int*>, Sentinel<int*> >();
test_rng<BidirectionalIterator<int*>, Sentinel<int*> >();
test_rng<RandomAccessIterator<int*>, Sentinel<int*> >();
// test projection
{
using P = std::pair<int,std::string>;
P ia[] = {{0,"0"}, {1,"1"}, {2,"2"}, {3,"3"}, {4,"4"}};
P *i = ranges::replace_if(ia, [](int j){return j==2;}, std::make_pair(42,"42"),
&std::pair<int,std::string>::first);
CHECK(ia[0] == P{0,"0"});
CHECK(ia[1] == P{1,"1"});
CHECK(ia[2] == P{42,"42"});
CHECK(ia[3] == P{3,"3"});
CHECK(ia[4] == P{4,"4"});
CHECK(i == ranges::end(ia));
}
// test rvalue ranges
{
using P = std::pair<int,std::string>;
P ia[] = {{0,"0"}, {1,"1"}, {2,"2"}, {3,"3"}, {4,"4"}};
auto i = ranges::replace_if(std::move(ia), [](int j){return j==2;}, std::make_pair(42,"42"),
&std::pair<int,std::string>::first);
#ifndef RANGES_WORKAROUND_MSVC_573728
CHECK(::is_dangling(i));
#endif // RANGES_WORKAROUND_MSVC_573728
CHECK(ia[0] == P{0,"0"});
CHECK(ia[1] == P{1,"1"});
CHECK(ia[2] == P{42,"42"});
CHECK(ia[3] == P{3,"3"});
CHECK(ia[4] == P{4,"4"});
}
{
using P = std::pair<int,std::string>;
std::vector<P> ia{{0,"0"}, {1,"1"}, {2,"2"}, {3,"3"}, {4,"4"}};
auto i = ranges::replace_if(std::move(ia), [](int j){return j==2;}, std::make_pair(42,"42"),
&std::pair<int,std::string>::first);
CHECK(::is_dangling(i));
CHECK(ia[0] == P{0,"0"});
CHECK(ia[1] == P{1,"1"});
CHECK(ia[2] == P{42,"42"});
CHECK(ia[3] == P{3,"3"});
CHECK(ia[4] == P{4,"4"});
}
{
STATIC_CHECK(test_constexpr());
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/stable_sort.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <memory>
#include <random>
#include <vector>
#include <algorithm>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/stable_sort.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
RANGES_DIAGNOSTIC_IGNORE_GLOBAL_CONSTRUCTORS
RANGES_DIAGNOSTIC_IGNORE_SIGN_CONVERSION
namespace
{
std::mt19937 gen;
#if !defined(__clang__) || !defined(_MSVC_STL_VERSION) // Avoid #890
struct indirect_less
{
template<class P>
bool operator()(const P& x, const P& y)
{return *x < *y;}
};
#endif // Avoid #890
template<class RI>
void
test_sort_helper(RI f, RI l)
{
using value_type = ranges::iter_value_t<RI>;
auto stable_sort = make_testable_1<false>(ranges::stable_sort);
if (f != l)
{
auto len = l - f;
value_type* save(new value_type[len]);
do
{
std::copy(f, l, save);
stable_sort(save, save+len).check([&](int *res)
{
CHECK(res == save+len);
CHECK(std::is_sorted(save, save+len));
std::copy(f, l, save);
});
stable_sort(save, save+len, std::greater<int>{}).check([&](int *res)
{
CHECK(res == save+len);
CHECK(std::is_sorted(save, save+len, std::greater<int>{}));
std::copy(f, l, save);
});
} while (std::next_permutation(f, l));
delete [] save;
}
}
template<class RI>
void
test_sort_driver_driver(RI f, RI l, int start, RI real_last)
{
for (RI i = l; i > f + start;)
{
*--i = start;
if (f == i)
{
test_sort_helper(f, real_last);
}
if (start > 0)
test_sort_driver_driver(f, i, start-1, real_last);
}
}
template<class RI>
void
test_sort_driver(RI f, RI l, int start)
{
test_sort_driver_driver(f, l, start, l);
}
template<int sa>
void
test_sort_()
{
int ia[sa];
for (int i = 0; i < sa; ++i)
{
test_sort_driver(ia, ia+sa, i);
}
}
void
test_larger_sorts(int N, int M)
{
RANGES_ENSURE(N > 0);
RANGES_ENSURE(M > 0);
// create array length N filled with M different numbers
int* array = new int[N];
int x = 0;
for (int i = 0; i < N; ++i)
{
array[i] = x;
if (++x == M)
x = 0;
}
// test saw tooth pattern
CHECK(ranges::stable_sort(array, array+N) == array+N);
CHECK(std::is_sorted(array, array+N));
// test random pattern
std::shuffle(array, array+N, gen);
CHECK(ranges::stable_sort(array, array+N) == array+N);
CHECK(std::is_sorted(array, array+N));
// test sorted pattern
CHECK(ranges::stable_sort(array, array+N) == array+N);
CHECK(std::is_sorted(array, array+N));
// test reverse sorted pattern
std::reverse(array, array+N);
CHECK(ranges::stable_sort(array, array+N) == array+N);
CHECK(std::is_sorted(array, array+N));
// test swap ranges 2 pattern
std::swap_ranges(array, array+N/2, array+N/2);
CHECK(ranges::stable_sort(array, array+N) == array+N);
CHECK(std::is_sorted(array, array+N));
// test reverse swap ranges 2 pattern
std::reverse(array, array+N);
std::swap_ranges(array, array+N/2, array+N/2);
CHECK(ranges::stable_sort(array, array+N) == array+N);
CHECK(std::is_sorted(array, array+N));
delete [] array;
}
void
test_larger_sorts(unsigned N)
{
test_larger_sorts(N, 1);
test_larger_sorts(N, 2);
test_larger_sorts(N, 3);
test_larger_sorts(N, N/2-1);
test_larger_sorts(N, N/2);
test_larger_sorts(N, N/2+1);
test_larger_sorts(N, N-2);
test_larger_sorts(N, N-1);
test_larger_sorts(N, N);
}
struct S
{
int i, j;
};
}
int main()
{
// test null range
int d = 0;
int * r = ranges::stable_sort(&d, &d);
CHECK(r == &d);
// exhaustively test all possibilities up to length 8
test_sort_<1>();
test_sort_<2>();
test_sort_<3>();
test_sort_<4>();
test_sort_<5>();
test_sort_<6>();
test_sort_<7>();
test_sort_<8>();
test_larger_sorts(15);
test_larger_sorts(16);
test_larger_sorts(17);
test_larger_sorts(256);
test_larger_sorts(257);
test_larger_sorts(499);
test_larger_sorts(500);
test_larger_sorts(997);
test_larger_sorts(1000);
test_larger_sorts(1009);
#if !defined(__clang__) || !defined(_MSVC_STL_VERSION) // Avoid #890
// Check move-only types
{
std::vector<std::unique_ptr<int> > v(1000);
for(int i = 0; (std::size_t)i < v.size(); ++i)
v[i].reset(new int((int)v.size() - i - 1));
ranges::stable_sort(v, indirect_less());
for(int i = 0; (std::size_t)i < v.size(); ++i)
CHECK(*v[i] == i);
}
// Check projections
{
std::vector<S> v(1000, S{});
for(int i = 0; (std::size_t)i < v.size(); ++i)
{
v[i].i = (int)v.size() - i - 1;
v[i].j = i;
}
ranges::stable_sort(v, std::less<int>{}, &S::i);
for(int i = 0; (std::size_t)i < v.size(); ++i)
{
CHECK(v[i].i == i);
CHECK((std::size_t)v[i].j == v.size() - i - 1);
}
}
// Check rvalue container
{
std::vector<S> v(1000, S{});
for(int i = 0; (std::size_t)i < v.size(); ++i)
{
v[i].i = (int)v.size() - i - 1;
v[i].j = i;
}
CHECK(::is_dangling(ranges::stable_sort(std::move(v), std::less<int>{}, &S::i)));
for(int i = 0; (std::size_t)i < v.size(); ++i)
{
CHECK(v[i].i == i);
CHECK((std::size_t)v[i].j == v.size() - i - 1);
}
}
// Check rvalue forwarding range
{
std::vector<S> v(1000, S{});
for(int i = 0; (std::size_t)i < v.size(); ++i)
{
v[i].i = (int)v.size() - i - 1;
v[i].j = i;
}
CHECK(ranges::stable_sort(ranges::views::all(v), std::less<int>{}, &S::i) == v.end());
for(int i = 0; (std::size_t)i < v.size(); ++i)
{
CHECK(v[i].i == i);
CHECK((std::size_t)v[i].j == v.size() - i - 1);
}
}
#endif // Avoid #890
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/CMakeLists.txt | set(CMAKE_FOLDER "${CMAKE_FOLDER}/algorithm")
rv3_add_test(test.alg.adjacent_find alg.adjacent_find adjacent_find.cpp)
rv3_add_test(test.alg.adjacent_remove_if alg.adjacent_remove_if adjacent_remove_if.cpp)
rv3_add_test(test.alg.all_of alg.all_of all_of.cpp)
rv3_add_test(test.alg.any_of alg.any_of any_of.cpp)
rv3_add_test(test.alg.none_of alg.none_of none_of.cpp)
rv3_add_test(test.alg.binary_search alg.binary_search binary_search.cpp)
rv3_add_test(test.alg.contains alg.contains contains.cpp)
rv3_add_test(test.alg.contains_subrange alg.contains_subrange contains_subrange.cpp)
rv3_add_test(test.alg.copy alg.copy copy.cpp)
rv3_add_test(test.alg.copy_backward alg.copy_backward copy_backward.cpp)
rv3_add_test(test.alg.copy_if alg.copy_if copy_if.cpp)
rv3_add_test(test.alg.count alg.count count.cpp)
rv3_add_test(test.alg.count_if alg.count_if count_if.cpp)
rv3_add_test(test.alg.ends_with alg.ends_with ends_with.cpp)
rv3_add_test(test.alg.equal alg.equal equal.cpp)
rv3_add_test(test.alg.equal_range alg.equal_range equal_range.cpp)
rv3_add_test(test.alg.fill alg.fill fill.cpp)
rv3_add_test(test.alg.find alg.find find.cpp)
rv3_add_test(test.alg.find_end alg.find_end find_end.cpp)
rv3_add_test(test.alg.find_if alg.find_if find_if.cpp)
rv3_add_test(test.alg.find_if_not alg.find_if_not find_if_not.cpp)
rv3_add_test(test.alg.find_first_of alg.find_first_of find_first_of.cpp)
rv3_add_test(test.alg.fold alg.fold fold.cpp)
rv3_add_test(test.alg.for_each alg.for_each for_each.cpp)
rv3_add_test(test.alg.for_each_n alg.for_each_n for_each_n.cpp)
rv3_add_test(test.alg.generate alg.generate generate.cpp)
rv3_add_test(test.alg.generate_n alg.generate_n generate_n.cpp)
rv3_add_test(test.alg.includes alg.includes includes.cpp)
rv3_add_test(test.alg.inplace_merge alg.inplace_merge inplace_merge.cpp)
rv3_add_test(test.alg.is_heap1 alg.is_heap1 is_heap1.cpp)
rv3_add_test(test.alg.is_heap2 alg.is_heap2 is_heap2.cpp)
rv3_add_test(test.alg.is_heap3 alg.is_heap3 is_heap3.cpp)
rv3_add_test(test.alg.is_heap4 alg.is_heap4 is_heap4.cpp)
rv3_add_test(test.alg.is_heap_until1 alg.is_heap_until1 is_heap_until1.cpp)
rv3_add_test(test.alg.is_heap_until2 alg.is_heap_until2 is_heap_until2.cpp)
rv3_add_test(test.alg.is_heap_until3 alg.is_heap_until3 is_heap_until3.cpp)
rv3_add_test(test.alg.is_heap_until4 alg.is_heap_until4 is_heap_until4.cpp)
rv3_add_test(test.alg.is_partitioned alg.is_partitioned is_partitioned.cpp)
rv3_add_test(test.alg.is_permutation alg.is_permutation is_permutation.cpp)
rv3_add_test(test.alg.is_sorted_until alg.is_sorted_until is_sorted_until.cpp)
rv3_add_test(test.alg.is_sorted alg.is_sorted is_sorted.cpp)
rv3_add_test(test.alg.lexicographical_compare alg.lexicographical_compare lexicographical_compare.cpp)
rv3_add_test(test.alg.lower_bound alg.lower_bound lower_bound.cpp)
rv3_add_test(test.alg.make_heap alg.make_heap make_heap.cpp)
rv3_add_test(test.alg.max alg.max max.cpp)
rv3_add_test(test.alg.max_element alg.max_element max_element.cpp)
rv3_add_test(test.alg.merge alg.merge merge.cpp)
rv3_add_test(test.alg.min alg.min min.cpp)
rv3_add_test(test.alg.min_element alg.min_element min_element.cpp)
rv3_add_test(test.alg.minmax alg.minmax minmax.cpp)
rv3_add_test(test.alg.minmax_element alg.minmax_element minmax_element.cpp)
rv3_add_test(test.alg.mismatch alg.mismatch mismatch.cpp)
rv3_add_test(test.alg.move alg.move move.cpp)
rv3_add_test(test.alg.move_backward alg.move_backward move_backward.cpp)
rv3_add_test(test.alg.next_permutation alg.next_permutation next_permutation.cpp)
rv3_add_test(test.alg.nth_element alg.nth_element nth_element.cpp)
rv3_add_test(test.alg.partial_sort alg.partial_sort partial_sort.cpp)
rv3_add_test(test.alg.partial_sort_copy alg.partial_sort_copy partial_sort_copy.cpp)
rv3_add_test(test.alg.partition alg.partition partition.cpp)
rv3_add_test(test.alg.partition_copy alg.partition_copy partition_copy.cpp)
rv3_add_test(test.alg.partition_point alg.partition_point partition_point.cpp)
rv3_add_test(test.alg.pop_heap alg.pop_heap pop_heap.cpp)
rv3_add_test(test.alg.prev_permutation alg.prev_permutation prev_permutation.cpp)
rv3_add_test(test.alg.push_heap alg.push_heap push_heap.cpp)
rv3_add_test(test.alg.remove alg.remove remove.cpp)
rv3_add_test(test.alg.remove_copy alg.remove_copy remove_copy.cpp)
rv3_add_test(test.alg.remove_copy_if alg.remove_copy_if remove_copy_if.cpp)
rv3_add_test(test.alg.remove_if alg.remove_if remove_if.cpp)
rv3_add_test(test.alg.replace alg.replace replace.cpp)
rv3_add_test(test.alg.replace_copy alg.replace_copy replace_copy.cpp)
rv3_add_test(test.alg.replace_copy_if alg.replace_copy_if replace_copy_if.cpp)
rv3_add_test(test.alg.replace_if alg.replace_if replace_if.cpp)
rv3_add_test(test.alg.reverse alg.reverse reverse.cpp)
rv3_add_test(test.alg.reverse_copy alg.reverse_copy reverse_copy.cpp)
rv3_add_test(test.alg.rotate alg.rotate rotate.cpp)
rv3_add_test(test.alg.rotate_copy alg.rotate_copy rotate_copy.cpp)
rv3_add_test(test.alg.sample alg.sample sample.cpp)
rv3_add_test(test.alg.search alg.search search.cpp)
rv3_add_test(test.alg.search_n alg.search_n search_n.cpp)
rv3_add_test(test.alg.set_difference1 alg.set_difference1 set_difference1.cpp)
rv3_add_test(test.alg.set_difference2 alg.set_difference2 set_difference2.cpp)
rv3_add_test(test.alg.set_difference3 alg.set_difference3 set_difference3.cpp)
rv3_add_test(test.alg.set_difference4 alg.set_difference4 set_difference4.cpp)
rv3_add_test(test.alg.set_difference5 alg.set_difference5 set_difference5.cpp)
rv3_add_test(test.alg.set_difference6 alg.set_difference6 set_difference6.cpp)
rv3_add_test(test.alg.set_intersection1 alg.set_intersection1 set_intersection1.cpp)
rv3_add_test(test.alg.set_intersection2 alg.set_intersection2 set_intersection2.cpp)
rv3_add_test(test.alg.set_intersection3 alg.set_intersection3 set_intersection3.cpp)
rv3_add_test(test.alg.set_intersection4 alg.set_intersection4 set_intersection4.cpp)
rv3_add_test(test.alg.set_intersection5 alg.set_intersection5 set_intersection5.cpp)
rv3_add_test(test.alg.set_intersection6 alg.set_intersection6 set_intersection6.cpp)
rv3_add_test(test.alg.set_symmetric_difference1 alg.set_symmetric_difference1 set_symmetric_difference1.cpp)
rv3_add_test(test.alg.set_symmetric_difference2 alg.set_symmetric_difference2 set_symmetric_difference2.cpp)
rv3_add_test(test.alg.set_symmetric_difference3 alg.set_symmetric_difference3 set_symmetric_difference3.cpp)
rv3_add_test(test.alg.set_symmetric_difference4 alg.set_symmetric_difference4 set_symmetric_difference4.cpp)
rv3_add_test(test.alg.set_symmetric_difference5 alg.set_symmetric_difference5 set_symmetric_difference5.cpp)
rv3_add_test(test.alg.set_symmetric_difference6 alg.set_symmetric_difference6 set_symmetric_difference6.cpp)
rv3_add_test(test.alg.set_union1 alg.set_union1 set_union1.cpp)
rv3_add_test(test.alg.set_union2 alg.set_union2 set_union2.cpp)
rv3_add_test(test.alg.set_union3 alg.set_union3 set_union3.cpp)
rv3_add_test(test.alg.set_union4 alg.set_union4 set_union4.cpp)
rv3_add_test(test.alg.set_union5 alg.set_union5 set_union5.cpp)
rv3_add_test(test.alg.set_union6 alg.set_union6 set_union6.cpp)
rv3_add_test(test.alg.shuffle alg.shuffle shuffle.cpp)
rv3_add_test(test.alg.sort alg.sort sort.cpp)
rv3_add_test(test.alg.sort_heap alg.sort_heap sort_heap.cpp)
rv3_add_test(test.alg.stable_partition alg.stable_partition stable_partition.cpp)
rv3_add_test(test.alg.stable_sort alg.stable_sort stable_sort.cpp)
rv3_add_test(test.alg.starts_with alg.starts_with starts_with.cpp)
rv3_add_test(test.alg.swap_ranges alg.swap_ranges swap_ranges.cpp)
rv3_add_test(test.alg.transform alg.transform transform.cpp)
rv3_add_test(test.alg.unique alg.unique unique.cpp)
rv3_add_test(test.alg.unique_copy alg.unique_copy unique_copy.cpp)
rv3_add_test(test.alg.unstable_remove_if alg.unstable_remove_if unstable_remove_if.cpp)
rv3_add_test(test.alg.upper_bound alg.upper_bound upper_bound.cpp)
rv3_add_test(test.alg.sort_n_with_buffer alg.sort_n_with_buffer sort_n_with_buffer.cpp)
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/set_union6.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#define SET_UNION_6
#include "./set_union.hpp"
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/min_element.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <memory>
#include <random>
#include <numeric>
#include <algorithm>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/min_element.hpp>
#include "../array.hpp"
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
RANGES_DIAGNOSTIC_IGNORE_GLOBAL_CONSTRUCTORS
namespace
{
std::mt19937 gen;
template<class Iter, class Sent = Iter>
void
test_iter(Iter first, Sent last)
{
Iter i = ranges::min_element(first, last);
if (first != last)
{
for (Iter j = first; j != last; ++j)
CHECK(!(*j < *i));
}
else
CHECK(i == last);
auto rng = ::MakeTestRange(first, last);
i = ranges::min_element(rng);
if (first != last)
{
for (Iter j = first; j != last; ++j)
CHECK(!(*j < *i));
}
else
CHECK(i == last);
auto res = ranges::min_element(std::move(rng));
CHECK(::is_dangling(res));
}
template<class Iter, class Sent = Iter>
void
test_iter(unsigned N)
{
std::unique_ptr<int[]> a{new int[N]};
std::iota(a.get(), a.get()+N, 0);
std::shuffle(a.get(), a.get()+N, gen);
test_iter(Iter(a.get()), Sent(a.get()+N));
}
template<class Iter, class Sent = Iter>
void
test_iter()
{
test_iter<Iter, Sent>(0);
test_iter<Iter, Sent>(1);
test_iter<Iter, Sent>(2);
test_iter<Iter, Sent>(3);
test_iter<Iter, Sent>(10);
test_iter<Iter, Sent>(1000);
}
template<class Iter, class Sent = Iter>
void
test_iter_comp(Iter first, Sent last)
{
Iter i = ranges::min_element(first, last, std::greater<int>());
if (first != last)
{
for (Iter j = first; j != last; ++j)
CHECK(!std::greater<int>()(*j, *i));
}
else
CHECK(i == last);
auto rng = ::MakeTestRange(first, last);
i = ranges::min_element(rng, std::greater<int>());
if (first != last)
{
for (Iter j = first; j != last; ++j)
CHECK(!std::greater<int>()(*j, *i));
}
else
CHECK(i == last);
auto res = ranges::min_element(std::move(rng), std::greater<int>());
CHECK(::is_dangling(res));
}
template<class Iter, class Sent = Iter>
void
test_iter_comp(unsigned N)
{
std::unique_ptr<int[]> a{new int[N]};
std::iota(a.get(), a.get()+N, 0);
std::shuffle(a.get(), a.get()+N, gen);
test_iter_comp(Iter(a.get()), Sent(a.get()+N));
}
template<class Iter, class Sent = Iter>
void
test_iter_comp()
{
test_iter_comp<Iter, Sent>(0);
test_iter_comp<Iter, Sent>(1);
test_iter_comp<Iter, Sent>(2);
test_iter_comp<Iter, Sent>(3);
test_iter_comp<Iter, Sent>(10);
test_iter_comp<Iter, Sent>(1000);
}
struct S
{
int i;
};
}
int main()
{
test_iter<ForwardIterator<const int*> >();
test_iter<BidirectionalIterator<const int*> >();
test_iter<RandomAccessIterator<const int*> >();
test_iter<const int*>();
test_iter<ForwardIterator<const int*>, Sentinel<const int*>>();
test_iter<BidirectionalIterator<const int*>, Sentinel<const int*>>();
test_iter<RandomAccessIterator<const int*>, Sentinel<const int*>>();
test_iter_comp<ForwardIterator<const int*> >();
test_iter_comp<BidirectionalIterator<const int*> >();
test_iter_comp<RandomAccessIterator<const int*> >();
test_iter_comp<const int*>();
test_iter_comp<ForwardIterator<const int*>, Sentinel<const int*>>();
test_iter_comp<BidirectionalIterator<const int*>, Sentinel<const int*>>();
test_iter_comp<RandomAccessIterator<const int*>, Sentinel<const int*>>();
// Works with projections?
S s[] = {S{1},S{2},S{3},S{4},S{-4},S{5},S{6},S{7},S{8},S{9}};
S const *ps = ranges::min_element(s, std::less<int>{}, &S::i);
CHECK(ps->i == -4);
{
constexpr auto a = test::array<int, 10>{{1, 2, 3, 4, -4, 5, 6, 7, 8, 9}};
STATIC_CHECK(ranges::min_element(a) == ranges::begin(a) + 4);
}
return test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/copy.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#include <vector>
#include <sstream>
#include <cstring>
#include <utility>
#include <algorithm>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/copy.hpp>
#include <range/v3/algorithm/equal.hpp>
#include <range/v3/view/delimit.hpp>
#include <range/v3/iterator/stream_iterators.hpp>
#include "../array.hpp"
#include "../simple_test.hpp"
#include "../test_iterators.hpp"
#if RANGES_CXX_CONSTEXPR >= RANGES_CXX_CONSTEXPR_14 && RANGES_CONSTEXPR_INVOKE
constexpr /*c++14*/
bool test_constexpr_copy()
{
int a[4] = {0, 0, 0, 0};
int const b[4] = {1, 2, 3, 4};
ranges::copy(b, a);
return ranges::equal(b, a);
}
static_assert(test_constexpr_copy(), "");
#endif
constexpr bool test_constexpr()
{
using IL = std::initializer_list<int>;
constexpr test::array<int, 4> input{{0, 1, 2, 3}};
test::array<int, 4> tmp{{0, 0, 0, 0}};
auto res = ranges::copy(input, ranges::begin(tmp));
STATIC_CHECK_RETURN(res.in == ranges::end(input));
STATIC_CHECK_RETURN(res.out == ranges::end(tmp));
STATIC_CHECK_RETURN(ranges::equal(tmp, IL{0, 1, 2, 3}));
return true;
}
int main()
{
using ranges::begin;
using ranges::end;
using ranges::size;
std::pair<int, int> const a[] = {{0, 0}, {0, 1}, {1, 2}, {1, 3}, {3, 4}, {3, 5}};
static_assert(size(a) == 6, "");
std::pair<int, int> out[size(a)] = {};
auto res = ranges::copy(begin(a), end(a), out);
CHECK(res.in == end(a));
CHECK(res.out == out + size(out));
CHECK(std::equal(a, a + size(a), out));
std::fill_n(out, size(out), std::make_pair(0, 0));
CHECK(!std::equal(a, a + size(a), out));
res = ranges::copy(a, out);
CHECK(res.in == a + size(a));
CHECK(res.out == out + size(out));
CHECK(std::equal(a, a + size(a), out));
std::fill_n(out, size(out), std::make_pair(0, 0));
using ranges::views::delimit;
{
char const *sz = "hello world";
char buf[50];
auto str = delimit(sz, '\0');
auto res3 = ranges::copy(str, buf);
*res3.out = '\0';
CHECK(res3.in == std::next(begin(str), static_cast<std::ptrdiff_t>(std::strlen(sz))));
CHECK(res3.out == buf + std::strlen(sz));
CHECK(std::strcmp(sz, buf) == 0);
}
{
char const *sz = "hello world";
char buf[50];
auto str = delimit(sz, '\0');
auto res3 = ranges::copy(std::move(str), buf);
*res3.out = '\0';
CHECK(!::is_dangling(res3.in));
CHECK(res3.out == buf + std::strlen(sz));
CHECK(std::strcmp(sz, buf) == 0);
}
{
using namespace ranges;
std::ostringstream sout;
std::vector<int> copy_vec{1,1,1,1,1};
copy(copy_vec, ostream_iterator<>(sout, " "));
CHECK(sout.str() == "1 1 1 1 1 ");
}
{
STATIC_CHECK(test_constexpr());
}
return test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/includes.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <functional>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/set_algorithm.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
RANGES_DIAGNOSTIC_IGNORE_GLOBAL_CONSTRUCTORS
namespace
{
auto const true_ = [](bool b){CHECK(b);};
auto const false_ = [](bool b){CHECK(!b);};
template<class Iter1, class Iter2>
void
test_iter()
{
int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4};
const unsigned sa = sizeof(ia)/sizeof(ia[0]);
int ib[] = {2, 4};
const unsigned sb = sizeof(ib)/sizeof(ib[0]);
int ic[] = {1, 2};
int id[] = {3, 3, 3, 3};
auto includes = make_testable_2<true, true>(ranges::includes);
includes(Iter1(ia), Iter1(ia), Iter2(ib), Iter2(ib)).check(true_);
includes(Iter1(ia), Iter1(ia), Iter2(ib), Iter2(ib+1)).check(false_);
includes(Iter1(ia), Iter1(ia+1), Iter2(ib), Iter2(ib)).check(true_);
includes(Iter1(ia), Iter1(ia+sa), Iter2(ia), Iter2(ia+sa)).check(true_);
includes(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+sb)).check(true_);
includes(Iter1(ib), Iter1(ib+sb), Iter2(ia), Iter2(ia+sa)).check(false_);
includes(Iter1(ia), Iter1(ia+2), Iter2(ic), Iter2(ic+2)).check(true_);
includes(Iter1(ia), Iter1(ia+2), Iter2(ib), Iter2(ib+2)).check(false_);
includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+1)).check(true_);
includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+2)).check(true_);
includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+3)).check(true_);
includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+4)).check(false_);
}
template<class Iter1, class Iter2>
void
test_comp()
{
int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4};
const unsigned sa = sizeof(ia)/sizeof(ia[0]);
int ib[] = {2, 4};
const unsigned sb = sizeof(ib)/sizeof(ib[0]);
int ic[] = {1, 2};
int id[] = {3, 3, 3, 3};
auto includes = make_testable_2<true, true>(ranges::includes);
includes(Iter1(ia), Iter1(ia), Iter2(ib), Iter2(ib), std::less<int>()).check(true_);
includes(Iter1(ia), Iter1(ia), Iter2(ib), Iter2(ib+1), std::less<int>()).check(false_);
includes(Iter1(ia), Iter1(ia+1), Iter2(ib), Iter2(ib), std::less<int>()).check(true_);
includes(Iter1(ia), Iter1(ia+sa), Iter2(ia), Iter2(ia+sa), std::less<int>()).check(true_);
includes(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+sb), std::less<int>()).check(true_);
includes(Iter1(ib), Iter1(ib+sb), Iter2(ia), Iter2(ia+sa), std::less<int>()).check(false_);
includes(Iter1(ia), Iter1(ia+2), Iter2(ic), Iter2(ic+2), std::less<int>()).check(true_);
includes(Iter1(ia), Iter1(ia+2), Iter2(ib), Iter2(ib+2), std::less<int>()).check(false_);
includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+1), std::less<int>()).check(true_);
includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+2), std::less<int>()).check(true_);
includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+3), std::less<int>()).check(true_);
includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+4), std::less<int>()).check(false_);
}
template<class Iter1, class Iter2>
void test()
{
test_iter<Iter1, Iter2>();
test_comp<Iter1, Iter2>();
}
struct S
{
int i;
};
struct T
{
int j;
};
}
int main()
{
test<InputIterator<const int*>, InputIterator<const int*> >();
test<InputIterator<const int*>, ForwardIterator<const int*> >();
test<InputIterator<const int*>, BidirectionalIterator<const int*> >();
test<InputIterator<const int*>, RandomAccessIterator<const int*> >();
test<InputIterator<const int*>, const int*>();
test<ForwardIterator<const int*>, InputIterator<const int*> >();
test<ForwardIterator<const int*>, ForwardIterator<const int*> >();
test<ForwardIterator<const int*>, BidirectionalIterator<const int*> >();
test<ForwardIterator<const int*>, RandomAccessIterator<const int*> >();
test<ForwardIterator<const int*>, const int*>();
test<BidirectionalIterator<const int*>, InputIterator<const int*> >();
test<BidirectionalIterator<const int*>, ForwardIterator<const int*> >();
test<BidirectionalIterator<const int*>, BidirectionalIterator<const int*> >();
test<BidirectionalIterator<const int*>, RandomAccessIterator<const int*> >();
test<BidirectionalIterator<const int*>, const int*>();
test<RandomAccessIterator<const int*>, InputIterator<const int*> >();
test<RandomAccessIterator<const int*>, ForwardIterator<const int*> >();
test<RandomAccessIterator<const int*>, BidirectionalIterator<const int*> >();
test<RandomAccessIterator<const int*>, RandomAccessIterator<const int*> >();
test<RandomAccessIterator<const int*>, const int*>();
test<const int*, InputIterator<const int*> >();
test<const int*, ForwardIterator<const int*> >();
test<const int*, BidirectionalIterator<const int*> >();
test<const int*, RandomAccessIterator<const int*> >();
test<const int*, const int*>();
// Test projections
{
S ia[] = {{1}, {2}, {2}, {3}, {3}, {3}, {4}, {4}, {4}, {4}};
T id[] = {{3}, {3}, {3}};
CHECK(ranges::includes(ia, id, std::less<int>(), &S::i, &T::j));
}
{
using IL = std::initializer_list<int>;
STATIC_CHECK(ranges::includes(
IL{1, 2, 2, 3, 3, 3, 4, 4, 4, 4}, IL{3, 3, 3}, std::less<int>()));
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/min.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
// Copyright Casey Carter 2015
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <range/v3/algorithm/min.hpp>
#include <range/v3/view/subrange.hpp>
#include <memory>
#include <random>
#include <numeric>
#include <algorithm>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
RANGES_DIAGNOSTIC_IGNORE_GLOBAL_CONSTRUCTORS
namespace
{
std::mt19937 gen;
template<class Iter, class Sent = Iter>
void
test_iter(Iter first, Sent last)
{
RANGES_ENSURE(first != last);
auto rng = ranges::make_subrange(first, last);
auto v1 = ranges::min(rng);
for (Iter i = first; i != last; ++i)
CHECK(!(*i < v1));
}
template<class Iter, class Sent = Iter>
void
test_iter(unsigned N)
{
RANGES_ENSURE(N > 0);
std::unique_ptr<int[]> a{new int[N]};
std::iota(a.get(), a.get()+N, 0);
std::shuffle(a.get(), a.get()+N, gen);
test_iter(Iter(a.get()), Sent(a.get()+N));
}
template<class Iter, class Sent = Iter>
void
test_iter()
{
test_iter<Iter, Sent>(1);
test_iter<Iter, Sent>(2);
test_iter<Iter, Sent>(3);
test_iter<Iter, Sent>(10);
test_iter<Iter, Sent>(1000);
}
template<class Iter, class Sent = Iter>
void
test_iter_comp(Iter first, Sent last)
{
RANGES_ENSURE(first != last);
auto rng = ranges::make_subrange(first, last);
auto v = ranges::min(rng, std::greater<int>());
for (Iter i = first; i != last; ++i)
CHECK(!std::greater<int>()(*i, v));
}
template<class Iter, class Sent = Iter>
void
test_iter_comp(unsigned N)
{
RANGES_ENSURE(N > 0);
std::unique_ptr<int[]> a{new int[N]};
std::iota(a.get(), a.get()+N, 0);
std::shuffle(a.get(), a.get()+N, gen);
test_iter_comp(Iter(a.get()), Sent(a.get()+N));
}
template<class Iter, class Sent = Iter>
void
test_iter_comp()
{
test_iter_comp<Iter, Sent>(1);
test_iter_comp<Iter, Sent>(2);
test_iter_comp<Iter, Sent>(3);
test_iter_comp<Iter, Sent>(10);
test_iter_comp<Iter, Sent>(1000);
}
struct S
{
int i;
};
}
int main()
{
test_iter<InputIterator<const int*> >();
test_iter<ForwardIterator<const int*> >();
test_iter<BidirectionalIterator<const int*> >();
test_iter<RandomAccessIterator<const int*> >();
test_iter<const int*>();
test_iter<InputIterator<const int*>, Sentinel<const int*>>();
test_iter<ForwardIterator<const int*>, Sentinel<const int*>>();
test_iter<BidirectionalIterator<const int*>, Sentinel<const int*>>();
test_iter<RandomAccessIterator<const int*>, Sentinel<const int*>>();
test_iter_comp<InputIterator<const int*> >();
test_iter_comp<ForwardIterator<const int*> >();
test_iter_comp<BidirectionalIterator<const int*> >();
test_iter_comp<RandomAccessIterator<const int*> >();
test_iter_comp<const int*>();
test_iter_comp<InputIterator<const int*>, Sentinel<const int*>>();
test_iter_comp<ForwardIterator<const int*>, Sentinel<const int*>>();
test_iter_comp<BidirectionalIterator<const int*>, Sentinel<const int*>>();
test_iter_comp<RandomAccessIterator<const int*>, Sentinel<const int*>>();
// Works with projections?
S s[] = {S{1},S{2},S{3},S{4},S{-4},S{5},S{6},S{7},S{8},S{9}};
S v = ranges::min(s, std::less<int>{}, &S::i);
CHECK(v.i == -4);
// Works with initializer_lists? (Regression test for #1004)
CHECK(ranges::min({4,3,1,2,6,5}) == 1);
return test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/is_heap_until2.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#define IS_HEAP_UNTIL_2
#include "./is_heap_until.hpp"
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/is_partitioned.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright 2005 - 2007 Adobe Systems Incorporated
// Distributed under the MIT License(see accompanying file LICENSE_1_0_0.txt
// or a copy at http://stlab.adobe.com/licenses.html)
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <memory>
#include <utility>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/is_partitioned.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
struct is_odd
{
constexpr bool operator()(const int & i) const
{
return i & 1;
}
};
template<class Iter, class Sent = Iter>
void
test_iter()
{
{
const int ia[] = {1, 2, 3, 4, 5, 6};
CHECK(!ranges::is_partitioned(Iter(ranges::begin(ia)),
Sent(ranges::end(ia)),
is_odd()));
}
{
const int ia[] = {1, 3, 5, 2, 4, 6};
CHECK( ranges::is_partitioned(Iter(ranges::begin(ia)),
Sent(ranges::end(ia)),
is_odd()));
}
{
const int ia[] = {2, 4, 6, 1, 3, 5};
CHECK(!ranges::is_partitioned(Iter(ranges::begin(ia)),
Sent(ranges::end(ia)),
is_odd()));
}
{
const int ia[] = {1, 3, 5, 2, 4, 6, 7};
CHECK(!ranges::is_partitioned(Iter(ranges::begin(ia)),
Sent(ranges::end(ia)),
is_odd()));
}
{
const int ia[] = {1, 3, 5, 2, 4, 6, 7};
CHECK( ranges::is_partitioned(Iter(ranges::begin(ia)),
Sent(ranges::begin(ia)),
is_odd()));
}
}
template<class Iter, class Sent = Iter>
void
test_range()
{
{
const int ia[] = {1, 2, 3, 4, 5, 6};
CHECK(!ranges::is_partitioned(ranges::make_subrange(Iter(ranges::begin(ia)),
Sent(ranges::end(ia))),
is_odd()));
}
{
const int ia[] = {1, 3, 5, 2, 4, 6};
CHECK( ranges::is_partitioned(ranges::make_subrange(Iter(ranges::begin(ia)),
Sent(ranges::end(ia))),
is_odd()));
}
{
const int ia[] = {2, 4, 6, 1, 3, 5};
CHECK(!ranges::is_partitioned(ranges::make_subrange(Iter(ranges::begin(ia)),
Sent(ranges::end(ia))),
is_odd()));
}
{
const int ia[] = {1, 3, 5, 2, 4, 6, 7};
CHECK(!ranges::is_partitioned(ranges::make_subrange(Iter(ranges::begin(ia)),
Sent(ranges::end(ia))),
is_odd()));
}
{
const int ia[] = {1, 3, 5, 2, 4, 6, 7};
CHECK( ranges::is_partitioned(ranges::make_subrange(Iter(ranges::begin(ia)),
Sent(ranges::begin(ia))),
is_odd()));
}
}
struct S
{
int i;
};
int main()
{
test_iter<InputIterator<const int*> >();
test_iter<InputIterator<const int*>, Sentinel<const int*>>();
test_range<InputIterator<const int*> >();
test_range<InputIterator<const int*>, Sentinel<const int*>>();
// Test projections
const S ia[] = {S{1}, S{3}, S{5}, S{2}, S{4}, S{6}};
CHECK( ranges::is_partitioned(ia, is_odd(), &S::i) );
{
using IL = std::initializer_list<int>;
STATIC_CHECK(ranges::is_partitioned(IL{1, 3, 5, 2, 4, 6}, is_odd()));
STATIC_CHECK(!ranges::is_partitioned(IL{1, 3, 1, 2, 5, 6}, is_odd()));
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/binary_search.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright 2005 - 2007 Adobe Systems Incorporated
// Distributed under the MIT License(see accompanying file LICENSE_1_0_0.txt
// or a copy at http://stlab.adobe.com/licenses.html)
#include <utility>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/binary_search.hpp>
#include "../simple_test.hpp"
int main()
{
using ranges::begin;
using ranges::end;
using ranges::size;
using ranges::less;
constexpr std::pair<int, int> a[] = {{0, 0}, {0, 1}, {1, 2}, {1, 3}, {3, 4}, {3, 5}};
constexpr const std::pair<int, int> c[] = {
{0, 0}, {0, 1}, {1, 2}, {1, 3}, {3, 4}, {3, 5}};
CHECK(ranges::binary_search(begin(a), end(a), a[0]));
CHECK(ranges::binary_search(begin(a), end(a), a[1], less()));
CHECK(ranges::binary_search(begin(a), end(a), 1, less(), &std::pair<int, int>::first));
CHECK(ranges::binary_search(a, a[2]));
CHECK(ranges::binary_search(c, c[3]));
CHECK(ranges::binary_search(a, a[4], less()));
CHECK(ranges::binary_search(c, c[5], less()));
CHECK(ranges::binary_search(a, 1, less(), &std::pair<int, int>::first));
CHECK(ranges::binary_search(c, 1, less(), &std::pair<int, int>::first));
CHECK(ranges::binary_search(a, 0, less(), &std::pair<int, int>::first));
CHECK(ranges::binary_search(c, 0, less(), &std::pair<int, int>::first));
CHECK(!ranges::binary_search(a, -1, less(), &std::pair<int, int>::first));
CHECK(!ranges::binary_search(c, -1, less(), &std::pair<int, int>::first));
CHECK(!ranges::binary_search(a, 4, less(), &std::pair<int, int>::first));
CHECK(!ranges::binary_search(c, 4, less(), &std::pair<int, int>::first));
STATIC_CHECK(ranges::binary_search(begin(a), end(a), a[0]));
STATIC_CHECK(ranges::binary_search(begin(a), end(a), a[1], less()));
STATIC_CHECK(ranges::binary_search(a, a[2]));
STATIC_CHECK(ranges::binary_search(a, a[4], less()));
STATIC_CHECK(!ranges::binary_search(a, std::make_pair(-1, -1), less()));
return test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/inplace_merge.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <algorithm>
#include <random>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/inplace_merge.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
RANGES_DIAGNOSTIC_IGNORE_GLOBAL_CONSTRUCTORS
RANGES_DIAGNOSTIC_IGNORE_SIGN_CONVERSION
namespace
{
std::mt19937 gen;
template<class Iter, typename Sent = Iter>
void
test_one_iter(unsigned N, unsigned M)
{
RANGES_ENSURE(M <= N);
int* ia = new int[N];
for (unsigned i = 0; i < N; ++i)
ia[i] = i;
std::shuffle(ia, ia+N, gen);
std::sort(ia, ia+M);
std::sort(ia+M, ia+N);
auto res = ranges::inplace_merge(Iter(ia), Iter(ia+M), Sent(ia+N));
CHECK(res == Iter(ia+N));
if(N > 0)
{
CHECK(ia[0] == 0);
CHECK(ia[N-1] == (int)N-1);
CHECK(std::is_sorted(ia, ia+N));
}
delete [] ia;
}
template<class Iter, typename Sent = Iter>
void
test_one_rng(unsigned N, unsigned M)
{
RANGES_ENSURE(M <= N);
int* ia = new int[N];
for (unsigned i = 0; i < N; ++i)
ia[i] = i;
std::shuffle(ia, ia+N, gen);
std::sort(ia, ia+M);
std::sort(ia+M, ia+N);
auto res = ranges::inplace_merge(ranges::make_subrange(Iter(ia), Sent(ia+N)), Iter(ia+M));
CHECK(res == Iter(ia+N));
if(N > 0)
{
CHECK(ia[0] == 0);
CHECK(ia[N-1] == (int)N-1);
CHECK(std::is_sorted(ia, ia+N));
}
std::shuffle(ia, ia+N, gen);
std::sort(ia, ia+M);
std::sort(ia+M, ia+N);
auto res2 = ranges::inplace_merge(::MakeTestRange(Iter(ia), Sent(ia+N)), Iter(ia+M));
CHECK(::is_dangling(res2));
if(N > 0)
{
CHECK(ia[0] == 0);
CHECK(ia[N-1] == (int)N-1);
CHECK(std::is_sorted(ia, ia+N));
}
delete [] ia;
}
template<class Iter>
void
test_one(unsigned N, unsigned M)
{
test_one_iter<Iter>(N, M);
test_one_iter<Iter, typename sentinel_type<Iter>::type>(N, M);
test_one_rng<Iter>(N, M);
test_one_rng<Iter, typename sentinel_type<Iter>::type>(N, M);
}
template<class Iter>
void
test(unsigned N)
{
test_one<Iter>(N, 0);
test_one<Iter>(N, N/4);
test_one<Iter>(N, N/2);
test_one<Iter>(N, 3*N/4);
test_one<Iter>(N, N);
}
template<class Iter>
void
test()
{
test_one<Iter>(0, 0);
test_one<Iter>(1, 0);
test_one<Iter>(1, 1);
test_one<Iter>(2, 0);
test_one<Iter>(2, 1);
test_one<Iter>(2, 2);
test_one<Iter>(3, 0);
test_one<Iter>(3, 1);
test_one<Iter>(3, 2);
test_one<Iter>(3, 3);
test<Iter>(4);
test<Iter>(100);
test<Iter>(1000);
}
}
int main()
{
// test<ForwardIterator<int*> >();
test<BidirectionalIterator<int*> >();
test<RandomAccessIterator<int*> >();
test<int*>();
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/generate_n.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <vector>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/generate_n.hpp>
#include <range/v3/iterator/insert_iterators.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
struct gen_test
{
int i_;
constexpr gen_test()
: i_{}
{}
constexpr gen_test(int i)
: i_(i)
{}
constexpr int operator()()
{
return i_++;
}
};
template<class Iter, class Sent = Iter>
void
test()
{
const unsigned n = 4;
int ia[n] = {0};
ranges::generate_n_result<Iter, gen_test> res = ranges::generate_n(Iter(ia), n, gen_test(1));
CHECK(ia[0] == 1);
CHECK(ia[1] == 2);
CHECK(ia[2] == 3);
CHECK(ia[3] == 4);
CHECK(res.out == Iter(ia + n));
CHECK(res.fun.i_ == 5);
}
void test2()
{
// Test ranges::generate with a genuine output range
std::vector<int> v;
ranges::generate_n(ranges::back_inserter(v), 5, gen_test(1));
CHECK(v.size() == 5u);
CHECK(v[0] == 1);
CHECK(v[1] == 2);
CHECK(v[2] == 3);
CHECK(v[3] == 4);
CHECK(v[4] == 5);
}
template<class Iter, class Sent = Iter>
constexpr bool test_constexpr()
{
bool r = true;
const unsigned n = 4;
int ia[n] = {0};
const auto res = ranges::generate_n(Iter(ia), n, gen_test(1));
if(ia[0] != 1)
{
r = false;
}
if(ia[1] != 2)
{
r = false;
}
if(ia[2] != 3)
{
r = false;
}
if(ia[3] != 4)
{
r = false;
}
if(res.out != Iter(ia + n))
{
r = false;
}
if(res.fun.i_ != 5)
{
r = false;
}
return r;
}
int main()
{
test<ForwardIterator<int*> >();
test<BidirectionalIterator<int*> >();
test<RandomAccessIterator<int*> >();
test<int*>();
test<ForwardIterator<int*>, Sentinel<int*> >();
test<BidirectionalIterator<int*>, Sentinel<int*> >();
test<RandomAccessIterator<int*>, Sentinel<int*> >();
test2();
{
STATIC_CHECK(test_constexpr<ForwardIterator<int *>>());
STATIC_CHECK(test_constexpr<BidirectionalIterator<int *>>());
STATIC_CHECK(test_constexpr<RandomAccessIterator<int *>>());
STATIC_CHECK(test_constexpr<int *>());
STATIC_CHECK(test_constexpr<ForwardIterator<int *>, Sentinel<int *>>());
STATIC_CHECK(test_constexpr<BidirectionalIterator<int *>, Sentinel<int *>>());
STATIC_CHECK(test_constexpr<RandomAccessIterator<int *>, Sentinel<int *>>());
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/set_difference4.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#define SET_DIFFERENCE_4
#include "./set_difference.hpp"
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/set_intersection4.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#define SET_INTERSECTION_4
#include "./set_intersection.hpp"
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/pop_heap.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright 2005 - 2007 Adobe Systems Incorporated
// Distributed under the MIT License(see accompanying file LICENSE_1_0_0.txt
// or a copy at http://stlab.adobe.com/licenses.html)
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <memory>
#include <random>
#include <algorithm>
#include <functional>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/heap_algorithm.hpp>
#include "../array.hpp"
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
RANGES_DIAGNOSTIC_IGNORE_GLOBAL_CONSTRUCTORS
RANGES_DIAGNOSTIC_IGNORE_SIGN_CONVERSION
namespace
{
std::mt19937 gen;
void test_1(int N)
{
int* ia = new int[N];
for (int i = 0; i < N; ++i)
ia[i] = i;
std::shuffle(ia, ia+N, gen);
std::make_heap(ia, ia+N);
for (int i = N; i > 0; --i)
{
CHECK(ranges::pop_heap(ia, ia+i) == ia+i);
CHECK(std::is_heap(ia, ia+i-1));
}
CHECK(ranges::pop_heap(ia, ia) == ia);
delete[] ia;
}
void test_2(int N)
{
int* ia = new int[N];
for (int i = 0; i < N; ++i)
ia[i] = i;
std::shuffle(ia, ia+N, gen);
std::make_heap(ia, ia+N);
for (int i = N; i > 0; --i)
{
CHECK(ranges::pop_heap(ia, Sentinel<int*>(ia+i)) == ia+i);
CHECK(std::is_heap(ia, ia+i-1));
}
CHECK(ranges::pop_heap(ia, ia) == ia);
delete[] ia;
}
void test_3(int N)
{
int* ia = new int[N];
for (int i = 0; i < N; ++i)
ia[i] = i;
std::shuffle(ia, ia+N, gen);
std::make_heap(ia, ia+N);
for (int i = N; i > 0; --i)
{
CHECK(ranges::pop_heap(::as_lvalue(ranges::make_subrange(ia, ia+i))) == ia+i);
CHECK(std::is_heap(ia, ia+i-1));
}
std::shuffle(ia, ia+N, gen);
std::make_heap(ia, ia+N);
for (int i = N; i > 0; --i)
{
CHECK(ranges::pop_heap(ranges::make_subrange(ia, ia+i)) == ia+i);
CHECK(std::is_heap(ia, ia+i-1));
}
CHECK(ranges::pop_heap(ia, ia) == ia);
delete[] ia;
}
void test_4(int N)
{
int* ia = new int[N];
for (int i = 0; i < N; ++i)
ia[i] = i;
std::shuffle(ia, ia+N, gen);
std::make_heap(ia, ia+N);
for (int i = N; i > 0; --i)
{
CHECK(ranges::pop_heap(::as_lvalue(ranges::make_subrange(ia, Sentinel<int*>(ia+i)))) == ia+i);
CHECK(std::is_heap(ia, ia+i-1));
}
std::shuffle(ia, ia+N, gen);
std::make_heap(ia, ia+N);
for (int i = N; i > 0; --i)
{
CHECK(ranges::pop_heap(ranges::make_subrange(ia, Sentinel<int*>(ia+i))) == ia+i);
CHECK(std::is_heap(ia, ia+i-1));
}
CHECK(ranges::pop_heap(ia, ia) == ia);
delete[] ia;
}
void test_5(int N)
{
int* ia = new int[N];
for (int i = 0; i < N; ++i)
ia[i] = i;
std::shuffle(ia, ia+N, gen);
std::make_heap(ia, ia+N, std::greater<int>());
for (int i = N; i > 0; --i)
{
CHECK(ranges::pop_heap(ia, ia+i, std::greater<int>()) == ia+i);
CHECK(std::is_heap(ia, ia+i-1, std::greater<int>()));
}
CHECK(ranges::pop_heap(ia, ia, std::greater<int>()) == ia);
delete[] ia;
}
void test_6(int N)
{
int* ia = new int[N];
for (int i = 0; i < N; ++i)
ia[i] = i;
std::shuffle(ia, ia+N, gen);
std::make_heap(ia, ia+N, std::greater<int>());
for (int i = N; i > 0; --i)
{
CHECK(ranges::pop_heap(ia, Sentinel<int*>(ia+i), std::greater<int>()) == ia+i);
CHECK(std::is_heap(ia, ia+i-1, std::greater<int>()));
}
CHECK(ranges::pop_heap(ia, Sentinel<int*>(ia), std::greater<int>()) == ia);
delete[] ia;
}
void test_7(int N)
{
int* ia = new int[N];
for (int i = 0; i < N; ++i)
ia[i] = i;
std::shuffle(ia, ia+N, gen);
std::make_heap(ia, ia+N, std::greater<int>());
for (int i = N; i > 0; --i)
{
CHECK(ranges::pop_heap(::as_lvalue(ranges::make_subrange(ia, ia+i)), std::greater<int>()) == ia+i);
CHECK(std::is_heap(ia, ia+i-1, std::greater<int>()));
}
std::shuffle(ia, ia+N, gen);
std::make_heap(ia, ia+N, std::greater<int>());
for (int i = N; i > 0; --i)
{
CHECK(ranges::pop_heap(ranges::make_subrange(ia, ia+i), std::greater<int>()) == ia+i);
CHECK(std::is_heap(ia, ia+i-1, std::greater<int>()));
}
CHECK(ranges::pop_heap(ia, ia, std::greater<int>()) == ia);
delete[] ia;
}
void test_8(int N)
{
int* ia = new int[N];
for (int i = 0; i < N; ++i)
ia[i] = i;
std::shuffle(ia, ia+N, gen);
std::make_heap(ia, ia+N, std::greater<int>());
for (int i = N; i > 0; --i)
{
CHECK(ranges::pop_heap(::as_lvalue(ranges::make_subrange(ia, Sentinel<int*>(ia+i))), std::greater<int>()) == ia+i);
CHECK(std::is_heap(ia, ia+i-1, std::greater<int>()));
}
std::shuffle(ia, ia+N, gen);
std::make_heap(ia, ia+N, std::greater<int>());
for (int i = N; i > 0; --i)
{
CHECK(ranges::pop_heap(ranges::make_subrange(ia, Sentinel<int*>(ia+i)), std::greater<int>()) == ia+i);
CHECK(std::is_heap(ia, ia+i-1, std::greater<int>()));
}
CHECK(ranges::pop_heap(ia, Sentinel<int*>(ia), std::greater<int>()) == ia);
delete[] ia;
}
struct indirect_less
{
template<class P>
bool operator()(const P& x, const P& y)
{return *x < *y;}
};
void test_9(int N)
{
std::unique_ptr<int>* ia = new std::unique_ptr<int>[N];
for (int i = 0; i < N; ++i)
ia[i].reset(new int(i));
std::shuffle(ia, ia+N, gen);
std::make_heap(ia, ia+N, indirect_less());
for (int i = N; i > 0; --i)
{
CHECK(ranges::pop_heap(ia, ia+i, indirect_less()) == ia+i);
CHECK(std::is_heap(ia, ia+i-1, indirect_less()));
}
delete[] ia;
}
template<typename T>
struct construct
{
template<typename ...Us>
T operator()(Us &&... us) const
{
return T{((Us &&)us)...};
}
};
struct S
{
int i;
};
void test_10(int N)
{
int* ia = new int[N];
S* ib = new S[N];
for (int i = 0; i < N; ++i)
ia[i] = i;
std::shuffle(ia, ia+N, gen);
std::make_heap(ia, ia+N);
std::transform(ia, ia+N, ib, construct<S>());
for (int i = N; i > 0; --i)
{
CHECK(ranges::pop_heap(ib, ib+i, std::less<int>(), &S::i) == ib+i);
std::transform(ib, ib+i, ia, std::mem_fn(&S::i));
CHECK(std::is_heap(ia, ia+i-1));
}
CHECK(ranges::pop_heap(ib, ib, std::less<int>(), &S::i) == ib);
delete[] ia;
delete[] ib;
}
}
constexpr bool test_constexpr()
{
using namespace ranges;
constexpr int N = 100;
test::array<int, N> ia{{0}};
for(int i = 0; i < N; ++i)
ia[i] = i;
make_heap(ia);
for(int i = N; i > 0; --i)
{
STATIC_CHECK_RETURN(pop_heap(make_subrange(begin(ia), begin(ia) + i), less{}) == begin(ia) + i);
STATIC_CHECK_RETURN(is_heap(begin(ia), begin(ia) + i - 1));
}
STATIC_CHECK_RETURN(pop_heap(make_subrange(begin(ia), begin(ia)), less{}) == begin(ia));
return true;
}
int main()
{
test_1(1000);
test_2(1000);
test_3(1000);
test_4(1000);
test_5(1000);
test_6(1000);
test_7(1000);
test_8(1000);
test_9(1000);
test_10(1000);
{
STATIC_CHECK(test_constexpr());
}
return test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/replace_copy_if.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright 2005 - 2007 Adobe Systems Incorporated
// Distributed under the MIT License(see accompanying file LICENSE_1_0_0.txt
// or a copy at http://stlab.adobe.com/licenses.html)
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <utility>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/replace_copy_if.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
template<class InIter, class OutIter, class Sent = InIter>
void test_iter()
{
int ia[] = {0, 1, 2, 3, 4};
const unsigned sa = sizeof(ia)/sizeof(ia[0]);
int ib[sa] = {0};
ranges::replace_copy_if_result<InIter, OutIter> r = ranges::replace_copy_if(InIter(ia), Sent(ia+sa), OutIter(ib),
[](int i){return 2==i;}, 5);
CHECK(base(r.in) == ia + sa);
CHECK(base(r.out) == ib + sa);
CHECK(ib[0] == 0);
CHECK(ib[1] == 1);
CHECK(ib[2] == 5);
CHECK(ib[3] == 3);
CHECK(ib[4] == 4);
}
template<class InIter, class OutIter, class Sent = InIter>
void test_rng()
{
int ia[] = {0, 1, 2, 3, 4};
const unsigned sa = sizeof(ia)/sizeof(ia[0]);
int ib[sa] = {0};
auto rng = ranges::make_subrange(InIter(ia), Sent(ia+sa));
ranges::replace_copy_if_result<InIter, OutIter> r = ranges::replace_copy_if(rng, OutIter(ib),
[](int i){return 2==i;}, 5);
CHECK(base(r.in) == ia + sa);
CHECK(base(r.out) == ib + sa);
CHECK(ib[0] == 0);
CHECK(ib[1] == 1);
CHECK(ib[2] == 5);
CHECK(ib[3] == 3);
CHECK(ib[4] == 4);
}
template<class InIter, class OutIter>
void test()
{
using Sent = typename sentinel_type<InIter>::type;
test_iter<InIter, OutIter>();
test_iter<InIter, OutIter>();
test_rng<InIter, OutIter, Sent>();
test_rng<InIter, OutIter, Sent>();
}
constexpr bool equals_two(int i)
{
return i == 2;
}
constexpr bool test_constexpr()
{
using namespace ranges;
int ia[] = {0, 1, 2, 3, 4};
int ib[5] = {0};
constexpr auto sa = ranges::size(ia);
const auto r = ranges::replace_copy_if(ia, ib, equals_two, 42);
STATIC_CHECK_RETURN(r.in == ia + sa);
STATIC_CHECK_RETURN(r.out == ib + sa);
STATIC_CHECK_RETURN(ib[0] == 0);
STATIC_CHECK_RETURN(ib[1] == 1);
STATIC_CHECK_RETURN(ib[2] == 42);
STATIC_CHECK_RETURN(ib[3] == 3);
STATIC_CHECK_RETURN(ib[4] == 4);
return true;
}
int main()
{
test<InputIterator<const int*>, OutputIterator<int*> >();
test<InputIterator<const int*>, ForwardIterator<int*> >();
test<InputIterator<const int*>, BidirectionalIterator<int*> >();
test<InputIterator<const int*>, RandomAccessIterator<int*> >();
test<InputIterator<const int*>, int*>();
test<ForwardIterator<const int*>, OutputIterator<int*> >();
test<ForwardIterator<const int*>, ForwardIterator<int*> >();
test<ForwardIterator<const int*>, BidirectionalIterator<int*> >();
test<ForwardIterator<const int*>, RandomAccessIterator<int*> >();
test<ForwardIterator<const int*>, int*>();
test<BidirectionalIterator<const int*>, OutputIterator<int*> >();
test<BidirectionalIterator<const int*>, ForwardIterator<int*> >();
test<BidirectionalIterator<const int*>, BidirectionalIterator<int*> >();
test<BidirectionalIterator<const int*>, RandomAccessIterator<int*> >();
test<BidirectionalIterator<const int*>, int*>();
test<RandomAccessIterator<const int*>, OutputIterator<int*> >();
test<RandomAccessIterator<const int*>, ForwardIterator<int*> >();
test<RandomAccessIterator<const int*>, BidirectionalIterator<int*> >();
test<RandomAccessIterator<const int*>, RandomAccessIterator<int*> >();
test<RandomAccessIterator<const int*>, int*>();
test<const int*, OutputIterator<int*> >();
test<const int*, ForwardIterator<int*> >();
test<const int*, BidirectionalIterator<int*> >();
test<const int*, RandomAccessIterator<int*> >();
test<const int*, int*>();
// Test projection
{
using P = std::pair<int, std::string>;
P in[] = {{0, "0"}, {1, "1"}, {2, "2"}, {3, "3"}, {4, "4"}};
P out[ranges::size(in)] = {};
ranges::replace_copy_if_result<P *, P *> r = ranges::replace_copy_if(in, out,
[](int i){return 2==i;}, P{5, "5"}, &std::pair<int, std::string>::first);
CHECK(r.in == ranges::end(in));
CHECK(r.out == ranges::end(out));
CHECK(out[0] == P{0, "0"});
CHECK(out[1] == P{1, "1"});
CHECK(out[2] == P{5, "5"});
CHECK(out[3] == P{3, "3"});
CHECK(out[4] == P{4, "4"});
}
{
STATIC_CHECK(test_constexpr());
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/for_each_n.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
// Copyright Rostislav Khlebnikov 2017
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#include <vector>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/for_each_n.hpp>
#include "../array.hpp"
#include "../simple_test.hpp"
struct S
{
void p() const { *p_ += i_; }
int *p_;
int i_;
};
constexpr bool test_constexpr()
{
// lambda closure types are non-literal types before C++17
struct
{
constexpr void operator()(int i)
{
sum_ += i;
}
int sum_ = 0;
} fun;
constexpr test::array<int, 5> v1{{1, 2, 4, 6}};
STATIC_CHECK_RETURN(ranges::for_each_n(v1.begin(), 2, ranges::ref(fun)) ==
v1.begin() + 2);
STATIC_CHECK_RETURN(ranges::for_each_n(v1, 2, ranges::ref(fun)) == v1.begin() + 2);
STATIC_CHECK_RETURN(fun.sum_ == 3 * 2);
return true;
}
int main()
{
int sum = 0;
auto const fun = [&](int i){ sum += i; };
std::vector<int> v1 { 1, 2, 4, 6 };
CHECK(ranges::for_each_n(v1.begin(), 2, fun) == v1.begin() + 2);
CHECK(ranges::for_each_n(v1, 2, fun) == v1.begin() + 2);
CHECK(sum == 3 * 2);
sum = 0;
auto const rfun = [&](int & i){ sum += i; };
auto const sz = static_cast<int>(v1.size());
CHECK(ranges::for_each_n(v1.begin(), sz, rfun) == v1.end());
CHECK(ranges::for_each_n(v1, sz, rfun) == v1.end());
CHECK(sum == 13 * 2);
sum = 0;
std::vector<S> v2{{&sum, 1}, {&sum, 2}, {&sum, 4}, {&sum, 6}};
CHECK(ranges::for_each_n(v2.begin(), 3, &S::p) == v2.begin() + 3);
CHECK(ranges::for_each_n(v2, 3, &S::p) == v2.begin() + 3);
CHECK(sum == 7 * 2);
sum = 0;
CHECK(ranges::for_each_n(v2.begin(), 4, fun, &S::i_) == v2.begin() + 4);
CHECK(ranges::for_each_n(v2, 4, fun, &S::i_) == v2.begin() + 4);
CHECK(sum == 13 * 2);
STATIC_CHECK(test_constexpr());
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/rotate.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright 2005 - 2007 Adobe Systems Incorporated
// Distributed under the MIT License(see accompanying file LICENSE_1_0_0.txt
// or a copy at http://stlab.adobe.com/licenses.html)
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <utility>
#include <vector>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/rotate.hpp>
#include "../simple_test.hpp"
#include "../test_iterators.hpp"
template<class Iter, class Sent = Iter>
void test()
{
using namespace ranges;
using Res = subrange<Iter>;
int ia[] = {0};
const unsigned sa = sizeof(ia)/sizeof(ia[0]);
Res r = rotate(Iter(ia), Iter(ia), Sent(ia));
CHECK(base(r.begin()) == ia);
CHECK(base(r.end()) == ia);
CHECK(ia[0] == 0);
r = rotate(Iter(ia), Iter(ia), Sent(ia+sa));
CHECK(base(r.begin()) == ia+sa);
CHECK(base(r.end()) == ia+sa);
CHECK(ia[0] == 0);
r = rotate(Iter(ia), Iter(ia+sa), Sent(ia+sa));
CHECK(base(r.begin()) == ia);
CHECK(base(r.end()) == ia+sa);
CHECK(ia[0] == 0);
int ib[] = {0, 1};
const unsigned sb = sizeof(ib)/sizeof(ib[0]);
r = rotate(Iter(ib), Iter(ib), Sent(ib+sb));
CHECK(base(r.begin()) == ib+sb);
CHECK(base(r.end()) == ib+sb);
CHECK(ib[0] == 0);
CHECK(ib[1] == 1);
r = rotate(Iter(ib), Iter(ib+1), Sent(ib+sb));
CHECK(base(r.end()) == ib+sb);
CHECK(base(r.begin()) == ib+1);
CHECK(ib[0] == 1);
CHECK(ib[1] == 0);
r = rotate(Iter(ib), Iter(ib+sb), Sent(ib+sb));
CHECK(base(r.end()) == ib+sb);
CHECK(base(r.begin()) == ib);
CHECK(ib[0] == 1);
CHECK(ib[1] == 0);
int ic[] = {0, 1, 2};
const unsigned sc = sizeof(ic)/sizeof(ic[0]);
r = rotate(Iter(ic), Iter(ic), Sent(ic+sc));
CHECK(base(r.begin()) == ic+sc);
CHECK(base(r.end()) == ic+sc);
CHECK(ic[0] == 0);
CHECK(ic[1] == 1);
CHECK(ic[2] == 2);
r = rotate(Iter(ic), Iter(ic+1), Sent(ic+sc));
CHECK(base(r.begin()) == ic+2);
CHECK(base(r.end()) == ic+sc);
CHECK(ic[0] == 1);
CHECK(ic[1] == 2);
CHECK(ic[2] == 0);
r = rotate(Iter(ic), Iter(ic+2), Sent(ic+sc));
CHECK(base(r.begin()) == ic+1);
CHECK(base(r.end()) == ic+sc);
CHECK(ic[0] == 0);
CHECK(ic[1] == 1);
CHECK(ic[2] == 2);
r = rotate(Iter(ic), Iter(ic+sc), Sent(ic+sc));
CHECK(base(r.begin()) == ic);
CHECK(base(r.end()) == ic+sc);
CHECK(ic[0] == 0);
CHECK(ic[1] == 1);
CHECK(ic[2] == 2);
int id[] = {0, 1, 2, 3};
const unsigned sd = sizeof(id)/sizeof(id[0]);
r = rotate(Iter(id), Iter(id), Sent(id+sd));
CHECK(base(r.begin()) == id+sd);
CHECK(base(r.end()) == id+sd);
CHECK(id[0] == 0);
CHECK(id[1] == 1);
CHECK(id[2] == 2);
CHECK(id[3] == 3);
r = rotate(Iter(id), Iter(id+1), Sent(id+sd));
CHECK(base(r.begin()) == id+3);
CHECK(base(r.end()) == id+sd);
CHECK(id[0] == 1);
CHECK(id[1] == 2);
CHECK(id[2] == 3);
CHECK(id[3] == 0);
r = rotate(Iter(id), Iter(id+2), Sent(id+sd));
CHECK(base(r.begin()) == id+2);
CHECK(base(r.end()) == id+sd);
CHECK(id[0] == 3);
CHECK(id[1] == 0);
CHECK(id[2] == 1);
CHECK(id[3] == 2);
r = rotate(Iter(id), Iter(id+3), Sent(id+sd));
CHECK(base(r.begin()) == id+1);
CHECK(base(r.end()) == id+sd);
CHECK(id[0] == 2);
CHECK(id[1] == 3);
CHECK(id[2] == 0);
CHECK(id[3] == 1);
r = rotate(Iter(id), Iter(id+sd), Sent(id+sd));
CHECK(base(r.begin()) == id);
CHECK(base(r.end()) == id+sd);
CHECK(id[0] == 2);
CHECK(id[1] == 3);
CHECK(id[2] == 0);
CHECK(id[3] == 1);
int ie[] = {0, 1, 2, 3, 4};
const unsigned se = sizeof(ie)/sizeof(ie[0]);
r = rotate(Iter(ie), Iter(ie), Sent(ie+se));
CHECK(base(r.begin()) == ie+se);
CHECK(base(r.end()) == ie+se);
CHECK(ie[0] == 0);
CHECK(ie[1] == 1);
CHECK(ie[2] == 2);
CHECK(ie[3] == 3);
CHECK(ie[4] == 4);
r = rotate(Iter(ie), Iter(ie+1), Sent(ie+se));
CHECK(base(r.begin()) == ie+4);
CHECK(base(r.end()) == ie+se);
CHECK(ie[0] == 1);
CHECK(ie[1] == 2);
CHECK(ie[2] == 3);
CHECK(ie[3] == 4);
CHECK(ie[4] == 0);
r = rotate(Iter(ie), Iter(ie+2), Sent(ie+se));
CHECK(base(r.begin()) == ie+3);
CHECK(base(r.end()) == ie+se);
CHECK(ie[0] == 3);
CHECK(ie[1] == 4);
CHECK(ie[2] == 0);
CHECK(ie[3] == 1);
CHECK(ie[4] == 2);
r = rotate(Iter(ie), Iter(ie+3), Sent(ie+se));
CHECK(base(r.begin()) == ie+2);
CHECK(base(r.end()) == ie+se);
CHECK(ie[0] == 1);
CHECK(ie[1] == 2);
CHECK(ie[2] == 3);
CHECK(ie[3] == 4);
CHECK(ie[4] == 0);
r = rotate(Iter(ie), Iter(ie+4), Sent(ie+se));
CHECK(base(r.begin()) == ie+1);
CHECK(base(r.end()) == ie+se);
CHECK(ie[0] == 0);
CHECK(ie[1] == 1);
CHECK(ie[2] == 2);
CHECK(ie[3] == 3);
CHECK(ie[4] == 4);
r = rotate(Iter(ie), Iter(ie+se), Sent(ie+se));
CHECK(base(r.begin()) == ie);
CHECK(base(r.end()) == ie+se);
CHECK(ie[0] == 0);
CHECK(ie[1] == 1);
CHECK(ie[2] == 2);
CHECK(ie[3] == 3);
CHECK(ie[4] == 4);
int ig[] = {0, 1, 2, 3, 4, 5};
const unsigned sg = sizeof(ig)/sizeof(ig[0]);
r = rotate(Iter(ig), Iter(ig), Sent(ig+sg));
CHECK(base(r.begin()) == ig+sg);
CHECK(base(r.end()) == ig+sg);
CHECK(ig[0] == 0);
CHECK(ig[1] == 1);
CHECK(ig[2] == 2);
CHECK(ig[3] == 3);
CHECK(ig[4] == 4);
CHECK(ig[5] == 5);
r = rotate(Iter(ig), Iter(ig+1), Sent(ig+sg));
CHECK(base(r.begin()) == ig+5);
CHECK(base(r.end()) == ig+sg);
CHECK(ig[0] == 1);
CHECK(ig[1] == 2);
CHECK(ig[2] == 3);
CHECK(ig[3] == 4);
CHECK(ig[4] == 5);
CHECK(ig[5] == 0);
r = rotate(Iter(ig), Iter(ig+2), Sent(ig+sg));
CHECK(base(r.begin()) == ig+4);
CHECK(base(r.end()) == ig+sg);
CHECK(ig[0] == 3);
CHECK(ig[1] == 4);
CHECK(ig[2] == 5);
CHECK(ig[3] == 0);
CHECK(ig[4] == 1);
CHECK(ig[5] == 2);
r = rotate(Iter(ig), Iter(ig+3), Sent(ig+sg));
CHECK(base(r.begin()) == ig+3);
CHECK(base(r.end()) == ig+sg);
CHECK(ig[0] == 0);
CHECK(ig[1] == 1);
CHECK(ig[2] == 2);
CHECK(ig[3] == 3);
CHECK(ig[4] == 4);
CHECK(ig[5] == 5);
r = rotate(Iter(ig), Iter(ig+4), Sent(ig+sg));
CHECK(base(r.begin()) == ig+2);
CHECK(base(r.end()) == ig+sg);
CHECK(ig[0] == 4);
CHECK(ig[1] == 5);
CHECK(ig[2] == 0);
CHECK(ig[3] == 1);
CHECK(ig[4] == 2);
CHECK(ig[5] == 3);
r = rotate(Iter(ig), Iter(ig+5), Sent(ig+sg));
CHECK(base(r.begin()) == ig+1);
CHECK(base(r.end()) == ig+sg);
CHECK(ig[0] == 3);
CHECK(ig[1] == 4);
CHECK(ig[2] == 5);
CHECK(ig[3] == 0);
CHECK(ig[4] == 1);
CHECK(ig[5] == 2);
r = rotate(Iter(ig), Iter(ig+sg), Sent(ig+sg));
CHECK(base(r.begin()) == ig);
CHECK(base(r.end()) == ig+sg);
CHECK(ig[0] == 3);
CHECK(ig[1] == 4);
CHECK(ig[2] == 5);
CHECK(ig[3] == 0);
CHECK(ig[4] == 1);
CHECK(ig[5] == 2);
}
constexpr bool test_constexpr()
{
int rgi[] = {0, 1, 2, 3, 4, 5};
auto r = ranges::rotate(rgi, rgi + 2);
STATIC_CHECK_RETURN(r.begin() == rgi + 4);
STATIC_CHECK_RETURN(r.end() == ranges::end(rgi));
STATIC_CHECK_RETURN(rgi[0] == 2);
STATIC_CHECK_RETURN(rgi[1] == 3);
STATIC_CHECK_RETURN(rgi[2] == 4);
STATIC_CHECK_RETURN(rgi[3] == 5);
STATIC_CHECK_RETURN(rgi[4] == 0);
STATIC_CHECK_RETURN(rgi[5] == 1);
return true;
}
int main()
{
test<ForwardIterator<int *>>();
test<BidirectionalIterator<int *>>();
test<RandomAccessIterator<int *>>();
test<ForwardIterator<int *>, Sentinel<int*>>();
test<BidirectionalIterator<int *>, Sentinel<int*>>();
test<RandomAccessIterator<int *>, Sentinel<int*>>();
// test rvalue ranges
{
int rgi[] = {0,1,2,3,4,5};
auto r = ranges::rotate(ranges::views::all(rgi), rgi+2);
CHECK(r.begin() == rgi+4);
CHECK(r.end() == ranges::end(rgi));
CHECK(rgi[0] == 2);
CHECK(rgi[1] == 3);
CHECK(rgi[2] == 4);
CHECK(rgi[3] == 5);
CHECK(rgi[4] == 0);
CHECK(rgi[5] == 1);
}
{
int rgi[] = {0,1,2,3,4,5};
auto r = ranges::rotate(std::move(rgi), rgi+2);
#ifndef RANGES_WORKAROUND_MSVC_573728
CHECK(::is_dangling(r));
#endif // RANGES_WORKAROUND_MSVC_573728
CHECK(rgi[0] == 2);
CHECK(rgi[1] == 3);
CHECK(rgi[2] == 4);
CHECK(rgi[3] == 5);
CHECK(rgi[4] == 0);
CHECK(rgi[5] == 1);
}
{
std::vector<int> rgi{0,1,2,3,4,5};
auto r = ranges::rotate(std::move(rgi), rgi.begin()+2);
CHECK(::is_dangling(r));
CHECK(rgi[0] == 2);
CHECK(rgi[1] == 3);
CHECK(rgi[2] == 4);
CHECK(rgi[3] == 5);
CHECK(rgi[4] == 0);
CHECK(rgi[5] == 1);
}
{
STATIC_CHECK(test_constexpr());
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/replace_copy.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright 2005 - 2007 Adobe Systems Incorporated
// Distributed under the MIT License(see accompanying file LICENSE_1_0_0.txt
// or a copy at http://stlab.adobe.com/licenses.html)
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <utility>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/replace_copy.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
template<class InIter, class OutIter, class Sent = InIter>
void test_iter()
{
int ia[] = {0, 1, 2, 3, 4};
const unsigned sa = sizeof(ia)/sizeof(ia[0]);
int ib[sa] = {0};
ranges::replace_copy_result<InIter, OutIter> r = ranges::replace_copy(InIter(ia), Sent(ia+sa), OutIter(ib), 2, 5);
CHECK(base(r.in) == ia + sa);
CHECK(base(r.out) == ib + sa);
CHECK(ib[0] == 0);
CHECK(ib[1] == 1);
CHECK(ib[2] == 5);
CHECK(ib[3] == 3);
CHECK(ib[4] == 4);
}
template<class InIter, class OutIter, class Sent = InIter>
void test_rng()
{
int ia[] = {0, 1, 2, 3, 4};
const unsigned sa = sizeof(ia)/sizeof(ia[0]);
int ib[sa] = {0};
auto rng = ranges::make_subrange(InIter(ia), Sent(ia+sa));
ranges::replace_copy_result<InIter, OutIter> r = ranges::replace_copy(rng, OutIter(ib), 2, 5);
CHECK(base(r.in) == ia + sa);
CHECK(base(r.out) == ib + sa);
CHECK(ib[0] == 0);
CHECK(ib[1] == 1);
CHECK(ib[2] == 5);
CHECK(ib[3] == 3);
CHECK(ib[4] == 4);
}
template<class InIter, class OutIter>
void test()
{
using Sent = typename sentinel_type<InIter>::type;
test_iter<InIter, OutIter>();
test_iter<InIter, OutIter>();
test_rng<InIter, OutIter, Sent>();
test_rng<InIter, OutIter, Sent>();
}
constexpr bool test_constexpr()
{
using namespace ranges;
int ia[] = {0, 1, 2, 3, 4};
int ib[5] = {0};
constexpr auto sa = ranges::size(ia);
const auto r = ranges::replace_copy(ia, ib, 2, 42);
STATIC_CHECK_RETURN(r.in == ia + sa);
STATIC_CHECK_RETURN(r.out == ib + sa);
STATIC_CHECK_RETURN(ib[0] == 0);
STATIC_CHECK_RETURN(ib[1] == 1);
STATIC_CHECK_RETURN(ib[2] == 42);
STATIC_CHECK_RETURN(ib[3] == 3);
STATIC_CHECK_RETURN(ib[4] == 4);
return true;
}
int main()
{
test<InputIterator<const int*>, OutputIterator<int*> >();
test<InputIterator<const int*>, ForwardIterator<int*> >();
test<InputIterator<const int*>, BidirectionalIterator<int*> >();
test<InputIterator<const int*>, RandomAccessIterator<int*> >();
test<InputIterator<const int*>, int*>();
test<ForwardIterator<const int*>, OutputIterator<int*> >();
test<ForwardIterator<const int*>, ForwardIterator<int*> >();
test<ForwardIterator<const int*>, BidirectionalIterator<int*> >();
test<ForwardIterator<const int*>, RandomAccessIterator<int*> >();
test<ForwardIterator<const int*>, int*>();
test<BidirectionalIterator<const int*>, OutputIterator<int*> >();
test<BidirectionalIterator<const int*>, ForwardIterator<int*> >();
test<BidirectionalIterator<const int*>, BidirectionalIterator<int*> >();
test<BidirectionalIterator<const int*>, RandomAccessIterator<int*> >();
test<BidirectionalIterator<const int*>, int*>();
test<RandomAccessIterator<const int*>, OutputIterator<int*> >();
test<RandomAccessIterator<const int*>, ForwardIterator<int*> >();
test<RandomAccessIterator<const int*>, BidirectionalIterator<int*> >();
test<RandomAccessIterator<const int*>, RandomAccessIterator<int*> >();
test<RandomAccessIterator<const int*>, int*>();
test<const int*, OutputIterator<int*> >();
test<const int*, ForwardIterator<int*> >();
test<const int*, BidirectionalIterator<int*> >();
test<const int*, RandomAccessIterator<int*> >();
test<const int*, int*>();
// Test projection
{
using P = std::pair<int, std::string>;
P in[] = {{0, "0"}, {1, "1"}, {2, "2"}, {3, "3"}, {4, "4"}};
P out[ranges::size(in)] = {};
ranges::replace_copy_result<P *, P *> r = ranges::replace_copy(in, out, 2, P{5, "5"}, &std::pair<int, std::string>::first);
CHECK(r.in == ranges::end(in));
CHECK(r.out == ranges::end(out));
CHECK(out[0] == P{0, "0"});
CHECK(out[1] == P{1, "1"});
CHECK(out[2] == P{5, "5"});
CHECK(out[3] == P{3, "3"});
CHECK(out[4] == P{4, "4"});
}
{
STATIC_CHECK(test_constexpr());
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/partial_sort_copy.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <algorithm>
#include <memory>
#include <random>
#include <vector>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/partial_sort_copy.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
RANGES_DIAGNOSTIC_IGNORE_GLOBAL_CONSTRUCTORS
RANGES_DIAGNOSTIC_IGNORE_SIGN_CONVERSION
namespace
{
std::mt19937 gen;
template<class Iter>
void
test_larger_sorts(int N, int M)
{
auto partial_sort_copy = ::make_testable_2<true, false>(ranges::partial_sort_copy);
int* input = new int[N];
int* output = new int[M];
for (int i = 0; i < N; ++i)
input[i] = i;
std::shuffle(input, input+N, gen);
partial_sort_copy(Iter(input), Iter(input+N), output, output+M).check([&](int* r)
{
int* e = output + std::min(N, M);
CHECK(r == e);
int i = 0;
for (int* x = output; x < e; ++x, ++i)
CHECK(*x == i);
std::shuffle(input, input+N, gen);
});
partial_sort_copy(Iter(input), Iter(input+N), output, output+M, std::greater<int>()).check([&](int* r)
{
int* e = output + std::min(N, M);
CHECK(r == e);
int i = N-1;
for (int* x = output; x < e; ++x, --i)
CHECK(*x == i);
std::shuffle(input, input+N, gen);
});
delete [] output;
delete [] input;
}
template<class Iter>
void
test_larger_sorts(int N)
{
test_larger_sorts<Iter>(N, 0);
test_larger_sorts<Iter>(N, 1);
test_larger_sorts<Iter>(N, 2);
test_larger_sorts<Iter>(N, 3);
test_larger_sorts<Iter>(N, N/2-1);
test_larger_sorts<Iter>(N, N/2);
test_larger_sorts<Iter>(N, N/2+1);
test_larger_sorts<Iter>(N, N-2);
test_larger_sorts<Iter>(N, N-1);
test_larger_sorts<Iter>(N, N);
test_larger_sorts<Iter>(N, N+1000);
}
template<class Iter>
void
test()
{
test_larger_sorts<Iter>(0, 100);
test_larger_sorts<Iter>(10);
test_larger_sorts<Iter>(256);
test_larger_sorts<Iter>(257);
test_larger_sorts<Iter>(499);
test_larger_sorts<Iter>(500);
test_larger_sorts<Iter>(997);
test_larger_sorts<Iter>(1000);
test_larger_sorts<Iter>(1009);
}
struct S
{
int i;
};
struct U
{
int i;
U & operator=(S s)
{
i = s.i;
return *this;
}
};
}
constexpr bool test_constexpr()
{
using namespace ranges;
using IL = std::initializer_list<int>;
int output[9] = {0};
int * r = partial_sort_copy(IL{5, 3, 4, 1, 8, 2, 6, 7, 0, 9}, output, less{});
int * e = output + 9;
STATIC_CHECK_RETURN(r == e);
int i = 0;
for(int * x = output; x < e; ++x, ++i)
{
STATIC_CHECK_RETURN(*x == i);
}
return true;
}
int main()
{
int i = 0;
int * r = ranges::partial_sort_copy(&i, &i, &i, &i+5);
CHECK(r == &i);
CHECK(i == 0);
test<InputIterator<const int*> >();
test<ForwardIterator<const int*> >();
test<BidirectionalIterator<const int*> >();
test<RandomAccessIterator<const int*> >();
test<const int*>();
// Check projections
{
constexpr int N = 256;
constexpr int M = N/2-1;
S input[N];
U output[M];
for (int j = 0; j < N; ++j)
input[j].i = j;
std::shuffle(input, input+N, gen);
U * r2 = ranges::partial_sort_copy(input, output, std::less<int>(), &S::i, &U::i);
U* e = output + std::min(N, M);
CHECK(r2 == e);
int i2 = 0;
for (U* x = output; x < e; ++x, ++i2)
CHECK(x->i == i2);
}
// Check rvalue ranges
{
constexpr int N = 256;
constexpr int M = N/2-1;
S input[N];
U output[M];
for (int j = 0; j < N; ++j)
input[j].i = j;
std::shuffle(input, input+N, gen);
auto r0 = ranges::partial_sort_copy(input, std::move(output), std::less<int>(), &S::i, &U::i);
U* e = output + std::min(N, M);
#ifndef RANGES_WORKAROUND_MSVC_573728
CHECK(::is_dangling(r0));
#endif // RANGES_WORKAROUND_MSVC_573728
int i2 = 0;
for (U* x = output; x < e; ++x, ++i2)
CHECK(x->i == i2);
std::vector<U> vec(M);
auto r1 = ranges::partial_sort_copy(input, std::move(vec), std::less<int>(), &S::i, &U::i);
e = vec.data() + std::min(N, M);
CHECK(::is_dangling(r1));
i2 = 0;
for (U* x = vec.data(); x < e; ++x, ++i2)
CHECK(x->i == i2);
}
{
STATIC_CHECK(test_constexpr());
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/remove_copy.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright 2005 - 2007 Adobe Systems Incorporated
// Distributed under the MIT License(see accompanying file LICENSE_1_0_0.txt
// or a copy at http://stlab.adobe.com/licenses.html)
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <memory>
#include <utility>
#include <vector>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/remove_copy.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
template<class InIter, class OutIter, class Sent = InIter>
void
test_iter()
{
int ia[] = {0, 1, 2, 3, 4, 2, 3, 4, 2};
constexpr auto sa = ranges::size(ia);
int ib[sa];
ranges::remove_copy_result<InIter, OutIter> r = ranges::remove_copy(InIter(ia), Sent(ia+sa), OutIter(ib), 2);
CHECK(base(r.in) == ia + sa);
CHECK(base(r.out) == ib + sa-3);
CHECK(ib[0] == 0);
CHECK(ib[1] == 1);
CHECK(ib[2] == 3);
CHECK(ib[3] == 4);
CHECK(ib[4] == 3);
CHECK(ib[5] == 4);
}
template<class InIter, class OutIter, class Sent = InIter>
void
test_range()
{
int ia[] = {0, 1, 2, 3, 4, 2, 3, 4, 2};
constexpr auto sa = ranges::size(ia);
int ib[sa];
ranges::remove_copy_result<InIter, OutIter> r = ranges::remove_copy(::as_lvalue(ranges::make_subrange(InIter(ia), Sent(ia+sa))), OutIter(ib), 2);
CHECK(base(r.in) == ia + sa);
CHECK(base(r.out) == ib + sa-3);
CHECK(ib[0] == 0);
CHECK(ib[1] == 1);
CHECK(ib[2] == 3);
CHECK(ib[3] == 4);
CHECK(ib[4] == 3);
CHECK(ib[5] == 4);
}
template<class InIter, class OutIter, class Sent = InIter>
void
test()
{
test_iter<InIter, OutIter, Sent>();
test_range<InIter, OutIter, Sent>();
}
struct S
{
int i;
};
constexpr bool test_constexpr()
{
using namespace ranges;
int ia[] = {0, 1, 2, 3, 4, 2, 3, 4, 2};
int ib[6] = {0};
constexpr auto sa = ranges::size(ia);
auto r = ranges::remove_copy(ia, ib, 2);
STATIC_CHECK_RETURN(r.in == ia + sa);
STATIC_CHECK_RETURN(r.out == ib + (sa - 3));
STATIC_CHECK_RETURN(ib[0] == 0);
STATIC_CHECK_RETURN(ib[1] == 1);
STATIC_CHECK_RETURN(ib[2] == 3);
STATIC_CHECK_RETURN(ib[3] == 4);
STATIC_CHECK_RETURN(ib[4] == 3);
STATIC_CHECK_RETURN(ib[5] == 4);
return true;
}
int main()
{
test<InputIterator<const int*>, OutputIterator<int*>>();
test<InputIterator<const int*>, ForwardIterator<int*>>();
test<InputIterator<const int*>, BidirectionalIterator<int*>>();
test<InputIterator<const int*>, RandomAccessIterator<int*>>();
test<InputIterator<const int*>, int*>();
test<ForwardIterator<const int*>, OutputIterator<int*>>();
test<ForwardIterator<const int*>, ForwardIterator<int*>>();
test<ForwardIterator<const int*>, BidirectionalIterator<int*>>();
test<ForwardIterator<const int*>, RandomAccessIterator<int*>>();
test<ForwardIterator<const int*>, int*>();
test<BidirectionalIterator<const int*>, OutputIterator<int*>>();
test<BidirectionalIterator<const int*>, ForwardIterator<int*>>();
test<BidirectionalIterator<const int*>, BidirectionalIterator<int*>>();
test<BidirectionalIterator<const int*>, RandomAccessIterator<int*>>();
test<BidirectionalIterator<const int*>, int*>();
test<RandomAccessIterator<const int*>, OutputIterator<int*>>();
test<RandomAccessIterator<const int*>, ForwardIterator<int*>>();
test<RandomAccessIterator<const int*>, BidirectionalIterator<int*>>();
test<RandomAccessIterator<const int*>, RandomAccessIterator<int*>>();
test<RandomAccessIterator<const int*>, int*>();
test<const int*, OutputIterator<int*>>();
test<const int*, ForwardIterator<int*>>();
test<const int*, BidirectionalIterator<int*>>();
test<const int*, RandomAccessIterator<int*>>();
test<const int*, int*>();
test<InputIterator<const int*>, OutputIterator<int*>, Sentinel<const int*>>();
test<InputIterator<const int*>, ForwardIterator<int*>, Sentinel<const int*>>();
test<InputIterator<const int*>, BidirectionalIterator<int*>, Sentinel<const int*>>();
test<InputIterator<const int*>, RandomAccessIterator<int*>, Sentinel<const int*>>();
test<InputIterator<const int*>, int*, Sentinel<const int*>>();
test<ForwardIterator<const int*>, OutputIterator<int*>, Sentinel<const int*>>();
test<ForwardIterator<const int*>, ForwardIterator<int*>, Sentinel<const int*>>();
test<ForwardIterator<const int*>, BidirectionalIterator<int*>, Sentinel<const int*>>();
test<ForwardIterator<const int*>, RandomAccessIterator<int*>, Sentinel<const int*>>();
test<ForwardIterator<const int*>, int*, Sentinel<const int*>>();
test<BidirectionalIterator<const int*>, OutputIterator<int*>, Sentinel<const int*>>();
test<BidirectionalIterator<const int*>, ForwardIterator<int*>, Sentinel<const int*>>();
test<BidirectionalIterator<const int*>, BidirectionalIterator<int*>, Sentinel<const int*>>();
test<BidirectionalIterator<const int*>, RandomAccessIterator<int*>, Sentinel<const int*>>();
test<BidirectionalIterator<const int*>, int*, Sentinel<const int*>>();
test<RandomAccessIterator<const int*>, OutputIterator<int*>, Sentinel<const int*>>();
test<RandomAccessIterator<const int*>, ForwardIterator<int*>, Sentinel<const int*>>();
test<RandomAccessIterator<const int*>, BidirectionalIterator<int*>, Sentinel<const int*>>();
test<RandomAccessIterator<const int*>, RandomAccessIterator<int*>, Sentinel<const int*>>();
test<RandomAccessIterator<const int*>, int*, Sentinel<const int*>>();
// Check projection
{
S ia[] = {S{0}, S{1}, S{2}, S{3}, S{4}, S{2}, S{3}, S{4}, S{2}};
constexpr auto sa = ranges::size(ia);
S ib[sa];
ranges::remove_copy_result<S*, S*> r = ranges::remove_copy(ia, ib, 2, &S::i);
CHECK(r.in == ia + sa);
CHECK(r.out == ib + sa-3);
CHECK(ib[0].i == 0);
CHECK(ib[1].i == 1);
CHECK(ib[2].i == 3);
CHECK(ib[3].i == 4);
CHECK(ib[4].i == 3);
CHECK(ib[5].i == 4);
}
// Check rvalue range
{
S ia[] = {S{0}, S{1}, S{2}, S{3}, S{4}, S{2}, S{3}, S{4}, S{2}};
constexpr auto sa = ranges::size(ia);
S ib[sa] = {};
auto r0 = ranges::remove_copy(std::move(ia), ib, 2, &S::i);
#ifndef RANGES_WORKAROUND_MSVC_573728
static_assert(std::is_same<decltype(r0),
ranges::remove_copy_result<ranges::dangling, S *>>::value, "");
#endif // RANGES_WORKAROUND_MSVC_573728
CHECK(r0.out == ib + sa-3);
CHECK(ib[0].i == 0);
CHECK(ib[1].i == 1);
CHECK(ib[2].i == 3);
CHECK(ib[3].i == 4);
CHECK(ib[4].i == 3);
CHECK(ib[5].i == 4);
std::fill(ranges::begin(ib), ranges::end(ib), S{});
std::vector<S> vec(ranges::begin(ia), ranges::end(ia));
auto r1 = ranges::remove_copy(std::move(vec), ib, 2, &S::i);
static_assert(std::is_same<decltype(r1),
ranges::remove_copy_result<ranges::dangling, S *>>::value, "");
CHECK(r1.out == ib + sa-3);
CHECK(ib[0].i == 0);
CHECK(ib[1].i == 1);
CHECK(ib[2].i == 3);
CHECK(ib[3].i == 4);
CHECK(ib[4].i == 3);
CHECK(ib[5].i == 4);
}
{
STATIC_CHECK(test_constexpr());
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/set_symmetric_difference6.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#define SET_SYMMETRIC_DIFFERENCE_6
#include "./set_symmetric_difference.hpp"
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/set_intersection2.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#define SET_INTERSECTION_2
#include "./set_intersection.hpp"
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/find.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <utility>
#include <vector>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/find.hpp>
#include "../simple_test.hpp"
#include "../test_iterators.hpp"
struct S
{
int i_;
};
template<class Rng, class T>
constexpr T ret_val(Rng r, T val)
{
auto rng = r;
auto pi = ranges::find(rng, val);
return *pi;
}
template<class Rng, class T>
constexpr bool found(Rng r, T val)
{
auto rng = r;
auto pi = ranges::find(rng, val);
return pi != ranges::end(rng);
}
int main()
{
using namespace ranges;
int ia[] = {0, 1, 2, 3, 4, 5};
constexpr auto s = size(ia);
{
InputIterator<const int*> r = find(InputIterator<const int*>(ia),
InputIterator<const int*>(ia+s), 3);
CHECK(*r == 3);
r = find(InputIterator<const int*>(ia),
InputIterator<const int*>(ia+s), 10);
CHECK(r == InputIterator<const int*>(ia+s));
r = find(InputIterator<const int*>(ia),
Sentinel<const int*>(ia+s), 3);
CHECK(*r == 3);
r = find(InputIterator<const int*>(ia),
Sentinel<const int*>(ia+s), 10);
CHECK(r == InputIterator<const int*>(ia+s));
}
{
int *pi = find(ia, 3);
CHECK(*pi == 3);
pi = find(ia, 10);
CHECK(pi == ia+s);
}
{
#ifndef RANGES_WORKAROUND_MSVC_573728
auto pj0 = find(std::move(ia), 3);
CHECK(::is_dangling(pj0));
#endif // RANGES_WORKAROUND_MSVC_573728
std::vector<int> vec(begin(ia), end(ia));
auto pj1 = find(std::move(vec), 3);
CHECK(::is_dangling(pj1));
auto pj2 = find(views::all(ia), 10);
CHECK(pj2 == ia+s);
}
{
S sa[] = {{0}, {1}, {2}, {3}, {4}, {5}};
S *ps = find(sa, 3, &S::i_);
CHECK(ps->i_ == 3);
ps = find(sa, 10, &S::i_);
CHECK(ps == end(sa));
}
{
// https://github.com/Microsoft/Range-V3-VS2015/issues/9
auto vec = std::vector<std::string>{{"a"}, {"b"}, {"c"}};
auto it = ranges::find(vec, "b");
CHECK(it == vec.begin() + 1);
}
{
using IL = std::initializer_list<int>;
STATIC_CHECK(ret_val(IL{1, 2}, 2) == 2);
STATIC_CHECK(found(IL{1, 3, 4}, 4));
STATIC_CHECK(!found(IL{1, 3, 4}, 5));
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/set_union1.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#define SET_UNION_1
#include "./set_union.hpp"
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/reverse.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright 2005 - 2007 Adobe Systems Incorporated
// Distributed under the MIT License(see accompanying file LICENSE_1_0_0.txt
// or a copy at http://stlab.adobe.com/licenses.html)
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <utility>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/reverse.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
template<class Iter, class Sent = Iter>
void test()
{
// iterators
{
int ia[] = {0};
const unsigned sa = sizeof(ia)/sizeof(ia[0]);
Iter i0 = ranges::reverse(Iter(ia), Sent(ia));
::check_equal(ia, {0});
CHECK(i0 == Iter(ia));
Iter i1 = ranges::reverse(Iter(ia), Sent(ia+sa));
::check_equal(ia, {0});
CHECK(i1 == Iter(ia+sa));
int ib[] = {0, 1};
const unsigned sb = sizeof(ib)/sizeof(ib[0]);
Iter i2 = ranges::reverse(Iter(ib), Sent(ib+sb));
::check_equal(ib, {1, 0});
CHECK(i2 == Iter(ib+sb));
int ic[] = {0, 1, 2};
const unsigned sc = sizeof(ic)/sizeof(ic[0]);
Iter i3 = ranges::reverse(Iter(ic), Sent(ic+sc));
::check_equal(ic, {2, 1, 0});
CHECK(i3 == Iter(ic+sc));
int id[] = {0, 1, 2, 3};
const unsigned sd = sizeof(id)/sizeof(id[0]);
Iter i4 = ranges::reverse(Iter(id), Sent(id+sd));
::check_equal(id, {3, 2, 1, 0});
CHECK(i4 == Iter(id+sd));
}
// ranges
{
int ia[] = {0};
const unsigned sa = sizeof(ia)/sizeof(ia[0]);
Iter i0 = ranges::reverse(::as_lvalue(ranges::make_subrange(Iter(ia), Sent(ia))));
::check_equal(ia, {0});
CHECK(i0 == Iter(ia));
Iter i1 = ranges::reverse(::as_lvalue(ranges::make_subrange(Iter(ia), Sent(ia+sa))));
::check_equal(ia, {0});
CHECK(i1 == Iter(ia+sa));
int ib[] = {0, 1};
const unsigned sb = sizeof(ib)/sizeof(ib[0]);
Iter i2 = ranges::reverse(::as_lvalue(ranges::make_subrange(Iter(ib), Sent(ib+sb))));
::check_equal(ib, {1, 0});
CHECK(i2 == Iter(ib+sb));
int ic[] = {0, 1, 2};
const unsigned sc = sizeof(ic)/sizeof(ic[0]);
Iter i3 = ranges::reverse(::as_lvalue(ranges::make_subrange(Iter(ic), Sent(ic+sc))));
::check_equal(ic, {2, 1, 0});
CHECK(i3 == Iter(ic+sc));
int id[] = {0, 1, 2, 3};
const unsigned sd = sizeof(id)/sizeof(id[0]);
Iter i4 = ranges::reverse(::as_lvalue(ranges::make_subrange(Iter(id), Sent(id+sd))));
::check_equal(id, {3, 2, 1, 0});
CHECK(i4 == Iter(id+sd));
// rvalue range
auto i5 = ranges::reverse(ranges::make_subrange(Iter(id), Sent(id+sd)));
::check_equal(id, {0, 1, 2, 3});
CHECK(i5 == Iter(id+sd));
}
}
constexpr bool test_constexpr()
{
using namespace ranges;
int ia[] = {0, 1, 2, 3, 4};
constexpr auto sa = ranges::size(ia);
auto r = ranges::reverse(ia);
STATIC_CHECK_RETURN(r == ia + sa);
STATIC_CHECK_RETURN(ia[0] == 4);
STATIC_CHECK_RETURN(ia[1] == 3);
STATIC_CHECK_RETURN(ia[2] == 2);
STATIC_CHECK_RETURN(ia[3] == 1);
STATIC_CHECK_RETURN(ia[4] == 0);
return true;
}
int main()
{
test<BidirectionalIterator<int *>>();
test<RandomAccessIterator<int *>>();
test<int*>();
test<BidirectionalIterator<int *>, Sentinel<int*>>();
test<RandomAccessIterator<int *>, Sentinel<int*>>();
{
STATIC_CHECK(test_constexpr());
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/nth_element.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <memory>
#include <random>
#include <algorithm>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/nth_element.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
RANGES_DIAGNOSTIC_IGNORE_GLOBAL_CONSTRUCTORS
RANGES_DIAGNOSTIC_IGNORE_SIGN_CONVERSION
namespace
{
std::mt19937 gen;
void
test_one(unsigned N, unsigned M)
{
RANGES_ENSURE(N != 0);
RANGES_ENSURE(M < N);
std::unique_ptr<int[]> array{new int[N]};
for (int i = 0; (unsigned)i < N; ++i)
array[i] = i;
std::shuffle(array.get(), array.get()+N, gen);
CHECK(ranges::nth_element(array.get(), array.get()+M, array.get()+N) == array.get()+N);
CHECK((unsigned)array[M] == M);
std::shuffle(array.get(), array.get()+N, gen);
CHECK(ranges::nth_element(::as_lvalue(ranges::make_subrange(array.get(), array.get()+N)), array.get()+M) == array.get()+N);
CHECK((unsigned)array[M] == M);
std::shuffle(array.get(), array.get()+N, gen);
CHECK(ranges::nth_element(ranges::make_subrange(array.get(), array.get()+N), array.get()+M) == array.get()+N);
CHECK((unsigned)array[M] == M);
ranges::nth_element(array.get(), array.get()+N, array.get()+N); // first, last, end
}
void
test(unsigned N)
{
test_one(N, 0);
test_one(N, 1);
test_one(N, 2);
test_one(N, 3);
test_one(N, N/2-1);
test_one(N, N/2);
test_one(N, N/2+1);
test_one(N, N-3);
test_one(N, N-2);
test_one(N, N-1);
}
struct S
{
int i,j;
};
}
int main()
{
int d = 0;
ranges::nth_element(&d, &d, &d);
CHECK(d == 0);
test(256);
test(257);
test(499);
test(500);
test(997);
test(1000);
test(1009);
// Works with projections?
const int N = 257;
const int M = 56;
S ia[N];
for(int i = 0; i < N; ++i)
ia[i].i = ia[i].j = i;
std::shuffle(ia, ia+N, gen);
ranges::nth_element(ia, ia+M, std::less<int>(), &S::i);
CHECK(ia[M].i == M);
CHECK(ia[M].j == M);
return test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/shuffle.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright 2005 - 2007 Adobe Systems Incorporated
// Distributed under the MIT License(see accompanying file LICENSE_1_0_0.txt
// or a copy at http://stlab.adobe.com/licenses.html)
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <array>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/equal.hpp>
#include <range/v3/algorithm/shuffle.hpp>
#include <range/v3/numeric/iota.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
int main()
{
constexpr unsigned N = 100;
{
std::array<int, N> a, b, c;
for (auto p : {&a, &b, &c})
ranges::iota(*p, 0);
std::minstd_rand g1, g2 = g1;
ranges::shuffle(RandomAccessIterator<int*>(a.data()), Sentinel<int*>(a.data()+N), g1);
CHECK(!ranges::equal(a, b));
CHECK(ranges::shuffle(b.begin(), b.end(), g1) == b.end());
CHECK(!ranges::equal(a, b));
CHECK(ranges::shuffle(c.begin(), c.end(), g2) == c.end());
CHECK(ranges::equal(a, c));
CHECK(!ranges::equal(b, c));
}
{
std::array<int, N> a, b, c;
for (auto p : {&a, &b, &c})
ranges::iota(*p, 0);
std::minstd_rand g1, g2 = g1;
auto rng = ::MakeTestRange(RandomAccessIterator<int*>(a.data()), Sentinel<int*>(a.data() + N));
ranges::shuffle(rng, g1);
CHECK(!ranges::equal(a, b));
CHECK(ranges::shuffle(b, g2) == b.end());
CHECK(ranges::equal(a, b));
CHECK(ranges::shuffle(b, g1) == b.end());
CHECK(!ranges::equal(a, b));
CHECK(!ranges::equal(b, c));
ranges::iota(a, 0);
CHECK(::is_dangling(ranges::shuffle(std::move(rng), g1)));
CHECK(!ranges::equal(a, c));
}
{
std::array<int, N> a, b, c;
for (auto p : {&a, &b, &c})
ranges::iota(*p, 0);
ranges::shuffle(RandomAccessIterator<int*>(a.data()), Sentinel<int*>(a.data() + N));
CHECK(!ranges::equal(a, c));
ranges::shuffle(b);
CHECK(!ranges::equal(b, c));
CHECK(!ranges::equal(a, b));
}
{
std::array<int, N> a, b;
for (auto p : {&a, &b})
ranges::iota(*p, 0);
ranges::shuffle(a);
CHECK(!ranges::equal(a, b));
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/set_difference2.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#define SET_DIFFERENCE_2
#include "./set_difference.hpp"
|
0 | repos/range-v3/test | repos/range-v3/test/algorithm/prev_permutation.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright 2005 - 2007 Adobe Systems Incorporated
// Distributed under the MIT License(see accompanying file LICENSE_1_0_0.txt
// or a copy at http://stlab.adobe.com/licenses.html)
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <cstring>
#include <utility>
#include <algorithm>
#include <range/v3/core.hpp>
#include <range/v3/algorithm/permutation.hpp>
#include <range/v3/algorithm/equal.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "../test_iterators.hpp"
int factorial(int x)
{
int r = 1;
for (; x; --x)
r *= x;
return r;
}
template<typename Iter, typename Sent = Iter>
void test_iter()
{
int ia[] = {6, 5, 4, 3, 2, 1};
const int sa = sizeof(ia)/sizeof(ia[0]);
int prev[sa];
for (int e = 0; e <= sa; ++e)
{
int count = 0;
bool x;
do
{
std::copy(ia, ia+e, prev);
x = ranges::prev_permutation(Iter(ia), Sent(ia+e));
if(e > 1)
{
if(!x)
CHECK(std::lexicographical_compare(prev, prev+e, ia, ia+e));
else
CHECK(std::lexicographical_compare(ia, ia+e, prev, prev+e));
}
++count;
} while(x);
CHECK(count == factorial(e));
}
}
template<typename Iter, typename Sent = Iter>
void test_range()
{
int ia[] = {6, 5, 4, 3, 2, 1};
const int sa = sizeof(ia)/sizeof(ia[0]);
int prev[sa];
for (int e = 0; e <= sa; ++e)
{
int count = 0;
bool x;
do
{
std::copy(ia, ia+e, prev);
x = ranges::prev_permutation(ranges::make_subrange(Iter(ia), Sent(ia+e)));
if(e > 1)
{
if(!x)
CHECK(std::lexicographical_compare(prev, prev+e, ia, ia+e));
else
CHECK(std::lexicographical_compare(ia, ia+e, prev, prev+e));
}
++count;
} while(x);
CHECK(count == factorial(e));
}
}
template<typename Iter, typename Sent = Iter>
void test_iter_comp()
{
typedef std::greater<int> C;
int ia[] = {1, 2, 3, 4, 5, 6};
const int sa = sizeof(ia)/sizeof(ia[0]);
int prev[sa];
for(int e = 0; e <= sa; ++e)
{
int count = 0;
bool x;
do
{
std::copy(ia, ia+e, prev);
x = ranges::prev_permutation(Iter(ia), Sent(ia+e), C());
if(e > 1)
{
if(!x)
CHECK(std::lexicographical_compare(prev, prev+e, ia, ia+e, C()));
else
CHECK(std::lexicographical_compare(ia, ia+e, prev, prev+e, C()));
}
++count;
} while (x);
CHECK(count == factorial(e));
}
}
template<typename Iter, typename Sent = Iter>
void test_range_comp()
{
typedef std::greater<int> C;
int ia[] = {1, 2, 3, 4, 5, 6};
const int sa = sizeof(ia)/sizeof(ia[0]);
int prev[sa];
for(int e = 0; e <= sa; ++e)
{
int count = 0;
bool x;
do
{
std::copy(ia, ia+e, prev);
x = ranges::prev_permutation(ranges::make_subrange(Iter(ia), Sent(ia+e)), C());
if(e > 1)
{
if(!x)
CHECK(std::lexicographical_compare(prev, prev+e, ia, ia+e, C()));
else
CHECK(std::lexicographical_compare(ia, ia+e, prev, prev+e, C()));
}
++count;
} while (x);
CHECK(count == factorial(e));
}
}
struct c_str
{
char const * value;
friend bool operator==(c_str a, c_str b)
{
return 0 == std::strcmp(a.value, b.value);
}
friend bool operator!=(c_str a, c_str b)
{
return !(a == b);
}
};
// For debugging the projection test
std::ostream &operator<<(std::ostream& sout, std::pair<int, c_str> p)
{
return sout << "{" << p.first << "," << p.second.value << "}";
}
constexpr bool test_constexpr()
{
using namespace ranges;
using IL = std::initializer_list<int>;
int ia[] = {6, 5, 4, 3, 2, 1};
prev_permutation(ia);
STATIC_CHECK_RETURN(equal(ia, IL{6, 5, 4, 3, 1, 2}));
prev_permutation(ia);
STATIC_CHECK_RETURN(equal(ia, IL{6, 5, 4, 2, 3, 1}));
prev_permutation(ia);
STATIC_CHECK_RETURN(equal(ia, IL{6, 5, 4, 2, 1, 3}));
return true;
}
int main()
{
test_iter<BidirectionalIterator<int*> >();
test_iter<RandomAccessIterator<int*> >();
test_iter<int*>();
test_iter<BidirectionalIterator<int*>, Sentinel<int*> >();
test_iter<RandomAccessIterator<int*>, Sentinel<int*> >();
test_iter_comp<BidirectionalIterator<int*> >();
test_iter_comp<RandomAccessIterator<int*> >();
test_iter_comp<int*>();
test_iter_comp<BidirectionalIterator<int*>, Sentinel<int*> >();
test_iter_comp<RandomAccessIterator<int*>, Sentinel<int*> >();
test_range<BidirectionalIterator<int*> >();
test_range<RandomAccessIterator<int*> >();
test_range<int*>();
test_range<BidirectionalIterator<int*>, Sentinel<int*> >();
test_range<RandomAccessIterator<int*>, Sentinel<int*> >();
test_range_comp<BidirectionalIterator<int*> >();
test_range_comp<RandomAccessIterator<int*> >();
test_range_comp<int*>();
test_range_comp<BidirectionalIterator<int*>, Sentinel<int*> >();
test_range_comp<RandomAccessIterator<int*>, Sentinel<int*> >();
// Test projection
using C = std::less<int>;
using I = std::initializer_list<std::pair<int, c_str>>;
std::pair<int, c_str> ia[] = {{6, {"six"}}, {5,{"five"}}, {4,{"four"}}, {3,{"three"}}, {2,{"two"}}, {1,{"one"}}};
CHECK(ranges::prev_permutation(ia, C(), &std::pair<int,c_str>::first));
::check_equal(ia, I{{6, {"six"}}, {5,{"five"}}, {4,{"four"}}, {3,{"three"}}, {1,{"one"}}, {2,{"two"}}});
CHECK(ranges::prev_permutation(ia, C(), &std::pair<int,c_str>::first));
::check_equal(ia, I{{6, {"six"}}, {5,{"five"}}, {4,{"four"}}, {2,{"two"}}, {3,{"three"}}, {1,{"one"}}});
CHECK(ranges::prev_permutation(ia, C(), &std::pair<int,c_str>::first));
::check_equal(ia, I{{6, {"six"}}, {5,{"five"}}, {4,{"four"}}, {2,{"two"}}, {1,{"one"}}, {3,{"three"}}});
// etc..
{
STATIC_CHECK(test_constexpr());
}
return ::test_result();
}
|
Subsets and Splits