init
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
This commit is contained in:
6
Telegram/ThirdParty/range-v3/test/range/CMakeLists.txt
vendored
Normal file
6
Telegram/ThirdParty/range-v3/test/range/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
set(CMAKE_FOLDER "${CMAKE_FOLDER}/range")
|
||||
|
||||
rv3_add_test(test.range.access range.access access.cpp)
|
||||
rv3_add_test(test.range.conversion range.conversion conversion.cpp)
|
||||
rv3_add_test(test.range.index range.index index.cpp)
|
||||
rv3_add_test(test.range.operations range.operations operations.cpp)
|
||||
316
Telegram/ThirdParty/range-v3/test/range/access.cpp
vendored
Normal file
316
Telegram/ThirdParty/range-v3/test/range/access.cpp
vendored
Normal file
@@ -0,0 +1,316 @@
|
||||
// Range v3 library
|
||||
//
|
||||
// Copyright Casey Carter 2016
|
||||
// Copyright Eric Niebler 2018
|
||||
//
|
||||
// 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/range/access.hpp>
|
||||
#include <range/v3/range/primitives.hpp>
|
||||
#include <range/v3/view/subrange.hpp>
|
||||
#include <range/v3/view/ref.hpp>
|
||||
#include <range/v3/view/iota.hpp>
|
||||
#include <range/v3/algorithm/find.hpp>
|
||||
#include <vector>
|
||||
#include "../simple_test.hpp"
|
||||
|
||||
#if defined(__clang__)
|
||||
RANGES_DIAGNOSTIC_IGNORE("-Wunused-const-variable")
|
||||
#endif
|
||||
|
||||
void test_range_access_ambiguity()
|
||||
{
|
||||
std::vector<ranges::reverse_iterator<int*>> vri{};
|
||||
using namespace ranges;
|
||||
(void)begin(vri);
|
||||
(void)end(vri);
|
||||
(void)cbegin(vri);
|
||||
(void)cend(vri);
|
||||
(void)rbegin(vri);
|
||||
(void)rend(vri);
|
||||
(void)crbegin(vri);
|
||||
(void)crend(vri);
|
||||
}
|
||||
|
||||
void test_initializer_list()
|
||||
{
|
||||
std::initializer_list<int> il = {0,1,2};
|
||||
{
|
||||
int count = 0;
|
||||
for(auto p = ranges::begin(il), e = ranges::end(il); p != e; ++p) {
|
||||
CHECK(*p == count++);
|
||||
}
|
||||
}
|
||||
{
|
||||
int count = 3;
|
||||
for(auto p = ranges::rbegin(il), e = ranges::rend(il); p != e; ++p) {
|
||||
CHECK(*p == --count);
|
||||
}
|
||||
}
|
||||
CHECK(ranges::size(il) == std::size_t{3});
|
||||
CHECK(ranges::data(il) == &*il.begin());
|
||||
CHECK(ranges::empty(il) == false);
|
||||
}
|
||||
|
||||
template<class Value, typename T, T... Is>
|
||||
void test_array(std::integer_sequence<T, Is...>)
|
||||
{
|
||||
Value a[sizeof...(Is)] = { Is... };
|
||||
{
|
||||
int count = 0;
|
||||
for(auto p = ranges::begin(a), e = ranges::end(a); p != e; ++p) {
|
||||
CHECK(*p == count++);
|
||||
}
|
||||
}
|
||||
{
|
||||
int count = sizeof...(Is);
|
||||
for(auto p = ranges::rbegin(a), e = ranges::rend(a); p != e; ++p) {
|
||||
CHECK(*p == --count);
|
||||
}
|
||||
}
|
||||
CHECK(ranges::size(a) == sizeof...(Is));
|
||||
CHECK(ranges::data(a) == a + 0);
|
||||
CHECK(ranges::empty(a) == false);
|
||||
}
|
||||
|
||||
namespace begin_testing
|
||||
{
|
||||
template<class R>
|
||||
CPP_requires(can_begin_,
|
||||
requires(R&& r) //
|
||||
(
|
||||
ranges::begin((R &&) r)
|
||||
));
|
||||
template<class R>
|
||||
CPP_concept can_begin =
|
||||
CPP_requires_ref(can_begin_, R);
|
||||
|
||||
template<class R>
|
||||
CPP_requires(can_cbegin_,
|
||||
requires(R&& r) //
|
||||
(
|
||||
ranges::cbegin((R &&) r)
|
||||
));
|
||||
template<class R>
|
||||
CPP_concept can_cbegin =
|
||||
CPP_requires_ref(can_cbegin_, R);
|
||||
|
||||
struct A
|
||||
{
|
||||
int* begin();
|
||||
int* end();
|
||||
int const * begin() const;
|
||||
int const * end() const;
|
||||
};
|
||||
|
||||
struct B : A {};
|
||||
void* begin(B&);
|
||||
|
||||
struct C : A {};
|
||||
void begin(C&);
|
||||
|
||||
struct D : A {};
|
||||
char* begin(D&);
|
||||
|
||||
void test()
|
||||
{
|
||||
// Valid
|
||||
CPP_assert(can_begin<int(&)[2]>);
|
||||
CPP_assert(ranges::same_as<decltype(ranges::begin(std::declval<int(&)[2]>())), int*>);
|
||||
CPP_assert(can_begin<int const(&)[2]>);
|
||||
CPP_assert(ranges::same_as<decltype(ranges::begin(std::declval<int const(&)[2]>())), int const *>);
|
||||
|
||||
CPP_assert(can_cbegin<int(&)[2]>);
|
||||
CPP_assert(ranges::same_as<decltype(ranges::cbegin(std::declval<int(&)[2]>())), int const *>);
|
||||
CPP_assert(can_cbegin<int const(&)[2]>);
|
||||
CPP_assert(ranges::same_as<decltype(ranges::cbegin(std::declval<int const(&)[2]>())), int const *>);
|
||||
|
||||
#ifndef RANGES_WORKAROUND_MSVC_573728
|
||||
// Ill-formed: array rvalue
|
||||
CPP_assert(!can_begin<int(&&)[2]>);
|
||||
CPP_assert(!can_begin<int const(&&)[2]>);
|
||||
|
||||
CPP_assert(!can_cbegin<int(&&)[2]>);
|
||||
CPP_assert(!can_cbegin<int const(&&)[2]>);
|
||||
#endif // RANGES_WORKAROUND_MSVC_573728
|
||||
|
||||
// Valid: only member begin
|
||||
CPP_assert(can_begin<A&>);
|
||||
CPP_assert(!can_begin<A>);
|
||||
CPP_assert(ranges::same_as<decltype(ranges::begin(std::declval<A&>())), int*>);
|
||||
CPP_assert(can_begin<const A&>);
|
||||
CPP_assert(!can_begin<const A>);
|
||||
CPP_assert(ranges::same_as<decltype(ranges::begin(std::declval<const A&>())), int const *>);
|
||||
|
||||
// Valid: Both member and non-member begin, but non-member returns non-Iterator.
|
||||
CPP_assert(can_begin<B&>);
|
||||
CPP_assert(!can_begin<B>);
|
||||
CPP_assert(ranges::same_as<decltype(ranges::begin(std::declval<B&>())), int*>);
|
||||
CPP_assert(can_begin<const B&>);
|
||||
CPP_assert(!can_begin<const B>);
|
||||
CPP_assert(ranges::same_as<decltype(ranges::begin(std::declval<const B&>())), int const *>);
|
||||
|
||||
// Valid: Both member and non-member begin, but non-member returns non-Iterator.
|
||||
CPP_assert(can_begin<C&>);
|
||||
CPP_assert(!can_begin<C>);
|
||||
CPP_assert(can_begin<const C&>);
|
||||
CPP_assert(!can_begin<const C>);
|
||||
|
||||
// Valid: Prefer member begin
|
||||
CPP_assert(can_begin<D&>);
|
||||
CPP_assert(!can_begin<D>);
|
||||
CPP_assert(ranges::same_as<int*, decltype(ranges::begin(std::declval<D&>()))>);
|
||||
CPP_assert(can_begin<const D&>);
|
||||
CPP_assert(!can_begin<const D>);
|
||||
CPP_assert(ranges::same_as<int const *, decltype(ranges::begin(std::declval<const D&>()))>);
|
||||
|
||||
{
|
||||
using T = std::initializer_list<int>;
|
||||
// Valid: begin accepts lvalue initializer_list
|
||||
CPP_assert(ranges::same_as<int const *, decltype(ranges::begin(std::declval<T&>()))>);
|
||||
CPP_assert(ranges::same_as<int const *, decltype(ranges::begin(std::declval<const T&>()))>);
|
||||
CPP_assert(!can_begin<T>);
|
||||
CPP_assert(!can_begin<T const>);
|
||||
}
|
||||
|
||||
CPP_assert(can_begin<ranges::subrange<int*, int*>&>);
|
||||
CPP_assert(can_begin<const ranges::subrange<int*, int*>&>);
|
||||
CPP_assert(can_begin<ranges::subrange<int*, int*>>);
|
||||
CPP_assert(can_begin<const ranges::subrange<int*, int*>>);
|
||||
|
||||
CPP_assert(can_cbegin<ranges::subrange<int*, int*>&>);
|
||||
CPP_assert(can_cbegin<const ranges::subrange<int*, int*>&>);
|
||||
CPP_assert(can_cbegin<ranges::subrange<int*, int*>>);
|
||||
CPP_assert(can_cbegin<const ranges::subrange<int*, int*>>);
|
||||
|
||||
CPP_assert(can_begin<ranges::ref_view<int[5]>&>);
|
||||
CPP_assert(can_begin<const ranges::ref_view<int[5]>&>);
|
||||
CPP_assert(can_begin<ranges::ref_view<int[5]>>);
|
||||
CPP_assert(can_begin<const ranges::ref_view<int[5]>>);
|
||||
|
||||
CPP_assert(can_cbegin<ranges::ref_view<int[5]>&>);
|
||||
CPP_assert(can_cbegin<const ranges::ref_view<int[5]>&>);
|
||||
CPP_assert(can_cbegin<ranges::ref_view<int[5]>>);
|
||||
CPP_assert(can_cbegin<const ranges::ref_view<int[5]>>);
|
||||
|
||||
// TODO
|
||||
// CPP_assert(can_begin<ranges::iota_view<int, int>&>);
|
||||
// CPP_assert(can_begin<const ranges::iota_view<int, int>&>);
|
||||
// CPP_assert(can_begin<ranges::iota_view<int, int>>);
|
||||
// CPP_assert(can_begin<const ranges::iota_view<int, int>>);
|
||||
|
||||
// CPP_assert(can_cbegin<ranges::iota_view<int, int>&>);
|
||||
// CPP_assert(can_cbegin<const ranges::iota_view<int, int>&>);
|
||||
// CPP_assert(can_cbegin<ranges::iota_view<int, int>>);
|
||||
// CPP_assert(can_cbegin<const ranges::iota_view<int, int>>);
|
||||
}
|
||||
} // namespace begin_testing
|
||||
|
||||
namespace X
|
||||
{
|
||||
template<class T, std::size_t N>
|
||||
struct array
|
||||
{
|
||||
T elements_[N];
|
||||
|
||||
constexpr bool empty() const noexcept { return N == 0; }
|
||||
constexpr T* data() noexcept { return elements_; }
|
||||
constexpr T const *data() const noexcept { return elements_; }
|
||||
};
|
||||
|
||||
template<class T, std::size_t N>
|
||||
constexpr T* begin(array<T, N> &a) noexcept { return a.elements_; }
|
||||
template<class T, std::size_t N>
|
||||
constexpr T* end(array<T, N> &a) noexcept { return a.elements_ + N; }
|
||||
template<class T, std::size_t N>
|
||||
constexpr T const *begin(array<T, N> const &a) noexcept { return a.elements_; }
|
||||
template<class T, std::size_t N>
|
||||
constexpr T const *end(array<T, N> const &a) noexcept { return a.elements_ + N; }
|
||||
} // namespace X
|
||||
|
||||
using I = int*;
|
||||
using CI = int const *;
|
||||
CPP_assert(ranges::input_or_output_iterator<I>);
|
||||
CPP_assert(ranges::input_or_output_iterator<CI>);
|
||||
|
||||
#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201603L
|
||||
void test_string_view_p0970()
|
||||
{
|
||||
// basic_string_views are non-dangling
|
||||
using I2 = ranges::iterator_t<std::string_view>;
|
||||
CPP_assert(ranges::same_as<I2, decltype(ranges::begin(std::declval<std::string_view>()))>);
|
||||
CPP_assert(ranges::same_as<I2, decltype(ranges::end(std::declval<std::string_view>()))>);
|
||||
CPP_assert(ranges::same_as<I2, decltype(ranges::begin(std::declval<const std::string_view>()))>);
|
||||
CPP_assert(ranges::same_as<I2, decltype(ranges::end(std::declval<const std::string_view>()))>);
|
||||
|
||||
{
|
||||
const char hw[] = "Hello, World!";
|
||||
auto result = ranges::find(std::string_view{hw}, 'W');
|
||||
CPP_assert(ranges::same_as<I2, decltype(result)>);
|
||||
CHECK(result == std::string_view{hw}.begin() + 7);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace ranges;
|
||||
|
||||
static constexpr X::array<int, 4> some_ints = {{0,1,2,3}};
|
||||
CPP_assert(begin_testing::can_begin<X::array<int, 4> &>);
|
||||
CPP_assert(begin_testing::can_begin<X::array<int, 4> const &>);
|
||||
CPP_assert(!begin_testing::can_begin<X::array<int, 4>>);
|
||||
CPP_assert(!begin_testing::can_begin<X::array<int, 4> const>);
|
||||
CPP_assert(begin_testing::can_cbegin<X::array<int, 4> &>);
|
||||
CPP_assert(begin_testing::can_cbegin<X::array<int, 4> const &>);
|
||||
CPP_assert(!begin_testing::can_cbegin<X::array<int, 4>>);
|
||||
CPP_assert(!begin_testing::can_cbegin<X::array<int, 4> const>);
|
||||
|
||||
constexpr auto first = begin(some_ints);
|
||||
constexpr auto last = end(some_ints);
|
||||
CPP_assert(ranges::same_as<const CI, decltype(first)>);
|
||||
CPP_assert(ranges::same_as<const CI, decltype(last)>);
|
||||
static_assert(first == cbegin(some_ints), "");
|
||||
static_assert(last == cend(some_ints), "");
|
||||
|
||||
static_assert(noexcept(begin(some_ints)), "");
|
||||
static_assert(noexcept(end(some_ints)), "");
|
||||
static_assert(noexcept(cbegin(some_ints)), "");
|
||||
static_assert(noexcept(cend(some_ints)), "");
|
||||
static_assert(noexcept(empty(some_ints)), "");
|
||||
static_assert(noexcept(data(some_ints)), "");
|
||||
|
||||
constexpr bool output = false;
|
||||
static_assert(!empty(some_ints), "");
|
||||
if(output)
|
||||
std::cout << '{';
|
||||
auto is_first = true;
|
||||
auto count = 0;
|
||||
for(auto&& i : some_ints)
|
||||
{
|
||||
CHECK(i == count++);
|
||||
if(is_first)
|
||||
is_first = false;
|
||||
else
|
||||
if(output) std::cout << ", ";
|
||||
if(output) std::cout << i;
|
||||
}
|
||||
if(output)
|
||||
std::cout << "}\n";
|
||||
|
||||
test_initializer_list();
|
||||
test_array<int>(std::make_integer_sequence<int, 3>{});
|
||||
test_array<int const>(std::make_integer_sequence<int, 3>{});
|
||||
begin_testing::test();
|
||||
|
||||
#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201603L
|
||||
test_string_view_p0970();
|
||||
#endif
|
||||
|
||||
return ::test_result();
|
||||
}
|
||||
260
Telegram/ThirdParty/range-v3/test/range/conversion.cpp
vendored
Normal file
260
Telegram/ThirdParty/range-v3/test/range/conversion.cpp
vendored
Normal file
@@ -0,0 +1,260 @@
|
||||
// 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 <list>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include <range/v3/action/sort.hpp>
|
||||
#include <range/v3/core.hpp>
|
||||
#include <range/v3/range/conversion.hpp>
|
||||
#include <range/v3/view/indices.hpp>
|
||||
#include <range/v3/view/iota.hpp>
|
||||
#include <range/v3/view/take.hpp>
|
||||
#include <range/v3/view/transform.hpp>
|
||||
#include <range/v3/view/zip.hpp>
|
||||
#include <range/v3/view/reverse.hpp>
|
||||
|
||||
#include "../simple_test.hpp"
|
||||
#include "../test_utils.hpp"
|
||||
|
||||
template<typename T>
|
||||
struct vector_like
|
||||
{
|
||||
private:
|
||||
std::vector<T> data_;
|
||||
public:
|
||||
using size_type = std::size_t;
|
||||
using allocator_type = std::allocator<T>;
|
||||
|
||||
vector_like() = default;
|
||||
template<typename I>
|
||||
vector_like(I first, I last)
|
||||
: data_(first, last)
|
||||
{}
|
||||
template<typename I>
|
||||
void assign(I first, I last)
|
||||
{
|
||||
data_.assign(first, last);
|
||||
}
|
||||
|
||||
auto begin()
|
||||
{
|
||||
return data_.begin();
|
||||
}
|
||||
auto end()
|
||||
{
|
||||
return data_.end();
|
||||
}
|
||||
auto begin() const
|
||||
{
|
||||
return data_.begin();
|
||||
}
|
||||
auto end() const
|
||||
{
|
||||
return data_.end();
|
||||
}
|
||||
size_type size() const
|
||||
{
|
||||
return data_.size();
|
||||
}
|
||||
size_type capacity() const
|
||||
{
|
||||
return data_.capacity();
|
||||
}
|
||||
size_type max_size() const
|
||||
{
|
||||
return data_.max_size();
|
||||
}
|
||||
auto& operator[](size_type n)
|
||||
{
|
||||
return data_[n];
|
||||
}
|
||||
auto& operator[](size_type n) const
|
||||
{
|
||||
return data_[n];
|
||||
}
|
||||
|
||||
size_type last_reservation{};
|
||||
size_type reservation_count{};
|
||||
|
||||
void reserve(size_type n)
|
||||
{
|
||||
data_.reserve(n);
|
||||
last_reservation = n;
|
||||
++reservation_count;
|
||||
}
|
||||
};
|
||||
|
||||
#if RANGES_CXX_DEDUCTION_GUIDES >= RANGES_CXX_DEDUCTION_GUIDES_17
|
||||
template<typename I>
|
||||
vector_like(I, I) -> vector_like<ranges::iter_value_t<I>>;
|
||||
|
||||
template<typename Rng, typename CI = ranges::range_common_iterator_t<Rng>,
|
||||
typename = decltype(std::map{CI{}, CI{}})>
|
||||
void test_zip_to_map(Rng && rng, int)
|
||||
{
|
||||
using namespace ranges;
|
||||
#ifdef RANGES_WORKAROUND_MSVC_779708
|
||||
auto m = static_cast<Rng &&>(rng) | to<std::map>();
|
||||
#else // ^^^ workaround / no workaround vvv
|
||||
auto m = static_cast<Rng &&>(rng) | to<std::map>;
|
||||
#endif // RANGES_WORKAROUND_MSVC_779708
|
||||
CPP_assert(same_as<decltype(m), std::map<int, int>>);
|
||||
}
|
||||
#endif
|
||||
template<typename Rng>
|
||||
void test_zip_to_map(Rng &&, long)
|
||||
{}
|
||||
|
||||
template<typename K, typename V>
|
||||
struct map_like : std::map<K, V>
|
||||
{
|
||||
template<typename Iter>
|
||||
map_like(Iter f, Iter l)
|
||||
: std::map<K, V>(f, l)
|
||||
{}
|
||||
};
|
||||
|
||||
#if RANGES_CXX_DEDUCTION_GUIDES >= RANGES_CXX_DEDUCTION_GUIDES_17
|
||||
template<typename Iter>
|
||||
map_like(Iter, Iter) -> map_like<typename ranges::iter_value_t<Iter>::first_type,
|
||||
typename ranges::iter_value_t<Iter>::second_type>;
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace ranges;
|
||||
|
||||
{
|
||||
auto lst0 = views::ints | views::transform([](int i) { return i * i; }) |
|
||||
views::take(10) | to<std::list>();
|
||||
CPP_assert(same_as<decltype(lst0), std::list<int>>);
|
||||
::check_equal(lst0, {0, 1, 4, 9, 16, 25, 36, 49, 64, 81});
|
||||
}
|
||||
|
||||
#ifndef RANGES_WORKAROUND_MSVC_779708 // "workaround" is a misnomer; there's no
|
||||
// workaround.
|
||||
{
|
||||
auto lst1 = views::ints | views::transform([](int i) { return i * i; }) |
|
||||
views::take(10) | to<std::list>;
|
||||
CPP_assert(same_as<decltype(lst1), std::list<int>>);
|
||||
::check_equal(lst1, {0, 1, 4, 9, 16, 25, 36, 49, 64, 81});
|
||||
}
|
||||
#endif // RANGES_WORKAROUND_MSVC_779708
|
||||
|
||||
{
|
||||
auto vec0 = views::ints | views::transform([](int i) { return i * i; }) |
|
||||
views::take(10) | to_vector | actions::sort(std::greater<int>{});
|
||||
CPP_assert(same_as<decltype(vec0), std::vector<int>>);
|
||||
::check_equal(vec0, {81, 64, 49, 36, 25, 16, 9, 4, 1, 0});
|
||||
}
|
||||
|
||||
{
|
||||
auto vec1 = views::ints | views::transform([](int i) { return i * i; }) |
|
||||
views::take(10) | to<std::vector<long>>() |
|
||||
actions::sort(std::greater<long>{});
|
||||
CPP_assert(same_as<decltype(vec1), std::vector<long>>);
|
||||
::check_equal(vec1, {81, 64, 49, 36, 25, 16, 9, 4, 1, 0});
|
||||
}
|
||||
|
||||
#ifndef RANGES_WORKAROUND_MSVC_779708
|
||||
{
|
||||
auto vec2 = views::ints | views::transform([](int i) { return i * i; }) |
|
||||
views::take(10) | to<std::vector<long>> |
|
||||
actions::sort(std::greater<long>{});
|
||||
CPP_assert(same_as<decltype(vec2), std::vector<long>>);
|
||||
::check_equal(vec2, {81, 64, 49, 36, 25, 16, 9, 4, 1, 0});
|
||||
}
|
||||
#endif // RANGES_WORKAROUND_MSVC_779708
|
||||
|
||||
{
|
||||
const std::size_t N = 4096;
|
||||
auto vl = views::iota(0, int{N}) | to<vector_like<int>>();
|
||||
CPP_assert(same_as<decltype(vl), vector_like<int>>);
|
||||
CHECK(vl.reservation_count == std::size_t{1});
|
||||
CHECK(vl.last_reservation == N);
|
||||
}
|
||||
|
||||
// https://github.com/ericniebler/range-v3/issues/1145
|
||||
{
|
||||
auto r1 = views::indices(std::uintmax_t{100});
|
||||
auto r2 = views::zip(r1, r1);
|
||||
|
||||
#ifdef RANGES_WORKAROUND_MSVC_779708
|
||||
auto m = r2 | ranges::to<std::map<std::uintmax_t, std::uintmax_t>>();
|
||||
#else // ^^^ workaround / no workaround vvv
|
||||
auto m = r2 | ranges::to<std::map<std::uintmax_t, std::uintmax_t>>;
|
||||
#endif // RANGES_WORKAROUND_MSVC_779708
|
||||
CPP_assert(same_as<decltype(m), std::map<std::uintmax_t, std::uintmax_t>>);
|
||||
}
|
||||
|
||||
// Transform a range-of-ranges into a container of containers
|
||||
{
|
||||
auto r = views::ints(1, 4) |
|
||||
views::transform([](int i) { return views::ints(i, i + 3); });
|
||||
|
||||
auto m = r | ranges::to<std::vector<std::vector<int>>>();
|
||||
CPP_assert(same_as<decltype(m), std::vector<std::vector<int>>>);
|
||||
CHECK(m.size() == 3u);
|
||||
check_equal(m[0], {1, 2, 3});
|
||||
check_equal(m[1], {2, 3, 4});
|
||||
check_equal(m[2], {3, 4, 5});
|
||||
}
|
||||
|
||||
// Use ranges::to in a closure with an action
|
||||
{
|
||||
#ifdef RANGES_WORKAROUND_MSVC_779708
|
||||
auto closure = ranges::to<std::vector>() | actions::sort;
|
||||
#else // ^^^ workaround / no workaround vvv
|
||||
auto closure = ranges::to<std::vector> | actions::sort;
|
||||
#endif // RANGES_WORKAROUND_MSVC_779708
|
||||
|
||||
auto r = views::ints(1, 4) | views::reverse;
|
||||
auto m = r | closure;
|
||||
|
||||
CPP_assert(same_as<decltype(m), std::vector<int>>);
|
||||
CHECK(m.size() == 3u);
|
||||
check_equal(m, {1, 2, 3});
|
||||
}
|
||||
|
||||
test_zip_to_map(views::zip(views::ints, views::iota(0, 10)), 0);
|
||||
|
||||
// https://github.com/ericniebler/range-v3/issues/1544
|
||||
{
|
||||
std::vector<std::vector<int>> d;
|
||||
auto m = views::transform(d, views::all);
|
||||
auto v = ranges::to<std::vector<std::vector<int>>>(m);
|
||||
check_equal(d, v);
|
||||
}
|
||||
|
||||
{
|
||||
std::vector<std::pair<int, int>> v = {{1, 2}, {3, 4}};
|
||||
auto m1 = ranges::to<map_like<int, int>>(v);
|
||||
auto m2 = v | ranges::to<map_like<int, int>>();
|
||||
|
||||
CPP_assert(same_as<decltype(m1), map_like<int, int>>);
|
||||
CPP_assert(same_as<decltype(m2), map_like<int, int>>);
|
||||
check_equal(m1, std::map<int, int>{{1, 2}, {3, 4}});
|
||||
check_equal(m1, m2);
|
||||
|
||||
#if RANGES_CXX_DEDUCTION_GUIDES >= RANGES_CXX_DEDUCTION_GUIDES_17
|
||||
auto m3 = ranges::to<map_like>(v);
|
||||
auto m4 = v | ranges::to<map_like>();
|
||||
CPP_assert(same_as<decltype(m3), map_like<int, int>>);
|
||||
CPP_assert(same_as<decltype(m4), map_like<int, int>>);
|
||||
check_equal(m1, m3);
|
||||
check_equal(m1, m4);
|
||||
#endif
|
||||
}
|
||||
|
||||
return ::test_result();
|
||||
}
|
||||
132
Telegram/ThirdParty/range-v3/test/range/index.cpp
vendored
Normal file
132
Telegram/ThirdParty/range-v3/test/range/index.cpp
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
// Range v3 library
|
||||
//
|
||||
// Copyright Eric Niebler 2014-present
|
||||
// Copyright Gonzalo Brito Gadeschi 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/algorithm/equal.hpp>
|
||||
#include <range/v3/view/c_str.hpp>
|
||||
#include <range/v3/view/iota.hpp>
|
||||
#include <range/v3/core.hpp>
|
||||
#include "../simple_test.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::vector<int> vi{1,2,3,4};
|
||||
CHECK(ranges::index(vi, 0) == 1);
|
||||
CHECK(ranges::index(vi, 1) == 2);
|
||||
CHECK(ranges::index(vi, 2) == 3);
|
||||
CHECK(ranges::index(vi, 3) == 4);
|
||||
|
||||
CHECK(ranges::at(vi, 0) == 1);
|
||||
CHECK(ranges::at(vi, 1) == 2);
|
||||
CHECK(ranges::at(vi, 2) == 3);
|
||||
CHECK(ranges::at(vi, 3) == 4);
|
||||
|
||||
try
|
||||
{
|
||||
ranges::at(vi, 4);
|
||||
CHECK(false);
|
||||
}
|
||||
catch(std::out_of_range const& e)
|
||||
{
|
||||
CHECK(ranges::equal(ranges::views::c_str(e.what()),
|
||||
ranges::views::c_str("ranges::at")));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
ranges::at(vi, -1);
|
||||
CHECK(false);
|
||||
}
|
||||
catch(std::out_of_range const& e)
|
||||
{
|
||||
CHECK(ranges::equal(ranges::views::c_str(e.what()),
|
||||
ranges::views::c_str("ranges::at")));
|
||||
}
|
||||
|
||||
auto viv = ranges::make_subrange(vi.begin(), vi.end());
|
||||
CHECK(viv.at(0) == 1);
|
||||
CHECK(viv.at(1) == 2);
|
||||
CHECK(viv.at(2) == 3);
|
||||
CHECK(viv.at(3) == 4);
|
||||
|
||||
try
|
||||
{
|
||||
viv.at(4);
|
||||
CHECK(false);
|
||||
}
|
||||
catch(std::out_of_range const& e)
|
||||
{
|
||||
CHECK(ranges::equal(ranges::views::c_str(e.what()),
|
||||
ranges::views::c_str("view_interface::at")));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
viv.at(-1);
|
||||
CHECK(false);
|
||||
}
|
||||
catch(std::out_of_range const& e)
|
||||
{
|
||||
CHECK(ranges::equal(ranges::views::c_str(e.what()),
|
||||
ranges::views::c_str("view_interface::at")));
|
||||
}
|
||||
|
||||
const auto cviv = viv;
|
||||
CHECK(cviv.at(0) == 1);
|
||||
CHECK(cviv.at(1) == 2);
|
||||
CHECK(cviv.at(2) == 3);
|
||||
CHECK(cviv.at(3) == 4);
|
||||
|
||||
try
|
||||
{
|
||||
cviv.at(4);
|
||||
CHECK(false);
|
||||
}
|
||||
catch(std::out_of_range const& e)
|
||||
{
|
||||
CHECK(ranges::equal(ranges::views::c_str(e.what()),
|
||||
ranges::views::c_str("view_interface::at")));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
cviv.at(-1);
|
||||
CHECK(false);
|
||||
}
|
||||
catch(std::out_of_range const& e)
|
||||
{
|
||||
CHECK(ranges::equal(ranges::views::c_str(e.what()),
|
||||
ranges::views::c_str("view_interface::at")));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto rng = ranges::views::ints(std::int64_t{0}, std::numeric_limits<std::int64_t>::max());
|
||||
CHECK(ranges::index(rng, std::numeric_limits<std::int64_t>::max() - 1) ==
|
||||
std::numeric_limits<std::int64_t>::max() - 1);
|
||||
CHECK(ranges::at(rng, std::numeric_limits<std::int64_t>::max() - 1) ==
|
||||
std::numeric_limits<std::int64_t>::max() - 1);
|
||||
}
|
||||
|
||||
#if RANGES_CXX_CONSTEXPR >= RANGES_CXX_CONSTEXPR_14
|
||||
{
|
||||
constexpr int vi[4] = {1, 2, 3, 4};
|
||||
constexpr int vi0 = ranges::index(vi, 0);
|
||||
static_assert(vi0 == 1, "");
|
||||
constexpr int vi1 = ranges::at(vi, 1);
|
||||
static_assert(vi1 == 2, "");
|
||||
}
|
||||
#endif
|
||||
|
||||
return ::test_result();
|
||||
}
|
||||
159
Telegram/ThirdParty/range-v3/test/range/operations.cpp
vendored
Normal file
159
Telegram/ThirdParty/range-v3/test/range/operations.cpp
vendored
Normal file
@@ -0,0 +1,159 @@
|
||||
// Range v3 library
|
||||
//
|
||||
// Copyright Eric Niebler 2014-present
|
||||
// Copyright Michel Morin 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 <forward_list>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <limits>
|
||||
#include <range/v3/core.hpp>
|
||||
#include <range/v3/view/iota.hpp>
|
||||
#include <range/v3/view/take_while.hpp>
|
||||
#include "../array.hpp"
|
||||
#include "../simple_test.hpp"
|
||||
#include "../test_utils.hpp"
|
||||
|
||||
template<typename I, typename S>
|
||||
void test_iterators(I first, S last, ranges::iter_difference_t<I> n)
|
||||
{
|
||||
using namespace ranges;
|
||||
|
||||
CHECK(distance(first, last) == n);
|
||||
CHECK(distance_compare(first, last, n) == 0);
|
||||
CHECK(distance_compare(first, last, n - 1) > 0);
|
||||
CHECK(distance_compare(first, last, n + 1) < 0);
|
||||
CHECK(distance_compare(first, last, (std::numeric_limits<iter_difference_t<I>>::min)()) > 0);
|
||||
CHECK(distance_compare(first, last, (std::numeric_limits<iter_difference_t<I>>::max)()) < 0);
|
||||
}
|
||||
|
||||
template<typename Rng>
|
||||
void test_range(Rng&& rng, ranges::range_difference_t<Rng> n)
|
||||
{
|
||||
using namespace ranges;
|
||||
|
||||
CHECK(distance(rng) == n);
|
||||
CHECK(distance_compare(rng, n) == 0);
|
||||
CHECK(distance_compare(rng, n - 1) > 0);
|
||||
CHECK(distance_compare(rng, n + 1) < 0);
|
||||
CHECK(distance_compare(rng, (std::numeric_limits<range_difference_t<Rng>>::min)()) > 0);
|
||||
CHECK(distance_compare(rng, (std::numeric_limits<range_difference_t<Rng>>::max)()) < 0);
|
||||
}
|
||||
|
||||
template<typename Rng>
|
||||
void test_infinite_range(Rng&& rng)
|
||||
{
|
||||
using namespace ranges;
|
||||
|
||||
CHECK(distance_compare(rng, 0) > 0);
|
||||
CHECK(distance_compare(rng,-1) > 0);
|
||||
CHECK(distance_compare(rng, 1) > 0);
|
||||
CHECK(distance_compare(rng, (std::numeric_limits<range_difference_t<Rng>>::min)()) > 0);
|
||||
if (is_infinite<Rng>::value) {
|
||||
// For infinite ranges that can be detected by is_infinite<Rng> traits,
|
||||
// distance_compare can compute the result in constant time.
|
||||
CHECK(distance_compare(rng, (std::numeric_limits<range_difference_t<Rng>>::max)()) > 0);
|
||||
}
|
||||
else {
|
||||
// For other infinite ranges, comparing to a huge number might take too much time.
|
||||
// Thus commented out the test.
|
||||
// CHECK(distance_compare(rng, (std::numeric_limits<range_difference_t<Rng>>::max)()) > 0);
|
||||
}
|
||||
}
|
||||
|
||||
constexpr bool test_constexpr()
|
||||
{
|
||||
using namespace ranges;
|
||||
|
||||
auto rng = test::array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};
|
||||
using Rng = decltype(rng);
|
||||
auto bit = ranges::begin(rng);
|
||||
using I = decltype(bit);
|
||||
auto it = bit + 5;
|
||||
auto eit = ranges::end(rng);
|
||||
auto n = ranges::distance(rng);
|
||||
auto en = ranges::enumerate(rng);
|
||||
STATIC_CHECK_RETURN(n == 10);
|
||||
STATIC_CHECK_RETURN(distance(bit, eit) == n);
|
||||
STATIC_CHECK_RETURN(distance(it, eit) == 5);
|
||||
STATIC_CHECK_RETURN(distance_compare(bit, eit, n) == 0);
|
||||
STATIC_CHECK_RETURN(distance_compare(bit, eit, n - 1) > 0);
|
||||
STATIC_CHECK_RETURN(distance_compare(bit, eit, n + 1) < 0);
|
||||
STATIC_CHECK_RETURN(distance_compare(bit, eit, (std::numeric_limits<iter_difference_t<I>>::min)()) > 0);
|
||||
STATIC_CHECK_RETURN(distance_compare(bit, eit, (std::numeric_limits<iter_difference_t<I>>::max)()) < 0);
|
||||
STATIC_CHECK_RETURN(distance(rng) == n);
|
||||
STATIC_CHECK_RETURN(distance_compare(rng, n) == 0);
|
||||
STATIC_CHECK_RETURN(distance_compare(rng, n - 1) > 0);
|
||||
STATIC_CHECK_RETURN(distance_compare(rng, n + 1) < 0);
|
||||
STATIC_CHECK_RETURN(distance_compare(rng, (std::numeric_limits<range_difference_t<Rng>>::min)()) > 0);
|
||||
STATIC_CHECK_RETURN(distance_compare(rng, (std::numeric_limits<range_difference_t<Rng>>::max)()) < 0);
|
||||
|
||||
STATIC_CHECK_RETURN(en.first == 10);
|
||||
STATIC_CHECK_RETURN(en.second == eit);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace ranges;
|
||||
|
||||
{
|
||||
using cont_t = std::vector<int>;
|
||||
cont_t c {1, 2, 3, 4};
|
||||
test_range(c, 4);
|
||||
test_iterators(c.begin(), c.end(), 4);
|
||||
|
||||
c.clear();
|
||||
test_range(c, 0);
|
||||
test_iterators(c.begin(), c.end(), 0);
|
||||
}
|
||||
|
||||
{
|
||||
using cont_t = std::list<int>;
|
||||
cont_t c {1, 2, 3, 4};
|
||||
test_range(c, 4);
|
||||
test_iterators(c.begin(), c.end(), 4);
|
||||
|
||||
c.clear();
|
||||
test_range(c, 0);
|
||||
test_iterators(c.begin(), c.end(), 0);
|
||||
}
|
||||
|
||||
{
|
||||
using cont_t = std::forward_list<int>;
|
||||
cont_t c {1, 2, 3, 4};
|
||||
test_range(c, 4);
|
||||
test_iterators(c.begin(), c.end(), 4);
|
||||
|
||||
c.clear();
|
||||
test_range(c, 0);
|
||||
test_iterators(c.begin(), c.end(), 0);
|
||||
}
|
||||
|
||||
{
|
||||
int a[] = {1, 2, 3, 4};
|
||||
test_iterators(a + 4, a, -4);
|
||||
}
|
||||
|
||||
{
|
||||
test_range(views::iota(0) | views::take_while([](int i) { return i < 4; }), 4);
|
||||
}
|
||||
|
||||
{
|
||||
test_infinite_range(views::iota(0u));
|
||||
}
|
||||
|
||||
{
|
||||
STATIC_CHECK(test_constexpr());
|
||||
}
|
||||
|
||||
return ::test_result();
|
||||
}
|
||||
Reference in New Issue
Block a user