// 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 #include #include #include #include "../simple_test.hpp" #include "../test_iterators.hpp" int comparison_count = 0; template 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(ia), RandomAccessIterator(ia + as), RandomAccessIterator(ib), RandomAccessIterator(ib + bs))); CHECK(!ends_with(InputIterator(ia), InputIterator(ia + as), InputIterator(ib), InputIterator(ib + bs - 1))); CHECK(!ends_with(ForwardIterator(ia), Sentinel(ia + as), ForwardIterator(ib), Sentinel(ib + bs - 1))); CHECK(!ends_with(make_subrange(RandomAccessIterator(ia), RandomAccessIterator(ia + as)), make_subrange(RandomAccessIterator(ib), RandomAccessIterator(ib + bs - 1)))); CHECK(ends_with(make_subrange(InputIterator(ia), InputIterator(ia + as)), make_subrange(InputIterator(ib), InputIterator(ib + bs)))); CHECK(ends_with(make_subrange(ForwardIterator(ia), Sentinel(ia + as)), make_subrange(ForwardIterator(ib), Sentinel(ib + bs)))); comparison_count = 0; CHECK(!ends_with(RandomAccessIterator(ib), RandomAccessIterator(ib + bs), RandomAccessIterator(ia), RandomAccessIterator(ia + as), counting_equals)); CHECK(comparison_count == 0); comparison_count = 0; CHECK(ends_with(InputIterator(ia), InputIterator(ia + as), InputIterator(ib), InputIterator(ib + bs), counting_equals)); CHECK(comparison_count > 0); comparison_count = 0; CHECK(ends_with(ForwardIterator(ia), Sentinel(ia + as), ForwardIterator(ib), Sentinel(ib + bs), counting_equals)); CHECK(comparison_count > 0); comparison_count = 0; CHECK(ends_with(make_subrange(RandomAccessIterator(ia), RandomAccessIterator(ia + as)), make_subrange(RandomAccessIterator(ib), RandomAccessIterator(ib + bs)), counting_equals)); CHECK(comparison_count > 0); comparison_count = 0; CHECK(!ends_with(make_subrange(InputIterator(ib), InputIterator(ib + bs - 1)), make_subrange(InputIterator(ib), InputIterator(ib + bs)), counting_equals)); CHECK(comparison_count == 0); comparison_count = 0; CHECK(!ends_with(make_subrange(ForwardIterator(ia), Sentinel(ia)), make_subrange(ForwardIterator(ib), Sentinel(ib + bs)), counting_equals)); CHECK(comparison_count == 0); #if RANGES_CXX_CONSTEXPR >= RANGES_CXX_CONSTEXPR_14 && RANGES_CONSTEXPR_INVOKE using IL = std::initializer_list; 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(); }