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/algorithm/equal.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 <range/v3/core.hpp> #include <range/v3/algorithm/equal.hpp> #include <range/v3/view/unbounded.hpp> #include "../simple_test.hpp" #include "../test_iterators.hpp" RANGES_DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS void test() { using namespace ranges; int ia[] = {0, 1, 2, 3, 4, 5}; constexpr auto s = size(ia); int ib[s] = {0, 1, 2, 5, 4, 5}; CHECK(equal(InputIterator<const int*>(ia), Sentinel<const int*>(ia+s), InputIterator<const int*>(ia))); CHECK(equal(InputIterator<const int*>(ia), Sentinel<const int*>(ia+s), InputIterator<const int*>(ia), Sentinel<const int*>(ia+s))); CHECK(equal(RandomAccessIterator<const int*>(ia), RandomAccessIterator<const int*>(ia+s), RandomAccessIterator<const int*>(ia), RandomAccessIterator<const int*>(ia + s))); CHECK(equal(RandomAccessIterator<const int*>(ia), Sentinel<const int*>(ia+s), RandomAccessIterator<const int*>(ia), Sentinel<const int*>(ia + s))); CHECK(!equal(InputIterator<const int*>(ia), Sentinel<const int*>(ia+s), InputIterator<const int*>(ib))); CHECK(!equal(InputIterator<const int*>(ia), Sentinel<const int*>(ia+s), InputIterator<const int*>(ib), Sentinel<const int*>(ib + s))); CHECK(!equal(RandomAccessIterator<const int*>(ia), RandomAccessIterator<const int*>(ia+s), RandomAccessIterator<const int*>(ib), RandomAccessIterator<const int*>(ib+s))); CHECK(!equal(RandomAccessIterator<const int*>(ia), Sentinel<const int*>(ia+s), RandomAccessIterator<const int*>(ib), Sentinel<const int*>(ib + s))); CHECK(!equal(InputIterator<const int*>(ia), Sentinel<const int*>(ia+s), InputIterator<const int*>(ia), Sentinel<const int*>(ia + s - 1))); CHECK(!equal(RandomAccessIterator<const int*>(ia), RandomAccessIterator<const int*>(ia+s), RandomAccessIterator<const int*>(ia), RandomAccessIterator<const int*>(ia+s-1))); CHECK(!equal(RandomAccessIterator<const int*>(ia), Sentinel<const int*>(ia+s), RandomAccessIterator<const int*>(ia), Sentinel<const int*>(ia + s - 1))); } void test_rng() { using namespace ranges; int ia[] = {0, 1, 2, 3, 4, 5}; constexpr auto s = size(ia); int ib[s] = {0, 1, 2, 5, 4, 5}; CHECK(equal(make_subrange(InputIterator<const int*>(ia), Sentinel<const int*>(ia+s)), InputIterator<const int*>(ia))); CHECK(equal(make_subrange(InputIterator<const int*>(ia), Sentinel<const int*>(ia+s)), make_subrange(InputIterator<const int*>(ia), Sentinel<const int*>(ia+s)))); CHECK(equal(make_subrange(RandomAccessIterator<const int*>(ia), RandomAccessIterator<const int*>(ia+s)), make_subrange(RandomAccessIterator<const int*>(ia), RandomAccessIterator<const int*>(ia + s)))); CHECK(equal(make_subrange(RandomAccessIterator<const int*>(ia), Sentinel<const int*>(ia+s)), make_subrange(RandomAccessIterator<const int*>(ia), Sentinel<const int*>(ia + s)))); CHECK(!equal(make_subrange(InputIterator<const int*>(ia), Sentinel<const int*>(ia+s)), InputIterator<const int*>(ib))); CHECK(!equal(make_subrange(InputIterator<const int*>(ia), Sentinel<const int*>(ia+s)), make_subrange(InputIterator<const int*>(ib), Sentinel<const int*>(ib + s)))); CHECK(!equal(make_subrange(RandomAccessIterator<const int*>(ia), RandomAccessIterator<const int*>(ia+s)), make_subrange(RandomAccessIterator<const int*>(ib), RandomAccessIterator<const int*>(ib+s)))); CHECK(!equal(make_subrange(RandomAccessIterator<const int*>(ia), Sentinel<const int*>(ia+s)), make_subrange(RandomAccessIterator<const int*>(ib), Sentinel<const int*>(ib + s)))); CHECK(!equal(make_subrange(InputIterator<const int*>(ia), Sentinel<const int*>(ia+s)), make_subrange(InputIterator<const int*>(ia), Sentinel<const int*>(ia + s - 1)))); CHECK(!equal(make_subrange(RandomAccessIterator<const int*>(ia), RandomAccessIterator<const int*>(ia+s)), make_subrange(RandomAccessIterator<const int*>(ia), RandomAccessIterator<const int*>(ia+s-1)))); CHECK(!equal(make_subrange(RandomAccessIterator<const int*>(ia), Sentinel<const int*>(ia+s)), make_subrange(RandomAccessIterator<const int*>(ia), Sentinel<const int*>(ia + s - 1)))); } int comparison_count = 0; template<typename T> bool counting_equals(const T &a, const T &b) { ++comparison_count; return a == b; } void test_pred() { using namespace ranges; int ia[] = {0, 1, 2, 3, 4, 5}; constexpr auto s = size(ia); int ib[s] = {0, 1, 2, 5, 4, 5}; CHECK(equal(InputIterator<const int*>(ia), Sentinel<const int*>(ia+s), InputIterator<const int*>(ia), std::equal_to<int>())); CHECK(equal(InputIterator<const int*>(ia), Sentinel<const int*>(ia+s), InputIterator<const int*>(ia), Sentinel<const int*>(ia + s), std::equal_to<int>())); CHECK(equal(RandomAccessIterator<const int*>(ia), RandomAccessIterator<const int*>(ia+s), RandomAccessIterator<const int*>(ia), RandomAccessIterator<const int*>(ia+s), std::equal_to<int>())); CHECK(equal(RandomAccessIterator<const int*>(ia), Sentinel<const int*>(ia+s), RandomAccessIterator<const int*>(ia), Sentinel<const int*>(ia + s), std::equal_to<int>())); comparison_count = 0; CHECK(!equal(InputIterator<const int*>(ia), Sentinel<const int*>(ia+s), InputIterator<const int*>(ia), Sentinel<const int*>(ia + s - 1), counting_equals<int>)); CHECK(comparison_count > 0); comparison_count = 0; CHECK(!equal(RandomAccessIterator<const int*>(ia), RandomAccessIterator<const int*>(ia+s), RandomAccessIterator<const int*>(ia), RandomAccessIterator<const int*>(ia+s-1), counting_equals<int>)); CHECK(comparison_count == 0); comparison_count = 0; CHECK(!equal(RandomAccessIterator<const int*>(ia), Sentinel<const int*>(ia+s), RandomAccessIterator<const int*>(ia), Sentinel<const int*>(ia + s - 1), counting_equals<int>)); CHECK(comparison_count > 0); CHECK(!equal(InputIterator<const int*>(ia), Sentinel<const int*>(ia+s), InputIterator<const int*>(ib), std::equal_to<int>())); CHECK(!equal(InputIterator<const int*>(ia), Sentinel<const int*>(ia+s), InputIterator<const int*>(ib), Sentinel<const int*>(ib + s), std::equal_to<int>())); CHECK(!equal(RandomAccessIterator<const int*>(ia), RandomAccessIterator<const int*>(ia+s), RandomAccessIterator<const int*>(ib), RandomAccessIterator<const int*>(ib+s), std::equal_to<int>())); CHECK(!equal(RandomAccessIterator<const int*>(ia), Sentinel<const int*>(ia+s), RandomAccessIterator<const int*>(ib), Sentinel<const int*>(ib + s), std::equal_to<int>())); } void test_rng_pred() { using namespace ranges; int ia[] = {0, 1, 2, 3, 4, 5}; constexpr auto s = size(ia); int ib[s] = {0, 1, 2, 5, 4, 5}; CHECK(equal(make_subrange(InputIterator<const int*>(ia), Sentinel<const int*>(ia+s)), InputIterator<const int*>(ia), std::equal_to<int>())); CHECK(equal(make_subrange(InputIterator<const int*>(ia), Sentinel<const int*>(ia+s)), make_subrange(InputIterator<const int*>(ia), Sentinel<const int*>(ia + s)), std::equal_to<int>())); CHECK(equal(make_subrange(RandomAccessIterator<const int*>(ia), RandomAccessIterator<const int*>(ia+s)), make_subrange(RandomAccessIterator<const int*>(ia), RandomAccessIterator<const int*>(ia+s)), std::equal_to<int>())); CHECK(equal(make_subrange(RandomAccessIterator<const int*>(ia), Sentinel<const int*>(ia+s)), make_subrange(RandomAccessIterator<const int*>(ia), Sentinel<const int*>(ia + s)), std::equal_to<int>())); comparison_count = 0; CHECK(!equal(make_subrange(InputIterator<const int*>(ia), Sentinel<const int*>(ia+s)), make_subrange(InputIterator<const int*>(ia), Sentinel<const int*>(ia + s - 1)), counting_equals<int>)); CHECK(comparison_count > 0); comparison_count = 0; CHECK(!equal(make_subrange(RandomAccessIterator<const int*>(ia), RandomAccessIterator<const int*>(ia+s)), make_subrange(RandomAccessIterator<const int*>(ia), RandomAccessIterator<const int*>(ia+s-1)), counting_equals<int>)); CHECK(comparison_count == 0); comparison_count = 0; CHECK(!equal(make_subrange(RandomAccessIterator<const int*>(ia), Sentinel<const int*>(ia+s)), make_subrange(RandomAccessIterator<const int*>(ia), Sentinel<const int*>(ia + s - 1)), counting_equals<int>)); CHECK(comparison_count > 0); CHECK(!equal(make_subrange(InputIterator<const int*>(ia), Sentinel<const int*>(ia+s)), InputIterator<const int*>(ib), std::equal_to<int>())); CHECK(!equal(make_subrange(InputIterator<const int*>(ia), Sentinel<const int*>(ia+s)), make_subrange(InputIterator<const int*>(ib), Sentinel<const int*>(ib + s)), std::equal_to<int>())); CHECK(!equal(make_subrange(RandomAccessIterator<const int*>(ia), RandomAccessIterator<const int*>(ia+s)), make_subrange(RandomAccessIterator<const int*>(ib), RandomAccessIterator<const int*>(ib+s)), std::equal_to<int>())); CHECK(!equal(make_subrange(RandomAccessIterator<const int*>(ia), Sentinel<const int*>(ia+s)), make_subrange(RandomAccessIterator<const int*>(ib), Sentinel<const int*>(ib + s)), std::equal_to<int>())); } int main() { ::test(); ::test_rng(); ::test_pred(); ::test_rng_pred(); using IL = std::initializer_list<int>; int *p = nullptr; static_assert(std::is_same<bool, decltype(ranges::equal(IL{1, 2, 3, 4}, p))>::value, ""); static_assert(std::is_same<bool, decltype(ranges::equal(IL{1, 2, 3, 4}, IL{1, 2, 3, 4}))>::value, ""); static_assert(std::is_same<bool, decltype(ranges::equal(IL{1, 2, 3, 4}, ranges::views::unbounded(p)))>::value, ""); #if RANGES_CXX_CONSTEXPR >= RANGES_CXX_CONSTEXPR_14 && RANGES_CONSTEXPR_INVOKE static_assert(ranges::equal(IL{1, 2, 3, 4}, IL{1, 2, 3, 4}), ""); static_assert(!ranges::equal(IL{1, 2, 3, 4}, IL{1, 2, 3}), ""); static_assert(!ranges::equal(IL{1, 2, 3, 4}, IL{1, 2, 4, 3}), ""); static_assert(ranges::equal(IL{}, IL{}), ""); #endif return ::test_result(); }
0
repos/range-v3/test
repos/range-v3/test/algorithm/is_sorted_until.cpp
// Range v3 library // // Copyright Eric Niebler 2014-present // 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 // // 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/algorithm/is_sorted_until.hpp> #include <range/v3/core.hpp> #include "../array.hpp" #include "../simple_test.hpp" #include "../test_iterators.hpp" #include "../test_utils.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) -> decltype(ranges::is_sorted_until(begin_t{It}, sentinel_t{e}, std::forward<Args>(args)...)) { return ranges::is_sorted_until( 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> static auto _impl(B && It, E && e, Args &&... args) -> decltype(ranges::is_sorted_until( ::as_lvalue(ranges::make_subrange(begin_t{It}, sentinel_t{e})), std::forward<Args>(args)...)) { return ranges::is_sorted_until( ::as_lvalue(ranges::make_subrange(begin_t{It}, sentinel_t{e})), std::forward<Args>(args)...); } template<class B, class E> auto operator()(B && It, E && e) const -> decltype(ranges::is_sorted_until( ::as_lvalue(ranges::make_subrange(begin_t{It}, sentinel_t{e})))) { return range_call::_impl(static_cast<B &&>(It), static_cast<E &&>(e)); } template<class B, class E, class A0> auto operator()(B && It, E && e, A0 && a0) const -> decltype(ranges::is_sorted_until(::as_lvalue( ranges::make_subrange(begin_t{It}, sentinel_t{e})), static_cast<A0 &&>(a0))) { return range_call::_impl( static_cast<B &&>(It), static_cast<E &&>(e), static_cast<A0 &&>(a0)); } template<class B, class E, class A0, class A1> auto operator()(B && It, E && e, A0 && a0, A1 && a1) const -> decltype(ranges::is_sorted_until(::as_lvalue(ranges::make_subrange( begin_t{It}, sentinel_t{e})), static_cast<A0 &&>(a0), static_cast<A1 &&>(a1))) { return range_call::_impl( static_cast<B &&>(It), static_cast<E &&>(e), static_cast<A0 &&>(a0), static_cast<A1 &&>(a1)); } }; template<class It, template<class> class FunT> void test_basic() { using Fun = FunT<It>; { int a[] = {0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a) == It(a)); CHECK(Fun{}(a, a + sa) == It(a + sa)); } { int a[] = {0, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa) == It(a + sa)); } { int a[] = {0, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa) == It(a + sa)); } { int a[] = {1, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa) == It(a + 1)); } { int a[] = {1, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa) == It(a + sa)); } { int a[] = {0, 0, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa) == It(a + sa)); } { int a[] = {0, 0, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa) == It(a + sa)); } { int a[] = {0, 1, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa) == It(a + 2)); } { int a[] = {0, 1, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa) == It(a + sa)); } { int a[] = {1, 0, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa) == It(a + 1)); } { int a[] = {1, 0, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa) == It(a + 1)); } { int a[] = {1, 1, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa) == It(a + 2)); } { int a[] = {1, 1, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa) == It(a + sa)); } { int a[] = {0, 0, 0, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa) == It(a + sa)); } { int a[] = {0, 0, 0, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa) == It(a + sa)); } { int a[] = {0, 0, 1, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa) == It(a + 3)); } { int a[] = {0, 0, 1, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa) == It(a + sa)); } { int a[] = {0, 1, 0, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa) == It(a + 2)); } { int a[] = {0, 1, 0, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa) == It(a + 2)); } { int a[] = {0, 1, 1, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa) == It(a + 3)); } { int a[] = {0, 1, 1, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa) == It(a + sa)); } { int a[] = {1, 0, 0, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa) == It(a + 1)); } { int a[] = {1, 0, 0, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa) == It(a + 1)); } { int a[] = {1, 0, 1, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa) == It(a + 1)); } { int a[] = {1, 0, 1, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa) == It(a + 1)); } { int a[] = {1, 1, 0, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa) == It(a + 2)); } { int a[] = {1, 1, 0, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa) == It(a + 2)); } { int a[] = {1, 1, 1, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa) == It(a + 3)); } { int a[] = {1, 1, 1, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa) == It(a + sa)); } { int a[] = {0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a, std::greater<int>()) == It(a)); CHECK(Fun{}(a, a + sa, std::greater<int>()) == It(a + sa)); } { int a[] = {0, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>()) == It(a + sa)); } { int a[] = {0, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>()) == It(a + 1)); } { int a[] = {1, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>()) == It(a + sa)); } { int a[] = {1, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>()) == It(a + sa)); } { int a[] = {0, 0, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>()) == It(a + sa)); } { int a[] = {0, 0, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>()) == It(a + 2)); } { int a[] = {0, 1, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>()) == It(a + 1)); } { int a[] = {0, 1, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>()) == It(a + 1)); } { int a[] = {1, 0, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>()) == It(a + sa)); } { int a[] = {1, 0, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>()) == It(a + 2)); } { int a[] = {1, 1, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>()) == It(a + sa)); } { int a[] = {1, 1, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>()) == It(a + sa)); } { int a[] = {0, 0, 0, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>()) == It(a + sa)); } { int a[] = {0, 0, 0, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>()) == It(a + 3)); } { int a[] = {0, 0, 1, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>()) == It(a + 2)); } { int a[] = {0, 0, 1, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>()) == It(a + 2)); } { int a[] = {0, 1, 0, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>()) == It(a + 1)); } { int a[] = {0, 1, 0, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>()) == It(a + 1)); } { int a[] = {0, 1, 1, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>()) == It(a + 1)); } { int a[] = {0, 1, 1, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>()) == It(a + 1)); } { int a[] = {1, 0, 0, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>()) == It(a + sa)); } { int a[] = {1, 0, 0, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>()) == It(a + 3)); } { int a[] = {1, 0, 1, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>()) == It(a + 2)); } { int a[] = {1, 0, 1, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>()) == It(a + 2)); } { int a[] = {1, 1, 0, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>()) == It(a + sa)); } { int a[] = {1, 1, 0, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>()) == It(a + 3)); } { int a[] = {1, 1, 1, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>()) == It(a + sa)); } { int a[] = {1, 1, 1, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>()) == It(a + sa)); } } struct A { int a; }; constexpr bool test_constexpr() { test::array<int, 4> a{{1, 2, 3, 4}}; auto b = ranges::begin(a); auto b1 = ++b; auto end = ranges::end(a); STATIC_CHECK_RETURN(ranges::is_sorted_until(a) == end); STATIC_CHECK_RETURN(ranges::is_sorted_until(a, std::less<>{}) == end); STATIC_CHECK_RETURN(ranges::is_sorted_until(a, std::greater<>{}) == b1); return true; } int main() { test_basic<ForwardIterator<const int *>, iter_call>(); test_basic<BidirectionalIterator<const int *>, iter_call>(); test_basic<RandomAccessIterator<const int *>, iter_call>(); test_basic<const int *, iter_call>(); test_basic<ForwardIterator<const int *>, range_call>(); test_basic<BidirectionalIterator<const int *>, range_call>(); test_basic<RandomAccessIterator<const int *>, range_call>(); test_basic<const int *, range_call>(); /// Initializer list test: { std::initializer_list<int> r = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; CHECK(ranges::is_sorted_until(r) == ranges::end(r)); } /// Projection test: { A as[] = {{0}, {1}, {2}, {3}, {4}}; CHECK(ranges::is_sorted_until(as, std::less<int>{}, &A::a) == ranges::end(as)); CHECK(ranges::is_sorted_until(as, std::greater<int>{}, &A::a) == ranges::next(ranges::begin(as), 1)); } /// Rvalue range test: { A as[] = {{0}, {1}, {2}, {3}, {4}}; #ifndef RANGES_WORKAROUND_MSVC_573728 CHECK(::is_dangling( ranges::is_sorted_until(std::move(as), std::less<int>{}, &A::a))); CHECK(::is_dangling( ranges::is_sorted_until(std::move(as), std::greater<int>{}, &A::a))); #endif // RANGES_WORKAROUND_MSVC_573728 std::vector<A> vec(ranges::begin(as), ranges::end(as)); CHECK(::is_dangling( ranges::is_sorted_until(std::move(vec), std::less<int>{}, &A::a))); CHECK(::is_dangling( ranges::is_sorted_until(std::move(vec), std::greater<int>{}, &A::a))); } { STATIC_CHECK(test_constexpr()); } return ::test_result(); }
0
repos/range-v3/test
repos/range-v3/test/algorithm/find_first_of.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 <range/v3/core.hpp> #include <range/v3/algorithm/find_first_of.hpp> #include "../simple_test.hpp" #include "../test_iterators.hpp" #include "../test_utils.hpp" namespace rng = ranges; void test_iter() { using namespace ranges; int ia[] = {0, 1, 2, 3, 0, 1, 2, 3}; static constexpr auto sa = size(ia); int ib[] = {1, 3, 5, 7}; static constexpr auto sb = size(ib); CHECK(rng::find_first_of(InputIterator<const int*>(ia), Sentinel<const int*>(ia + sa), ForwardIterator<const int*>(ib), Sentinel<const int*>(ib + sb)) == InputIterator<const int*>(ia+1)); int ic[] = {7}; CHECK(rng::find_first_of(InputIterator<const int*>(ia), Sentinel<const int*>(ia + sa), ForwardIterator<const int*>(ic), Sentinel<const int*>(ic + 1)) == InputIterator<const int*>(ia+sa)); CHECK(rng::find_first_of(InputIterator<const int*>(ia), Sentinel<const int*>(ia + sa), ForwardIterator<const int*>(ic), Sentinel<const int*>(ic)) == InputIterator<const int*>(ia+sa)); CHECK(rng::find_first_of(InputIterator<const int*>(ia), Sentinel<const int*>(ia), ForwardIterator<const int*>(ic), Sentinel<const int*>(ic+1)) == InputIterator<const int*>(ia)); } void test_iter_pred() { using namespace ranges; int ia[] = {0, 1, 2, 3, 0, 1, 2, 3}; static constexpr auto sa = size(ia); int ib[] = {1, 3, 5, 7}; static constexpr auto sb = size(ib); CHECK(rng::find_first_of(InputIterator<const int*>(ia), Sentinel<const int*>(ia + sa), ForwardIterator<const int*>(ib), Sentinel<const int*>(ib + sb), std::equal_to<int>()) == InputIterator<const int*>(ia+1)); int ic[] = {7}; CHECK(rng::find_first_of(InputIterator<const int*>(ia), Sentinel<const int*>(ia + sa), ForwardIterator<const int*>(ic), Sentinel<const int*>(ic + 1), std::equal_to<int>()) == InputIterator<const int*>(ia+sa)); CHECK(rng::find_first_of(InputIterator<const int*>(ia), Sentinel<const int*>(ia + sa), ForwardIterator<const int*>(ic), Sentinel<const int*>(ic), std::equal_to<int>()) == InputIterator<const int*>(ia+sa)); CHECK(rng::find_first_of(InputIterator<const int*>(ia), Sentinel<const int*>(ia), ForwardIterator<const int*>(ic), Sentinel<const int*>(ic+1), std::equal_to<int>()) == InputIterator<const int*>(ia)); } void test_rng() { using namespace ranges; int ia[] = {0, 1, 2, 3, 0, 1, 2, 3}; static constexpr auto sa = size(ia); int ib[] = {1, 3, 5, 7}; static constexpr auto sb = size(ib); CHECK(rng::find_first_of(make_subrange(InputIterator<const int*>(ia), InputIterator<const int*>(ia + sa)), make_subrange(ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sb))) == InputIterator<const int*>(ia+1)); CHECK(::is_dangling(rng::find_first_of(::MakeTestRange(InputIterator<const int*>(ia), InputIterator<const int*>(ia + sa)), make_subrange(ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sb))))); int ic[] = {7}; CHECK(rng::find_first_of(make_subrange(InputIterator<const int*>(ia), InputIterator<const int*>(ia + sa)), make_subrange(ForwardIterator<const int*>(ic), ForwardIterator<const int*>(ic + 1))) == InputIterator<const int*>(ia+sa)); CHECK(rng::find_first_of(make_subrange(InputIterator<const int*>(ia), InputIterator<const int*>(ia + sa)), make_subrange(ForwardIterator<const int*>(ic), ForwardIterator<const int*>(ic))) == InputIterator<const int*>(ia+sa)); CHECK(rng::find_first_of(make_subrange(InputIterator<const int*>(ia), InputIterator<const int*>(ia)), make_subrange(ForwardIterator<const int*>(ic), ForwardIterator<const int*>(ic+1))) == InputIterator<const int*>(ia)); CHECK(::is_dangling(rng::find_first_of(::MakeTestRange(InputIterator<const int*>(ia), InputIterator<const int*>(ia + sa)), make_subrange(ForwardIterator<const int*>(ic), ForwardIterator<const int*>(ic + 1))))); CHECK(::is_dangling(rng::find_first_of(::MakeTestRange(InputIterator<const int*>(ia), InputIterator<const int*>(ia + sa)), make_subrange(ForwardIterator<const int*>(ic), ForwardIterator<const int*>(ic))))); CHECK(::is_dangling(rng::find_first_of(::MakeTestRange(InputIterator<const int*>(ia), InputIterator<const int*>(ia)), make_subrange(ForwardIterator<const int*>(ic), ForwardIterator<const int*>(ic+1))))); } void test_rng_pred() { using namespace ranges; int ia[] = {0, 1, 2, 3, 0, 1, 2, 3}; static constexpr auto sa = size(ia); int ib[] = {1, 3, 5, 7}; static constexpr auto sb = size(ib); CHECK(rng::find_first_of(make_subrange(InputIterator<const int*>(ia), InputIterator<const int*>(ia + sa)), make_subrange(ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sb)), std::equal_to<int>()) == InputIterator<const int*>(ia+1)); int ic[] = {7}; CHECK(rng::find_first_of(make_subrange(InputIterator<const int*>(ia), InputIterator<const int*>(ia + sa)), make_subrange(ForwardIterator<const int*>(ic), ForwardIterator<const int*>(ic + 1)), std::equal_to<int>()) == InputIterator<const int*>(ia+sa)); CHECK(rng::find_first_of(make_subrange(InputIterator<const int*>(ia), InputIterator<const int*>(ia + sa)), make_subrange(ForwardIterator<const int*>(ic), ForwardIterator<const int*>(ic)), std::equal_to<int>()) == InputIterator<const int*>(ia+sa)); CHECK(rng::find_first_of(make_subrange(InputIterator<const int*>(ia), InputIterator<const int*>(ia)), make_subrange(ForwardIterator<const int*>(ic), ForwardIterator<const int*>(ic+1)), std::equal_to<int>()) == InputIterator<const int*>(ia)); } struct S { int i; }; void test_rng_pred_proj() { using namespace ranges; S ia[] = {S{0}, S{1}, S{2}, S{3}, S{0}, S{1}, S{2}, S{3}}; static constexpr auto sa = size(ia); S ib[] = {S{1}, S{3}, S{5}, S{7}}; static constexpr auto sb = size(ib); CHECK(rng::find_first_of(make_subrange(InputIterator<const S*>(ia), InputIterator<const S*>(ia + sa)), make_subrange(ForwardIterator<const S*>(ib), ForwardIterator<const S*>(ib + sb)), std::equal_to<int>(), &S::i, &S::i) == InputIterator<const S*>(ia+1)); S ic[] = {S{7}}; CHECK(rng::find_first_of(make_subrange(InputIterator<const S*>(ia), InputIterator<const S*>(ia + sa)), make_subrange(ForwardIterator<const S*>(ic), ForwardIterator<const S*>(ic + 1)), std::equal_to<int>(), &S::i, &S::i) == InputIterator<const S*>(ia+sa)); CHECK(rng::find_first_of(make_subrange(InputIterator<const S*>(ia), InputIterator<const S*>(ia + sa)), make_subrange(ForwardIterator<const S*>(ic), ForwardIterator<const S*>(ic)), std::equal_to<int>(), &S::i, &S::i) == InputIterator<const S*>(ia+sa)); CHECK(rng::find_first_of(make_subrange(InputIterator<const S*>(ia), InputIterator<const S*>(ia)), make_subrange(ForwardIterator<const S*>(ic), ForwardIterator<const S*>(ic+1)), std::equal_to<int>(), &S::i, &S::i) == InputIterator<const S*>(ia)); } void test_constexpr() { using namespace ranges; constexpr int ia[] = {0, 1, 2, 3, 0, 1, 2, 3}; constexpr auto sa = size(ia); constexpr int ib[] = {1, 3, 5, 7}; constexpr auto sb = size(ib); STATIC_CHECK( rng::find_first_of(as_lvalue(make_subrange(InputIterator<const int *>(ia), InputIterator<const int *>(ia + sa))), make_subrange(ForwardIterator<const int *>(ib), ForwardIterator<const int *>(ib + sb)), equal_to{}) == InputIterator<const int *>(ia + 1)); constexpr int ic[] = {7}; STATIC_CHECK( rng::find_first_of(as_lvalue(make_subrange(InputIterator<const int *>(ia), InputIterator<const int *>(ia + sa))), make_subrange(ForwardIterator<const int *>(ic), ForwardIterator<const int *>(ic + 1)), equal_to{}) == InputIterator<const int *>(ia + sa)); STATIC_CHECK( rng::find_first_of(as_lvalue(make_subrange(InputIterator<const int *>(ia), InputIterator<const int *>(ia + sa))), make_subrange(ForwardIterator<const int *>(ic), ForwardIterator<const int *>(ic)), equal_to{}) == InputIterator<const int *>(ia + sa)); STATIC_CHECK( rng::find_first_of(as_lvalue(make_subrange(InputIterator<const int *>(ia), InputIterator<const int *>(ia))), make_subrange(ForwardIterator<const int *>(ic), ForwardIterator<const int *>(ic + 1)), equal_to{}) == InputIterator<const int *>(ia)); } int main() { ::test_iter(); ::test_iter_pred(); ::test_rng(); ::test_rng_pred(); ::test_rng_pred_proj(); return ::test_result(); }
0
repos/range-v3/test
repos/range-v3/test/algorithm/adjacent_remove_if.cpp
/// \file // Range v3 library // // Copyright Eric Niebler // Copyright 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 // // 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 <range/v3/algorithm/adjacent_remove_if.hpp> #include <range/v3/core.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, 1, 1, 4, 2, 2, 4, 2}; constexpr auto sa = ranges::size(ia); Iter r = ranges::adjacent_remove_if(Iter(ia), Sent(ia+sa), ranges::equal_to{}); CHECK(base(r) == ia + sa-3); CHECK(ia[0] == 0); CHECK(ia[1] == 1); CHECK(ia[2] == 4); CHECK(ia[3] == 2); CHECK(ia[4] == 4); CHECK(ia[5] == 2); } template<class Iter, class Sent = Iter> void test_range() { int ia[] = {0, 1, 1, 1, 4, 2, 2, 4, 2}; constexpr auto sa = ranges::size(ia); Iter r = ranges::adjacent_remove_if( ranges::make_subrange(Iter(ia), Sent(ia+sa)), ranges::equal_to{}); CHECK(base(r) == ia + sa-3); CHECK(ia[0] == 0); CHECK(ia[1] == 1); CHECK(ia[2] == 4); CHECK(ia[3] == 2); CHECK(ia[4] == 4); CHECK(ia[5] == 2); } struct pred { bool operator()(const std::unique_ptr<int> &i, const std::unique_ptr<int> &j) { return *i == 2 && *j == 3; } }; 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[2].reset(new int(2)); ia[3].reset(new int(3)); ia[4].reset(new int(4)); ia[5].reset(new int(2)); ia[6].reset(new int(3)); ia[7].reset(new int(4)); ia[8].reset(new int(2)); Iter r = ranges::adjacent_remove_if(Iter(ia), Sent(ia+sa), pred()); CHECK(base(r) == ia + sa-2); CHECK(*ia[0] == 0); CHECK(*ia[1] == 1); CHECK(*ia[2] == 3); CHECK(*ia[3] == 4); CHECK(*ia[4] == 3); CHECK(*ia[5] == 4); CHECK(*ia[6] == 2); } 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[2].reset(new int(2)); ia[3].reset(new int(3)); ia[4].reset(new int(4)); ia[5].reset(new int(2)); ia[6].reset(new int(3)); ia[7].reset(new int(4)); ia[8].reset(new int(2)); Iter r = ranges::adjacent_remove_if(ranges::make_subrange(Iter(ia), Sent(ia+sa)), pred()); CHECK(base(r) == ia + sa-2); CHECK(*ia[0] == 0); CHECK(*ia[1] == 1); CHECK(*ia[2] == 3); CHECK(*ia[3] == 4); CHECK(*ia[4] == 3); CHECK(*ia[5] == 4); CHECK(*ia[6] == 2); } template<class Iter, class Sent = Iter> bool constexpr test_constexpr() { int ia[] = {0, 1, 1, 1, 4, 2, 2, 4, 2}; constexpr auto sa = ranges::size(ia); Iter r = ranges::adjacent_remove_if(ranges::make_subrange(Iter(ia), Sent(ia + sa)), ranges::equal_to{}); STATIC_CHECK_RETURN(base(r) == ia + sa - 3); STATIC_CHECK_RETURN(ia[0] == 0); STATIC_CHECK_RETURN(ia[1] == 1); STATIC_CHECK_RETURN(ia[2] == 4); STATIC_CHECK_RETURN(ia[3] == 2); STATIC_CHECK_RETURN(ia[4] == 4); STATIC_CHECK_RETURN(ia[5] == 2); return true; } struct S { int i; }; 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{1}, S{1}, S{4}, S{2}, S{2}, S{4}, S{2}}; constexpr auto sa = ranges::size(ia); S* r = ranges::adjacent_remove_if(ia, ranges::equal_to{}, &S::i); CHECK(r == ia + sa-3); CHECK(ia[0].i == 0); CHECK(ia[1].i == 1); CHECK(ia[2].i == 4); CHECK(ia[3].i == 2); CHECK(ia[4].i == 4); CHECK(ia[5].i == 2); } { // Check rvalue range S ia[] = {S{0}, S{1}, S{1}, S{2}, S{3}, S{5}, S{8}, S{13}, S{21}}; constexpr auto sa = ranges::size(ia); using namespace std::placeholders; auto r = ranges::adjacent_remove_if( ranges::views::all(ia), [](int x, int y) noexcept { return (x + y) % 2 == 0; }, &S::i); CHECK(r == ia + sa-3); CHECK(ia[0].i == 0); CHECK(ia[1].i == 1); CHECK(ia[2].i == 2); CHECK(ia[3].i == 5); CHECK(ia[4].i == 8); CHECK(ia[5].i == 21); } 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_difference.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 // //===----------------------------------------------------------------------===// // // 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 <functional> #include <vector> #include <range/v3/core.hpp> #include <range/v3/algorithm/fill.hpp> #include <range/v3/algorithm/set_algorithm.hpp> #include <range/v3/algorithm/lexicographical_compare.hpp> #include "../simple_test.hpp" #include "../test_utils.hpp" #include "../test_iterators.hpp" template<class Iter1, class Iter2, class OutIter> void test_iter() { int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4}; static const int sa = sizeof(ia)/sizeof(ia[0]); int ib[] = {2, 4, 4, 6}; static const int sb = sizeof(ib)/sizeof(ib[0]); int ic[20]; int ir[] = {1, 2, 3, 3, 3, 4, 4}; static const int sr = sizeof(ir)/sizeof(ir[0]); auto set_difference = ::make_testable_2<false, true>(ranges::set_difference); set_difference(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+sb), OutIter(ic)). check([&](ranges::set_difference_result<Iter1, OutIter> res) { CHECK((base(res.in1) - ia) == sa); CHECK((base(res.out) - ic) == sr); CHECK(std::lexicographical_compare(ic, base(res.out), ir, ir+sr) == false); ranges::fill(ic, 0); } ); int irr[] = {6}; static const int srr = sizeof(irr)/sizeof(irr[0]); set_difference(Iter1(ib), Iter1(ib+sb), Iter2(ia), Iter2(ia+sa), OutIter(ic)). check([&](ranges::set_difference_result<Iter1, OutIter> res) { CHECK((base(res.in1) - ib) == sb); CHECK((base(res.out) - ic) == srr); CHECK(std::lexicographical_compare(ic, base(res.out), irr, irr+srr) == false); ranges::fill(ic, 0); } ); } template<class Iter1, class Iter2, class OutIter> void test_comp() { int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4}; static const int sa = sizeof(ia)/sizeof(ia[0]); int ib[] = {2, 4, 4, 6}; static const int sb = sizeof(ib)/sizeof(ib[0]); int ic[20]; int ir[] = {1, 2, 3, 3, 3, 4, 4}; static const int sr = sizeof(ir)/sizeof(ir[0]); auto set_difference = ::make_testable_2<false, true>(ranges::set_difference); set_difference(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+sb), OutIter(ic), std::less<int>()). check([&](ranges::set_difference_result<Iter1, OutIter> res) { CHECK((base(res.in1) - ia) == sa); CHECK((base(res.out) - ic) == sr); CHECK(std::lexicographical_compare(ic, base(res.out), ir, ir+sr) == false); ranges::fill(ic, 0); } ); int irr[] = {6}; static const int srr = sizeof(irr)/sizeof(irr[0]); set_difference(Iter1(ib), Iter1(ib+sb), Iter2(ia), Iter2(ia+sa), OutIter(ic), std::less<int>()). check([&](ranges::set_difference_result<Iter1, OutIter> res) { CHECK((base(res.in1) - ib) == sb); CHECK((base(res.out) - ic) == srr); CHECK(std::lexicographical_compare(ic, base(res.out), irr, irr+srr) == false); ranges::fill(ic, 0); } ); } template<class Iter1, class Iter2, class OutIter> void test() { test_iter<Iter1, Iter2, OutIter>(); test_comp<Iter1, Iter2, OutIter>(); } struct S { int i; }; struct T { int j; }; struct U { int k; U& operator=(S s) { k = s.i; return *this;} U& operator=(T t) { k = t.j; return *this;} }; constexpr bool test_constexpr() { using namespace ranges; using IL = std::initializer_list<int>; int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4}; const int sa = sizeof(ia) / sizeof(ia[0]); int ib[] = {2, 4, 4, 6}; const int sb = sizeof(ib) / sizeof(ib[0]); int ic[20] = {0}; int ir[] = {1, 2, 3, 3, 3, 4, 4}; const int sr = sizeof(ir) / sizeof(ir[0]); const auto res = set_difference(ia, IL{2, 4, 4, 6}, ic, less{}); STATIC_CHECK_RETURN((res.in1 - ia) == sa); STATIC_CHECK_RETURN((res.out - ic) == sr); STATIC_CHECK_RETURN(lexicographical_compare(ic, res.out, ir, ir + sr, less{}) == 0); fill(ic, 0); int irr[] = {6}; const int srr = sizeof(irr) / sizeof(irr[0]); const auto res2 = set_difference(ib, IL{1, 2, 2, 3, 3, 3, 4, 4, 4, 4}, ic, less{}); STATIC_CHECK_RETURN((res2.in1 - ib) == sb); STATIC_CHECK_RETURN((res2.out - ic) == srr); STATIC_CHECK_RETURN(lexicographical_compare(ic, res2.out, irr, irr + srr, less{}) == 0); return true; } int main() { #ifdef SET_DIFFERENCE_1 test<InputIterator<const int*>, InputIterator<const int*>, OutputIterator<int*> >(); test<InputIterator<const int*>, InputIterator<const int*>, ForwardIterator<int*> >(); test<InputIterator<const int*>, InputIterator<const int*>, BidirectionalIterator<int*> >(); test<InputIterator<const int*>, InputIterator<const int*>, RandomAccessIterator<int*> >(); test<InputIterator<const int*>, InputIterator<const int*>, int*>(); test<InputIterator<const int*>, ForwardIterator<const int*>, OutputIterator<int*> >(); test<InputIterator<const int*>, ForwardIterator<const int*>, ForwardIterator<int*> >(); test<InputIterator<const int*>, ForwardIterator<const int*>, BidirectionalIterator<int*> >(); test<InputIterator<const int*>, ForwardIterator<const int*>, RandomAccessIterator<int*> >(); test<InputIterator<const int*>, ForwardIterator<const int*>, int*>(); test<InputIterator<const int*>, BidirectionalIterator<const int*>, OutputIterator<int*> >(); test<InputIterator<const int*>, BidirectionalIterator<const int*>, ForwardIterator<int*> >(); test<InputIterator<const int*>, BidirectionalIterator<const int*>, BidirectionalIterator<int*> >(); test<InputIterator<const int*>, BidirectionalIterator<const int*>, RandomAccessIterator<int*> >(); test<InputIterator<const int*>, BidirectionalIterator<const int*>, int*>(); test<InputIterator<const int*>, RandomAccessIterator<const int*>, OutputIterator<int*> >(); test<InputIterator<const int*>, RandomAccessIterator<const int*>, ForwardIterator<int*> >(); test<InputIterator<const int*>, RandomAccessIterator<const int*>, BidirectionalIterator<int*> >(); test<InputIterator<const int*>, RandomAccessIterator<const int*>, RandomAccessIterator<int*> >(); test<InputIterator<const int*>, RandomAccessIterator<const int*>, int*>(); test<InputIterator<const int*>, const int*, OutputIterator<int*> >(); test<InputIterator<const int*>, const int*, ForwardIterator<int*> >(); test<InputIterator<const int*>, const int*, BidirectionalIterator<int*> >(); test<InputIterator<const int*>, const int*, RandomAccessIterator<int*> >(); test<InputIterator<const int*>, const int*, int*>(); #endif #ifdef SET_DIFFERENCE_2 test<ForwardIterator<const int*>, InputIterator<const int*>, OutputIterator<int*> >(); test<ForwardIterator<const int*>, InputIterator<const int*>, ForwardIterator<int*> >(); test<ForwardIterator<const int*>, InputIterator<const int*>, BidirectionalIterator<int*> >(); test<ForwardIterator<const int*>, InputIterator<const int*>, RandomAccessIterator<int*> >(); test<ForwardIterator<const int*>, InputIterator<const int*>, int*>(); test<ForwardIterator<const int*>, ForwardIterator<const int*>, OutputIterator<int*> >(); test<ForwardIterator<const int*>, ForwardIterator<const int*>, ForwardIterator<int*> >(); test<ForwardIterator<const int*>, ForwardIterator<const int*>, BidirectionalIterator<int*> >(); test<ForwardIterator<const int*>, ForwardIterator<const int*>, RandomAccessIterator<int*> >(); test<ForwardIterator<const int*>, ForwardIterator<const int*>, int*>(); test<ForwardIterator<const int*>, BidirectionalIterator<const int*>, OutputIterator<int*> >(); test<ForwardIterator<const int*>, BidirectionalIterator<const int*>, ForwardIterator<int*> >(); test<ForwardIterator<const int*>, BidirectionalIterator<const int*>, BidirectionalIterator<int*> >(); test<ForwardIterator<const int*>, BidirectionalIterator<const int*>, RandomAccessIterator<int*> >(); test<ForwardIterator<const int*>, BidirectionalIterator<const int*>, int*>(); test<ForwardIterator<const int*>, RandomAccessIterator<const int*>, OutputIterator<int*> >(); test<ForwardIterator<const int*>, RandomAccessIterator<const int*>, ForwardIterator<int*> >(); test<ForwardIterator<const int*>, RandomAccessIterator<const int*>, BidirectionalIterator<int*> >(); test<ForwardIterator<const int*>, RandomAccessIterator<const int*>, RandomAccessIterator<int*> >(); test<ForwardIterator<const int*>, RandomAccessIterator<const int*>, int*>(); test<ForwardIterator<const int*>, const int*, OutputIterator<int*> >(); test<ForwardIterator<const int*>, const int*, ForwardIterator<int*> >(); test<ForwardIterator<const int*>, const int*, BidirectionalIterator<int*> >(); test<ForwardIterator<const int*>, const int*, RandomAccessIterator<int*> >(); test<ForwardIterator<const int*>, const int*, int*>(); #endif #ifdef SET_DIFFERENCE_3 test<BidirectionalIterator<const int*>, InputIterator<const int*>, OutputIterator<int*> >(); test<BidirectionalIterator<const int*>, InputIterator<const int*>, ForwardIterator<int*> >(); test<BidirectionalIterator<const int*>, InputIterator<const int*>, BidirectionalIterator<int*> >(); test<BidirectionalIterator<const int*>, InputIterator<const int*>, RandomAccessIterator<int*> >(); test<BidirectionalIterator<const int*>, InputIterator<const int*>, int*>(); test<BidirectionalIterator<const int*>, ForwardIterator<const int*>, OutputIterator<int*> >(); test<BidirectionalIterator<const int*>, ForwardIterator<const int*>, ForwardIterator<int*> >(); test<BidirectionalIterator<const int*>, ForwardIterator<const int*>, BidirectionalIterator<int*> >(); test<BidirectionalIterator<const int*>, ForwardIterator<const int*>, RandomAccessIterator<int*> >(); test<BidirectionalIterator<const int*>, ForwardIterator<const int*>, int*>(); test<BidirectionalIterator<const int*>, BidirectionalIterator<const int*>, OutputIterator<int*> >(); test<BidirectionalIterator<const int*>, BidirectionalIterator<const int*>, ForwardIterator<int*> >(); test<BidirectionalIterator<const int*>, BidirectionalIterator<const int*>, BidirectionalIterator<int*> >(); test<BidirectionalIterator<const int*>, BidirectionalIterator<const int*>, RandomAccessIterator<int*> >(); test<BidirectionalIterator<const int*>, BidirectionalIterator<const int*>, int*>(); test<BidirectionalIterator<const int*>, RandomAccessIterator<const int*>, OutputIterator<int*> >(); test<BidirectionalIterator<const int*>, RandomAccessIterator<const int*>, ForwardIterator<int*> >(); test<BidirectionalIterator<const int*>, RandomAccessIterator<const int*>, BidirectionalIterator<int*> >(); test<BidirectionalIterator<const int*>, RandomAccessIterator<const int*>, RandomAccessIterator<int*> >(); test<BidirectionalIterator<const int*>, RandomAccessIterator<const int*>, int*>(); test<BidirectionalIterator<const int*>, const int*, OutputIterator<int*> >(); test<BidirectionalIterator<const int*>, const int*, ForwardIterator<int*> >(); test<BidirectionalIterator<const int*>, const int*, BidirectionalIterator<int*> >(); test<BidirectionalIterator<const int*>, const int*, RandomAccessIterator<int*> >(); test<BidirectionalIterator<const int*>, const int*, int*>(); #endif #ifdef SET_DIFFERENCE_4 test<RandomAccessIterator<const int*>, InputIterator<const int*>, OutputIterator<int*> >(); test<RandomAccessIterator<const int*>, InputIterator<const int*>, ForwardIterator<int*> >(); test<RandomAccessIterator<const int*>, InputIterator<const int*>, BidirectionalIterator<int*> >(); test<RandomAccessIterator<const int*>, InputIterator<const int*>, RandomAccessIterator<int*> >(); test<RandomAccessIterator<const int*>, InputIterator<const int*>, int*>(); test<RandomAccessIterator<const int*>, ForwardIterator<const int*>, OutputIterator<int*> >(); test<RandomAccessIterator<const int*>, ForwardIterator<const int*>, ForwardIterator<int*> >(); test<RandomAccessIterator<const int*>, ForwardIterator<const int*>, BidirectionalIterator<int*> >(); test<RandomAccessIterator<const int*>, ForwardIterator<const int*>, RandomAccessIterator<int*> >(); test<RandomAccessIterator<const int*>, ForwardIterator<const int*>, int*>(); test<RandomAccessIterator<const int*>, BidirectionalIterator<const int*>, OutputIterator<int*> >(); test<RandomAccessIterator<const int*>, BidirectionalIterator<const int*>, ForwardIterator<int*> >(); test<RandomAccessIterator<const int*>, BidirectionalIterator<const int*>, BidirectionalIterator<int*> >(); test<RandomAccessIterator<const int*>, BidirectionalIterator<const int*>, RandomAccessIterator<int*> >(); test<RandomAccessIterator<const int*>, BidirectionalIterator<const int*>, int*>(); test<RandomAccessIterator<const int*>, RandomAccessIterator<const int*>, OutputIterator<int*> >(); test<RandomAccessIterator<const int*>, RandomAccessIterator<const int*>, ForwardIterator<int*> >(); test<RandomAccessIterator<const int*>, RandomAccessIterator<const int*>, BidirectionalIterator<int*> >(); test<RandomAccessIterator<const int*>, RandomAccessIterator<const int*>, RandomAccessIterator<int*> >(); test<RandomAccessIterator<const int*>, RandomAccessIterator<const int*>, int*>(); test<RandomAccessIterator<const int*>, const int*, OutputIterator<int*> >(); test<RandomAccessIterator<const int*>, const int*, ForwardIterator<int*> >(); test<RandomAccessIterator<const int*>, const int*, BidirectionalIterator<int*> >(); test<RandomAccessIterator<const int*>, const int*, RandomAccessIterator<int*> >(); test<RandomAccessIterator<const int*>, const int*, int*>(); #endif #ifdef SET_DIFFERENCE_5 test<const int*, InputIterator<const int*>, OutputIterator<int*> >(); test<const int*, InputIterator<const int*>, BidirectionalIterator<int*> >(); test<const int*, InputIterator<const int*>, BidirectionalIterator<int*> >(); test<const int*, InputIterator<const int*>, RandomAccessIterator<int*> >(); test<const int*, InputIterator<const int*>, int*>(); test<const int*, ForwardIterator<const int*>, OutputIterator<int*> >(); test<const int*, ForwardIterator<const int*>, ForwardIterator<int*> >(); test<const int*, ForwardIterator<const int*>, BidirectionalIterator<int*> >(); test<const int*, ForwardIterator<const int*>, RandomAccessIterator<int*> >(); test<const int*, ForwardIterator<const int*>, int*>(); test<const int*, BidirectionalIterator<const int*>, OutputIterator<int*> >(); test<const int*, BidirectionalIterator<const int*>, ForwardIterator<int*> >(); test<const int*, BidirectionalIterator<const int*>, BidirectionalIterator<int*> >(); test<const int*, BidirectionalIterator<const int*>, RandomAccessIterator<int*> >(); test<const int*, BidirectionalIterator<const int*>, int*>(); test<const int*, RandomAccessIterator<const int*>, OutputIterator<int*> >(); test<const int*, RandomAccessIterator<const int*>, ForwardIterator<int*> >(); test<const int*, RandomAccessIterator<const int*>, BidirectionalIterator<int*> >(); test<const int*, RandomAccessIterator<const int*>, RandomAccessIterator<int*> >(); test<const int*, RandomAccessIterator<const int*>, int*>(); test<const int*, const int*, OutputIterator<int*> >(); test<const int*, const int*, ForwardIterator<int*> >(); test<const int*, const int*, BidirectionalIterator<int*> >(); test<const int*, const int*, RandomAccessIterator<int*> >(); test<const int*, const int*, int*>(); #endif #ifdef SET_DIFFERENCE_6 // Test projections { S ia[] = {S{1}, S{2}, S{2}, S{3}, S{3}, S{3}, S{4}, S{4}, S{4}, S{4}}; static const int sa = sizeof(ia)/sizeof(ia[0]); T ib[] = {T{2}, T{4}, T{4}, T{6}}; static const int sb = sizeof(ib)/sizeof(ib[0]); U ic[20]; int ir[] = {1, 2, 3, 3, 3, 4, 4}; static const int sr = sizeof(ir)/sizeof(ir[0]); ranges::set_difference_result<S *, U *> res = ranges::set_difference(ia, ib, ic, std::less<int>(), &S::i, &T::j); CHECK((res.in1 - ia) == sa); CHECK((res.out - ic) == sr); CHECK(ranges::lexicographical_compare(ic, res.out, ir, ir+sr, std::less<int>(), &U::k) == false); ranges::fill(ic, U{0}); int irr[] = {6}; static const int srr = sizeof(irr)/sizeof(irr[0]); ranges::set_difference_result<T *, U *> res2 = ranges::set_difference(ib, ia, ic, std::less<int>(), &T::j, &S::i); CHECK((res2.in1 - ib) == sb); CHECK((res2.out - ic) == srr); CHECK(ranges::lexicographical_compare(ic, res2.out, ir, irr+srr, std::less<int>(), &U::k) == false); } // Test rvalue ranges { S ia[] = {S{1}, S{2}, S{2}, S{3}, S{3}, S{3}, S{4}, S{4}, S{4}, S{4}}; T ib[] = {T{2}, T{4}, T{4}, T{6}}; static const int sb = sizeof(ib)/sizeof(ib[0]); U ic[20]; int ir[] = {1, 2, 3, 3, 3, 4, 4}; static const int sr = sizeof(ir)/sizeof(ir[0]); auto res = ranges::set_difference(std::move(ia), ranges::views::all(ib), ic, std::less<int>(), &S::i, &T::j); #ifndef RANGES_WORKAROUND_MSVC_573728 CHECK(::is_dangling(res.in1)); #endif // RANGES_WORKAROUND_MSVC_573728 CHECK((res.out - ic) == sr); CHECK(ranges::lexicographical_compare(ic, res.out, ir, ir+sr, std::less<int>(), &U::k) == false); ranges::fill(ic, U{0}); int irr[] = {6}; static const int srr = sizeof(irr)/sizeof(irr[0]); auto res2 = ranges::set_difference(ranges::views::all(ib), ranges::views::all(ia), ic, std::less<int>(), &T::j, &S::i); CHECK((res2.in1 - ib) == sb); CHECK((res2.out - ic) == srr); CHECK(ranges::lexicographical_compare(ic, res2.out, ir, irr+srr, std::less<int>(), &U::k) == false); ranges::fill(ic, U{0}); std::vector<S> vec{S{1}, S{2}, S{2}, S{3}, S{3}, S{3}, S{4}, S{4}, S{4}, S{4}}; auto res3 = ranges::set_difference(std::move(vec), ranges::views::all(ib), ic, std::less<int>(), &S::i, &T::j); CHECK(::is_dangling(res3.in1)); CHECK((res3.out - ic) == sr); CHECK(ranges::lexicographical_compare(ic, res3.out, ir, ir+sr, std::less<int>(), &U::k) == false); } { STATIC_CHECK(test_constexpr()); } #endif return ::test_result(); }
0
repos/range-v3/test
repos/range-v3/test/algorithm/set_symmetric_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_SYMMETRIC_DIFFERENCE_3 #include "./set_symmetric_difference.hpp"
0
repos/range-v3/test
repos/range-v3/test/algorithm/partial_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 <algorithm> #include <vector> #include <range/v3/core.hpp> #include <range/v3/algorithm/partial_sort.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; struct indirect_less { template<class P> bool operator()(const P& x, const P& y) {return *x < *y;} }; void test_larger_sorts(int N, int M) { RANGES_ENSURE(N > 0); RANGES_ENSURE(M >= 0 && M <= N); int* array = new int[N]; for(int i = 0; i < N; ++i) array[i] = i; using I = RandomAccessIterator<int*>; using S = Sentinel<int*>; std::shuffle(array, array+N, gen); int *res = ranges::partial_sort(array, array+M, array+N); CHECK(res == array+N); for(int i = 0; i < M; ++i) CHECK(array[i] == i); std::shuffle(array, array+N, gen); I res2 = ranges::partial_sort(I{array}, I{array+M}, S{array+N}); CHECK(res2.base() == array+N); for(int i = 0; i < M; ++i) CHECK(array[i] == i); std::shuffle(array, array+N, gen); res = ranges::partial_sort(ranges::make_subrange(array, array+N), array+M); CHECK(res == array+N); for(int i = 0; i < M; ++i) CHECK(array[i] == i); std::shuffle(array, array+N, gen); res2 = ranges::partial_sort(ranges::make_subrange(I{array}, S{array+N}), I{array+M}); CHECK(res2.base() == array+N); for(int i = 0; i < M; ++i) CHECK(array[i] == i); std::shuffle(array, array+N, gen); auto res3 = ranges::partial_sort(::MakeTestRange(array, array+N), array+M); CHECK(::is_dangling(res3)); for(int i = 0; i < M; ++i) CHECK(array[i] == i); std::shuffle(array, array+N, gen); auto res4 = ranges::partial_sort(::MakeTestRange(I{array}, S{array+N}), I{array+M}); CHECK(::is_dangling(res4)); for(int i = 0; i < M; ++i) CHECK(array[i] == i); std::shuffle(array, array+N, gen); res = ranges::partial_sort(array, array+M, array+N, std::greater<int>()); CHECK(res == array+N); for(int i = 0; i < M; ++i) CHECK(array[i] == N-i-1); std::shuffle(array, array+N, gen); res2 = ranges::partial_sort(I{array}, I{array+M}, S{array+N}, std::greater<int>()); CHECK(res2.base() == array+N); for(int i = 0; i < M; ++i) CHECK(array[i] == N-i-1); std::shuffle(array, array+N, gen); res = ranges::partial_sort(ranges::make_subrange(array, array+N), array+M, std::greater<int>()); CHECK(res == array+N); for(int i = 0; i < M; ++i) CHECK(array[i] == N-i-1); std::shuffle(array, array+N, gen); res2 = ranges::partial_sort(ranges::make_subrange(I{array}, S{array+N}), I{array+M}, std::greater<int>()); CHECK(res2.base() == array+N); for(int i = 0; i < M; ++i) CHECK(array[i] == N-i-1); delete [] array; } void test_larger_sorts(int N) { test_larger_sorts(N, 0); 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; }; } constexpr bool test_constexpr() { test::array<std::size_t, 10> v{{0}}; for(std::size_t i = 0; i < v.size(); ++i) { v[i] = v.size() - i - 1; } ranges::partial_sort(v, v.begin() + v.size() / 2, ranges::less{}); for(size_t i = 0; i < v.size() / 2; ++i) { STATIC_CHECK_RETURN(v[i] == i); } return true; } int main() { int i = 0; int * res = ranges::partial_sort(&i, &i, &i); CHECK(i == 0); CHECK(res == &i); test_larger_sorts(10); 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 j = 0; j < (int)v.size(); ++j) v[j].reset(new int((int)v.size() - j - 1)); ranges::partial_sort(v, v.begin() + v.size()/2, indirect_less()); for(int j = 0; j < (int)v.size()/2; ++j) CHECK(*v[j] == j); } // Check projections { std::vector<S> v(1000, S{}); for(int j = 0; (std::size_t)j < v.size(); ++j) { v[j].i = (int)v.size() - j - 1; v[j].j = j; } ranges::partial_sort(v, v.begin() + v.size()/2, std::less<int>{}, &S::i); for(int j = 0; (std::size_t)j < v.size()/2; ++j) { CHECK(v[j].i == j); CHECK((std::size_t)v[j].j == v.size() - j - 1); } } { STATIC_CHECK(test_constexpr()); } return ::test_result(); }
0
repos/range-v3/test
repos/range-v3/test/algorithm/remove_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 <iostream> #include <memory> #include <utility> #include <vector> #include <range/v3/core.hpp> #include <range/v3/algorithm/remove_if.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); using namespace std::placeholders; Iter r = ranges::remove_if(Iter(ia), Sent(ia+sa), std::bind(std::equal_to<int>(), _1, 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); using namespace std::placeholders; Iter r = ranges::remove_if(::as_lvalue(ranges::make_subrange(Iter(ia), Sent(ia+sa))), std::bind(std::equal_to<int>(), _1, 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); } struct pred { bool operator()(const std::unique_ptr<int>& i) {return *i == 2;} }; 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[2].reset(new int(2)); ia[3].reset(new int(3)); ia[4].reset(new int(4)); ia[5].reset(new int(2)); ia[6].reset(new int(3)); ia[7].reset(new int(4)); ia[8].reset(new int(2)); Iter r = ranges::remove_if(Iter(ia), Sent(ia+sa), pred()); 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[2].reset(new int(2)); ia[3].reset(new int(3)); ia[4].reset(new int(4)); ia[5].reset(new int(2)); ia[6].reset(new int(3)); ia[7].reset(new int(4)); ia[8].reset(new int(2)); Iter r = ranges::remove_if(::as_lvalue(ranges::make_subrange(Iter(ia), Sent(ia+sa))), pred()); 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 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}; constexpr auto sa = ranges::size(ia); auto r = ranges::remove_if(ia, equals_two); 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); using namespace std::placeholders; S* r = ranges::remove_if(ia, std::bind(std::equal_to<int>(), _1, 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 ia[] = {S{0}, S{1}, S{2}, S{3}, S{4}, S{2}, S{3}, S{4}, S{2}}; using namespace std::placeholders; auto r0 = ranges::remove_if(std::move(ia), std::bind(std::equal_to<int>(), _1, 2), &S::i); #ifndef RANGES_WORKAROUND_MSVC_573728 static_assert(std::is_same<decltype(r0), ranges::dangling>::value, ""); #endif // RANGES_WORKAROUND_MSVC_573728 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); std::vector<S> vec{S{0}, S{1}, S{2}, S{3}, S{4}, S{2}, S{3}, S{4}, S{2}}; auto r1 = ranges::remove_if(std::move(vec), std::bind(std::equal_to<int>(), _1, 2), &S::i); static_assert(std::is_same<decltype(r1), ranges::dangling>::value, ""); 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/next_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[] = {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::next_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[] = {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::next_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[] = {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::next_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[] = {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::next_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; int ia[] = {6, 5, 4, 3, 2, 1}; using IL = std::initializer_list<int>; next_permutation(ia, greater{}); STATIC_CHECK_RETURN(equal(ia, IL{6, 5, 4, 3, 1, 2})); next_permutation(ia, greater{}); STATIC_CHECK_RETURN(equal(ia, IL{6, 5, 4, 2, 3, 1})); next_permutation(ia, greater{}); 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::greater<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::next_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::next_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::next_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(); }
0
repos/range-v3/test
repos/range-v3/test/algorithm/set_symmetric_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_SYMMETRIC_DIFFERENCE_4 #include "./set_symmetric_difference.hpp"
0
repos/range-v3/test
repos/range-v3/test/algorithm/count_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 #include <range/v3/core.hpp> #include <range/v3/algorithm/count_if.hpp> #include "../simple_test.hpp" #include "../test_iterators.hpp" struct S { int i; }; struct T { bool b; bool m() { return b; } }; constexpr bool even(int i) { return i % 2 == 0; } int main() { using namespace ranges; auto equals = [](int i){ return std::bind(equal_to{}, i, std::placeholders::_1); }; int ia[] = {0, 1, 2, 2, 0, 1, 2, 3}; constexpr auto cia = size(ia); CHECK(count_if(InputIterator<const int*>(ia), Sentinel<const int*>(ia + cia), equals(2)) == 3); CHECK(count_if(InputIterator<const int*>(ia), Sentinel<const int*>(ia + cia), equals(7)) == 0); CHECK(count_if(InputIterator<const int*>(ia), Sentinel<const int*>(ia), equals(2)) == 0); CHECK(count_if(make_subrange(InputIterator<const int*>(ia), Sentinel<const int*>(ia + cia)), equals(2)) == 3); CHECK(count_if(make_subrange(InputIterator<const int*>(ia), Sentinel<const int*>(ia + cia)), equals(7)) == 0); CHECK(count_if(make_subrange(InputIterator<const int*>(ia), Sentinel<const int*>(ia)), equals(2)) == 0); S sa[] = {{0}, {1}, {2}, {2}, {0}, {1}, {2}, {3}}; constexpr auto csa = size(ia); CHECK(count_if(InputIterator<const S*>(sa), Sentinel<const S*>(sa + csa), equals(2), &S::i) == 3); CHECK(count_if(InputIterator<const S*>(sa), Sentinel<const S*>(sa + csa), equals(7), &S::i) == 0); CHECK(count_if(InputIterator<const S*>(sa), Sentinel<const S*>(sa), equals(2), &S::i) == 0); CHECK(count_if(make_subrange(InputIterator<const S*>(sa), Sentinel<const S*>(sa + csa)), equals(2), &S::i) == 3); CHECK(count_if(make_subrange(InputIterator<const S*>(sa), Sentinel<const S*>(sa + csa)), equals(7), &S::i) == 0); CHECK(count_if(make_subrange(InputIterator<const S*>(sa), Sentinel<const S*>(sa)), equals(2), &S::i) == 0); T ta[] = {{true}, {false}, {true}, {false}, {false}, {true}, {false}, {false}, {true}, {false}}; CHECK(count_if(InputIterator<T*>(ta), Sentinel<T*>(ta + size(ta)), &T::m) == 4); CHECK(count_if(InputIterator<T*>(ta), Sentinel<T*>(ta + size(ta)), &T::b) == 4); CHECK(count_if(make_subrange(InputIterator<T*>(ta), Sentinel<T*>(ta + size(ta))), &T::m) == 4); CHECK(count_if(make_subrange(InputIterator<T*>(ta), Sentinel<T*>(ta + size(ta))), &T::b) == 4); { using IL = std::initializer_list<int>; STATIC_CHECK(ranges::count_if(IL{0, 1, 2, 1, 3, 1, 4}, even) == 3); STATIC_CHECK(ranges::count_if(IL{1, 1, 3, 1}, even) == 0); } return ::test_result(); }
0
repos/range-v3/test
repos/range-v3/test/algorithm/is_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 <utility> #include <range/v3/core.hpp> #include <range/v3/algorithm/permutation.hpp> #include "../simple_test.hpp" #include "../test_utils.hpp" #include "../test_iterators.hpp" RANGES_DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS int comparison_count = 0; template<typename T> bool counting_equals( T const &a, T const &b ) { ++comparison_count; return a == b; } struct S { int i; }; struct T { int i; }; int main() { { const int ia[] = {0}; const int ib[] = {0}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + 0), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == true); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == true); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == true); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa - 1), std::equal_to<const int>()) == false); } { const int ia[] = {0}; const int ib[] = {1}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == false); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == false); } { const int ia[] = {0, 0}; const int ib[] = {0, 0}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == true); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == true); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa - 1), std::equal_to<const int>()) == false); } { const int ia[] = {0, 0}; const int ib[] = {0, 1}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == false); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == false); } { const int ia[] = {0, 0}; const int ib[] = {1, 0}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == false); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == false); } { const int ia[] = {0, 0}; const int ib[] = {1, 1}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == false); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == false); } { const int ia[] = {0, 1}; const int ib[] = {0, 0}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == false); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == false); } { const int ia[] = {0, 1}; const int ib[] = {0, 1}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == true); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == true); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa - 1), std::equal_to<const int>()) == false); } { const int ia[] = {0, 1}; const int ib[] = {1, 0}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == true); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == true); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa - 1), std::equal_to<const int>()) == false); } { const int ia[] = {0, 1}; const int ib[] = {1, 1}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == false); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == false); } { const int ia[] = {1, 0}; const int ib[] = {0, 0}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == false); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == false); } { const int ia[] = {1, 0}; const int ib[] = {0, 1}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == true); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == true); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa - 1), std::equal_to<const int>()) == false); } { const int ia[] = {1, 0}; const int ib[] = {1, 0}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == true); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == true); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa - 1), std::equal_to<const int>()) == false); } { const int ia[] = {1, 0}; const int ib[] = {1, 1}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == false); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == false); } { const int ia[] = {1, 1}; const int ib[] = {0, 0}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == false); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == false); } { const int ia[] = {1, 1}; const int ib[] = {0, 1}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == false); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == false); } { const int ia[] = {1, 1}; const int ib[] = {1, 0}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == false); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == false); } { const int ia[] = {1, 1}; const int ib[] = {1, 1}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == true); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == true); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa - 1), std::equal_to<const int>()) == false); } { const int ia[] = {0, 0, 0}; const int ib[] = {1, 0, 0}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == false); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == false); } { const int ia[] = {0, 0, 0}; const int ib[] = {1, 0, 1}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == false); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == false); } { const int ia[] = {0, 0, 0}; const int ib[] = {1, 0, 2}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == false); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == false); } { const int ia[] = {0, 0, 0}; const int ib[] = {1, 1, 0}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == false); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == false); } { const int ia[] = {0, 0, 0}; const int ib[] = {1, 1, 1}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == false); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == false); } { const int ia[] = {0, 0, 0}; const int ib[] = {1, 1, 2}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == false); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == false); } { const int ia[] = {0, 0, 0}; const int ib[] = {1, 2, 0}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == false); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == false); } { const int ia[] = {0, 0, 0}; const int ib[] = {1, 2, 1}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == false); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == false); } { const int ia[] = {0, 0, 0}; const int ib[] = {1, 2, 2}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == false); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == false); } { const int ia[] = {0, 0, 1}; const int ib[] = {1, 0, 0}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == true); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == true); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa - 1), std::equal_to<const int>()) == false); } { const int ia[] = {0, 0, 1}; const int ib[] = {1, 0, 1}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == false); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == false); } { const int ia[] = {0, 1, 2}; const int ib[] = {1, 0, 2}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == true); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == true); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa - 1), std::equal_to<const int>()) == false); } { const int ia[] = {0, 1, 2}; const int ib[] = {1, 2, 0}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == true); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == true); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa - 1), std::equal_to<const int>()) == false); } { const int ia[] = {0, 1, 2}; const int ib[] = {2, 1, 0}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == true); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == true); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa - 1), std::equal_to<const int>()) == false); } { const int ia[] = {0, 1, 2}; const int ib[] = {2, 0, 1}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == true); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == true); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa - 1), std::equal_to<const int>()) == false); } { const int ia[] = {0, 0, 1}; const int ib[] = {1, 0, 1}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == false); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == false); } { const int ia[] = {0, 0, 1}; const int ib[] = {1, 0, 0}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == true); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == true); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib + 1), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == false); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa - 1), std::equal_to<const int>()) == false); } { const int ia[] = {0, 1, 2, 3, 0, 5, 6, 2, 4, 4}; const int ib[] = {4, 2, 3, 0, 1, 4, 0, 5, 6, 2}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == true); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == true); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib + 1), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == false); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa - 1), std::equal_to<const int>()) == false); comparison_count = 0; CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa - 1), counting_equals<const int>) == false); CHECK( comparison_count > 0 ); comparison_count = 0; CHECK(ranges::is_permutation(RandomAccessIterator<const int*>(ia), RandomAccessIterator<const int*>(ia + sa), RandomAccessIterator<const int*>(ib), RandomAccessIterator<const int*>(ib + sa - 1), counting_equals<const int>) == false); CHECK ( comparison_count == 0 ); } { const int ia[] = {0, 1, 2, 3, 0, 5, 6, 2, 4, 4}; const int ib[] = {4, 2, 3, 0, 1, 4, 0, 5, 6, 0}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), std::equal_to<const int>()) == false); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa), std::equal_to<const int>()) == false); } // Iterator tests, without predicate: { const int ia[] = {0, 1, 2, 3, 0, 5, 6, 2, 4, 4}; const int ib[] = {4, 2, 3, 0, 1, 4, 0, 5, 6, 2}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib)) == true); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa)) == true); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib + 1), ForwardIterator<const int*>(ib + sa)) == false); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), ForwardIterator<const int*>(ia + sa), ForwardIterator<const int*>(ib), ForwardIterator<const int*>(ib + sa - 1)) == false); } // Iterator tests, with sentinels: { const int ia[] = {0, 1, 2, 3, 0, 5, 6, 2, 4, 4}; const int ib[] = {4, 2, 3, 0, 1, 4, 0, 5, 6, 2}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), Sentinel<const int*>(ia + sa), ForwardIterator<const int*>(ib)) == true); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), Sentinel<const int*>(ia + sa), ForwardIterator<const int*>(ib), Sentinel<const int*>(ib + sa)) == true); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), Sentinel<const int*>(ia + sa), ForwardIterator<const int*>(ib + 1), Sentinel<const int*>(ib + sa)) == false); CHECK(ranges::is_permutation(ForwardIterator<const int*>(ia), Sentinel<const int*>(ia + sa), ForwardIterator<const int*>(ib), Sentinel<const int*>(ib + sa - 1)) == false); } // common_range tests, with sentinels: { const int ia[] = {0, 1, 2, 3, 0, 5, 6, 2, 4, 4}; const int ib[] = {4, 2, 3, 0, 1, 4, 0, 5, 6, 2}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ranges::make_subrange(ForwardIterator<const int*>(ia), Sentinel<const int*>(ia + sa)), ForwardIterator<const int*>(ib)) == true); CHECK(ranges::is_permutation(ranges::make_subrange(ForwardIterator<const int*>(ia), Sentinel<const int*>(ia + sa)), ranges::make_subrange(ForwardIterator<const int*>(ib), Sentinel<const int*>(ib + sa))) == true); CHECK(ranges::is_permutation(ranges::make_subrange(ForwardIterator<const int*>(ia), Sentinel<const int*>(ia + sa)), ranges::make_subrange(ForwardIterator<const int*>(ib + 1), Sentinel<const int*>(ib + sa))) == false); CHECK(ranges::is_permutation(ranges::make_subrange(ForwardIterator<const int*>(ia), Sentinel<const int*>(ia + sa)), ranges::make_subrange(ForwardIterator<const int*>(ib), Sentinel<const int*>(ib + sa - 1))) == false); } // common_range tests, with sentinels, with predicate: { const int ia[] = {0, 1, 2, 3, 0, 5, 6, 2, 4, 4}; const int ib[] = {4, 2, 3, 0, 1, 4, 0, 5, 6, 2}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ranges::make_subrange(ForwardIterator<const int*>(ia), Sentinel<const int*>(ia + sa)), ForwardIterator<const int*>(ib), std::equal_to<int const>()) == true); CHECK(ranges::is_permutation(ranges::make_subrange(ForwardIterator<const int*>(ia), Sentinel<const int*>(ia + sa)), ranges::make_subrange(ForwardIterator<const int*>(ib), Sentinel<const int*>(ib + sa)), std::equal_to<int const>()) == true); CHECK(ranges::is_permutation(ranges::make_subrange(ForwardIterator<const int*>(ia), Sentinel<const int*>(ia + sa)), ranges::make_subrange(ForwardIterator<const int*>(ib + 1), Sentinel<const int*>(ib + sa)), std::equal_to<int const>()) == false); CHECK(ranges::is_permutation(ranges::make_subrange(ForwardIterator<const int*>(ia), Sentinel<const int*>(ia + sa)), ranges::make_subrange(ForwardIterator<const int*>(ib), Sentinel<const int*>(ib + sa - 1)), std::equal_to<int const>()) == false); } // common_range tests, with sentinels, with predicate and projections: { const S ia[] = {{0}, {1}, {2}, {3}, {0}, {5}, {6}, {2}, {4}, {4}}; const T ib[] = {{4}, {2}, {3}, {0}, {1}, {4}, {0}, {5}, {6}, {2}}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ia, &ib[0], std::equal_to<int const>(), &S::i, &T::i) == true); CHECK(ranges::is_permutation(ia, ib, std::equal_to<int const>(), &S::i, &T::i) == true); CHECK(ranges::is_permutation(ranges::make_subrange(ForwardIterator<const S*>(ia), Sentinel<const S*>(ia + sa)), ranges::make_subrange(ForwardIterator<const T*>(ib + 1), Sentinel<const T*>(ib + sa)), std::equal_to<int const>(), &S::i, &T::i) == false); CHECK(ranges::is_permutation(ranges::make_subrange(ForwardIterator<const S*>(ia), Sentinel<const S*>(ia + sa)), ranges::make_subrange(ForwardIterator<const T*>(ib), Sentinel<const T*>(ib + sa - 1)), std::equal_to<int const>(), &S::i, &T::i) == false); } // Iterator tests, with sentinels, with predicate and projections: { const S ia[] = {{0}, {1}, {2}, {3}, {0}, {5}, {6}, {2}, {4}, {4}}; const T ib[] = {{4}, {2}, {3}, {0}, {1}, {4}, {0}, {5}, {6}, {2}}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::is_permutation(ForwardIterator<const S*>(ia), Sentinel<const S*>(ia + sa), ForwardIterator<const T*>(ib), std::equal_to<int const>(), &S::i, &T::i) == true); CHECK(ranges::is_permutation(ForwardIterator<const S*>(ia), Sentinel<const S*>(ia + sa), ForwardIterator<const T*>(ib), Sentinel<const T*>(ib + sa), std::equal_to<int const>(), &S::i, &T::i) == true); CHECK(ranges::is_permutation(ForwardIterator<const S*>(ia), Sentinel<const S*>(ia + sa), ForwardIterator<const T*>(ib + 1), Sentinel<const T*>(ib + sa), std::equal_to<int const>(), &S::i, &T::i) == false); CHECK(ranges::is_permutation(ForwardIterator<const S*>(ia), Sentinel<const S*>(ia + sa), ForwardIterator<const T*>(ib), Sentinel<const T*>(ib + sa - 1), std::equal_to<int const>(), &S::i, &T::i) == false); } return ::test_result(); }
0
repos/range-v3/test
repos/range-v3/test/algorithm/sample.cpp
// Range v3 lbrary // // Copyright Eric Niebler 2014-present // Copyright Casey Carter 2016 // // Use, modification and distrbution 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 // Distrbuted 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/sample.hpp> #include <range/v3/numeric/iota.hpp> #include <range/v3/iterator/move_iterators.hpp> #include "../simple_test.hpp" #include "../test_utils.hpp" #include "../test_iterators.hpp" namespace { template<typename I, typename S> auto in_sequence(I first, I mid, S last) -> CPP_ret(bool)( requires ranges::sentinel_for<S, I>) { for (; first != mid; ++first) RANGES_ENSURE(first != last); for (; first != last; ++first) ; return true; } } int main() { constexpr unsigned N = 100; constexpr unsigned K = 10; { std::array<int, N> i; ranges::iota(i, 0); std::array<int, K> a{}, b{}, c{}; std::minstd_rand g1, g2 = g1; { auto result = ranges::sample(RandomAccessIterator<int*>(i.data()), Sentinel<int*>(i.data()+N), a.begin(), K, g1); CHECK(in_sequence(i.data(), result.in.base(), i.data() + N)); CHECK(result.out == a.end()); CHECK(!ranges::equal(a, c)); } { auto result = ranges::sample(i.begin(), i.end(), b.begin(), K, g1); CHECK(in_sequence(i.begin(), result.in, i.end())); CHECK(result.out == b.end()); CHECK(!ranges::equal(a, b)); CHECK(!ranges::equal(b, c)); } { auto result = ranges::sample(i.begin(), i.end(), c.begin(), K, g2); CHECK(in_sequence(i.begin(), result.in, i.end())); CHECK(result.out == c.end()); CHECK(ranges::equal(a, c)); } } { std::array<int, N> i; ranges::iota(i, 0); std::array<int, K> a{}, b{}, c{}; std::minstd_rand g1, g2 = g1; auto rng = ranges::make_subrange(RandomAccessIterator<int*>(i.data()), Sentinel<int*>(i.data() + N)); { auto result = ranges::sample(rng, a.begin(), K, g1); CHECK(in_sequence(ranges::begin(rng), result.in, ranges::end(rng))); CHECK(result.out == a.end()); CHECK(!ranges::equal(a, b)); } { auto result = ranges::sample(i, b.begin(), K, g2); CHECK(in_sequence(i.begin(), result.in, i.end())); CHECK(result.out == b.end()); CHECK(ranges::equal(a, b)); } { auto result = ranges::sample(i, b.begin(), K, g1); CHECK(in_sequence(i.begin(), result.in, i.end())); CHECK(result.out == b.end()); CHECK(!ranges::equal(a, b)); CHECK(!ranges::equal(b, c)); } { a.fill(0); auto result = ranges::sample(std::move(rng), a.begin(), K, g1); CHECK(in_sequence(ranges::begin(rng), result.in, ranges::end(rng))); CHECK(result.out == a.end()); CHECK(!ranges::equal(a, c)); } } { std::array<int, N> i; ranges::iota(i, 0); std::array<int, K> a{}, b{}, c{}; { auto result = ranges::sample(RandomAccessIterator<int*>(i.data()), Sentinel<int*>(i.data() + N), a.begin(), K); CHECK(in_sequence(i.data(), result.in.base(), i.data() + N)); CHECK(result.out == a.end()); CHECK(!ranges::equal(a, b)); } { auto result = ranges::sample(i, b.begin(), K); CHECK(in_sequence(i.begin(), result.in, i.end())); CHECK(result.out == b.end()); CHECK(!ranges::equal(b, c)); CHECK(!ranges::equal(a, b)); } } { std::array<MoveOnlyString, 10> source; std::array<MoveOnlyString, 4> dest; auto result = ranges::sample(ranges::make_move_iterator(source.begin()), ranges::make_move_sentinel(source.end()), ForwardIterator<MoveOnlyString*>(dest.data()), dest.size()); CHECK(in_sequence(ranges::make_move_iterator(source.begin()), result.in, ranges::make_move_sentinel(source.end()))); CHECK(result.out == ForwardIterator<MoveOnlyString*>(dest.data() + dest.size())); } { std::array<int, N> i; ranges::iota(i, 0); std::array<int, K> a{}, b{}, c{}; std::minstd_rand g1, g2 = g1; { auto result = ranges::sample(RandomAccessIterator<int*>(i.data()), Sentinel<int*>(i.data()+N), a, g1); CHECK(in_sequence(i.data(), result.in.base(), i.data() + N)); CHECK(result.out == a.end()); CHECK(!ranges::equal(a, c)); } { auto result = ranges::sample(i.begin(), i.end(), b, g1); CHECK(in_sequence(i.begin(), result.in, i.end())); CHECK(result.out == b.end()); CHECK(!ranges::equal(a, b)); CHECK(!ranges::equal(b, c)); } { auto result = ranges::sample(i.begin(), i.end(), c, g2); CHECK(in_sequence(i.begin(), result.in, i.end())); CHECK(result.out == c.end()); CHECK(ranges::equal(a, c)); } } { std::array<int, N> i; ranges::iota(i, 0); std::array<int, K> a{}, b{}, c{}; std::minstd_rand g1, g2 = g1; auto rng = ranges::make_subrange(RandomAccessIterator<int*>(i.data()), Sentinel<int*>(i.data() + N)); { auto result = ranges::sample(rng, a, g1); CHECK(in_sequence(i.data(), result.in.base(), i.data() + N)); CHECK(result.out == a.end()); CHECK(!ranges::equal(a, b)); } { auto result = ranges::sample(i, b, g2); CHECK(in_sequence(i.begin(), result.in, i.end())); CHECK(result.out == b.end()); CHECK(ranges::equal(a, b)); } { auto result = ranges::sample(i, b, g1); CHECK(in_sequence(i.begin(), result.in, i.end())); CHECK(result.out == b.end()); CHECK(!ranges::equal(a, b)); CHECK(!ranges::equal(b, c)); } { a.fill(0); auto result = ranges::sample(std::move(rng), a, g1); CHECK(in_sequence(i.data(), result.in.base(), i.data() + N)); CHECK(result.out == a.end()); CHECK(!ranges::equal(a, c)); } } { std::array<int, N> i; ranges::iota(i, 0); std::array<int, K> a{}, b{}, c{}; { auto result = ranges::sample(RandomAccessIterator<int*>(i.data()), Sentinel<int*>(i.data() + N), a); CHECK(in_sequence(i.data(), result.in.base(), i.data() + N)); CHECK(result.out == a.end()); CHECK(!ranges::equal(a, b)); } { auto result = ranges::sample(i, b); CHECK(in_sequence(i.begin(), result.in, i.end())); CHECK(result.out == b.end()); CHECK(!ranges::equal(b, c)); CHECK(!ranges::equal(a, b)); } } { std::array<MoveOnlyString, 10> source; std::array<MoveOnlyString, 4> dest; auto out = ranges::make_subrange( ForwardIterator<MoveOnlyString*>(dest.data()), Sentinel<MoveOnlyString*, true>(dest.data() + dest.size())); auto result = ranges::sample(ranges::make_move_iterator(source.begin()), ranges::make_move_sentinel(source.end()), out); CHECK(in_sequence(source.begin(), result.in.base(), source.end())); CHECK(result.out == ranges::end(out)); } { int data[] = {0,1,2,3}; int sample[2]; std::minstd_rand g; { auto result = ranges::sample(data, sample, g); CHECK(in_sequence(ranges::begin(data), result.in, ranges::end(data))); CHECK(result.out == ranges::end(sample)); } { auto result = ranges::sample(data, sample); CHECK(in_sequence(ranges::begin(data), result.in, ranges::end(data))); CHECK(result.out == ranges::end(sample)); } { auto result = ranges::sample(data + 0, data + 2, sample + 0, 9999); CHECK(result.in == data + 2); CHECK(result.out == sample + 2); } } return ::test_result(); }
0
repos/range-v3/test
repos/range-v3/test/algorithm/find_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 //===----------------------------------------------------------------------===// // // 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_if.hpp> #include "../simple_test.hpp" #include "../test_iterators.hpp" struct S { int i_; }; constexpr bool is_three(int i) { return i == 3; } template<class Rng> constexpr bool contains_three(Rng r) { auto it = ranges::find_if(r, is_three); return it != ranges::end(r); } int main() { using namespace ranges; int ia[] = {0, 1, 2, 3, 4, 5}; constexpr auto s = size(ia); { InputIterator<const int*> r = find_if(InputIterator<const int*>(ia), InputIterator<const int*>(ia + s), [](int i){return i == 3;}); CHECK(*r == 3); r = find_if(InputIterator<const int*>(ia), InputIterator<const int*>(ia+s), [](int i){return i == 10;}); CHECK(r == InputIterator<const int*>(ia+s)); r = find_if(InputIterator<const int*>(ia), Sentinel<const int*>(ia+s), [](int i){return i == 3;}); CHECK(*r == 3); r = find_if(InputIterator<const int*>(ia), Sentinel<const int*>(ia+s), [](int i){return i == 10;}); CHECK(r == InputIterator<const int*>(ia+s)); } { int *pi = find_if(ia, [](int i){return i == 3;}); CHECK(*pi == 3); pi = find_if(ia, [](int i){return i == 10;}); CHECK(pi == ia+s); } #ifndef RANGES_WORKAROUND_MSVC_573728 { auto pj0 = find_if(std::move(ia), [](int i){return i == 3;}); CHECK(::is_dangling(pj0)); auto pj1 = find_if(std::move(ia), [](int i){return i == 10;}); CHECK(::is_dangling(pj1)); } #endif // RANGES_WORKAROUND_MSVC_573728 { std::vector<int> const vec(begin(ia), end(ia)); auto pj0 = find_if(std::move(vec), [](int i){return i == 3;}); CHECK(::is_dangling(pj0)); auto pj1 = find_if(std::move(vec), [](int i){return i == 10;}); CHECK(::is_dangling(pj1)); } { auto* ignore = find_if(ranges::views::all(ia), [](int i){return i == 10;}); (void)ignore; } { S sa[] = {{0}, {1}, {2}, {3}, {4}, {5}}; S *ps = find_if(sa, [](int i){return i == 3;}, &S::i_); CHECK(ps->i_ == 3); ps = find_if(sa, [](int i){return i == 10;}, &S::i_); CHECK(ps == end(sa)); } { using IL = std::initializer_list<int>; STATIC_CHECK(contains_three(IL{0, 1, 2, 3})); STATIC_CHECK(!contains_three(IL{0, 1, 2})); } return ::test_result(); }
0
repos/range-v3/test
repos/range-v3/test/algorithm/partition_point.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/partition_point.hpp> #include <range/v3/view/counted.hpp> #include "../simple_test.hpp" #include "../test_utils.hpp" #include "../test_iterators.hpp" #include "../array.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[] = {2, 4, 6, 8, 10}; CHECK(ranges::partition_point(Iter(ranges::begin(ia)), Sent(ranges::end(ia)), is_odd()) == Iter(ia)); } { const int ia[] = {1, 2, 4, 6, 8}; CHECK(ranges::partition_point(Iter(ranges::begin(ia)), Sent(ranges::end(ia)), is_odd()) == Iter(ia + 1)); } { const int ia[] = {1, 3, 2, 4, 6}; CHECK(ranges::partition_point(Iter(ranges::begin(ia)), Sent(ranges::end(ia)), is_odd()) == Iter(ia + 2)); } { const int ia[] = {1, 3, 5, 2, 4, 6}; CHECK(ranges::partition_point(Iter(ranges::begin(ia)), Sent(ranges::end(ia)), is_odd()) == Iter(ia + 3)); } { const int ia[] = {1, 3, 5, 7, 2, 4}; CHECK(ranges::partition_point(Iter(ranges::begin(ia)), Sent(ranges::end(ia)), is_odd()) == Iter(ia + 4)); } { const int ia[] = {1, 3, 5, 7, 9, 2}; CHECK(ranges::partition_point(Iter(ranges::begin(ia)), Sent(ranges::end(ia)), is_odd()) == Iter(ia + 5)); } { const int ia[] = {1, 3, 5, 7, 9, 11}; CHECK(ranges::partition_point(Iter(ranges::begin(ia)), Sent(ranges::end(ia)), is_odd()) == Iter(ia + 6)); } { const int ia[] = {1, 3, 5, 2, 4, 6, 7}; CHECK(ranges::partition_point(Iter(ranges::begin(ia)), Sent(ranges::begin(ia)), is_odd()) == Iter(ia)); } } template<class Iter, class Sent = Iter> void test_range() { { const int ia[] = {2, 4, 6, 8, 10}; CHECK(ranges::partition_point(::as_lvalue(ranges::make_subrange(Iter(ranges::begin(ia)), Sent(ranges::end(ia)))), is_odd()) == Iter(ia)); } { const int ia[] = {1, 2, 4, 6, 8}; CHECK(ranges::partition_point(::as_lvalue(ranges::make_subrange(Iter(ranges::begin(ia)), Sent(ranges::end(ia)))), is_odd()) == Iter(ia + 1)); } { const int ia[] = {1, 3, 2, 4, 6}; CHECK(ranges::partition_point(::as_lvalue(ranges::make_subrange(Iter(ranges::begin(ia)), Sent(ranges::end(ia)))), is_odd()) == Iter(ia + 2)); } { const int ia[] = {1, 3, 5, 2, 4, 6}; CHECK(ranges::partition_point(::as_lvalue(ranges::make_subrange(Iter(ranges::begin(ia)), Sent(ranges::end(ia)))), is_odd()) == Iter(ia + 3)); } { const int ia[] = {1, 3, 5, 7, 2, 4}; CHECK(ranges::partition_point(::as_lvalue(ranges::make_subrange(Iter(ranges::begin(ia)), Sent(ranges::end(ia)))), is_odd()) == Iter(ia + 4)); } { const int ia[] = {1, 3, 5, 7, 9, 2}; CHECK(ranges::partition_point(::as_lvalue(ranges::make_subrange(Iter(ranges::begin(ia)), Sent(ranges::end(ia)))), is_odd()) == Iter(ia + 5)); } { const int ia[] = {1, 3, 5, 7, 9, 11}; CHECK(ranges::partition_point(::as_lvalue(ranges::make_subrange(Iter(ranges::begin(ia)), Sent(ranges::end(ia)))), is_odd()) == Iter(ia + 6)); } { const int ia[] = {1, 3, 5, 2, 4, 6, 7}; CHECK(ranges::partition_point(::as_lvalue(ranges::make_subrange(Iter(ranges::begin(ia)), Sent(ranges::begin(ia)))), is_odd()) == Iter(ia)); } // An rvalue range { const int ia[] = {1, 3, 5, 7, 9, 2}; CHECK(ranges::partition_point(ranges::make_subrange(Iter(ranges::begin(ia)), Sent(ranges::end(ia))), is_odd()) == Iter(ia + 5)); } } template<class Iter> void test_counted() { { const int ia[] = {2, 4, 6, 8, 10}; CHECK(ranges::partition_point(::as_lvalue(ranges::views::counted(Iter(ranges::begin(ia)), ranges::size(ia))), is_odd()) == ranges::counted_iterator<Iter>(Iter(ia), ranges::size(ia))); } { const int ia[] = {1, 2, 4, 6, 8}; CHECK(ranges::partition_point(::as_lvalue(ranges::views::counted(Iter(ranges::begin(ia)), ranges::size(ia))), is_odd()) == ranges::counted_iterator<Iter>(Iter(ia + 1), ranges::size(ia) - 1)); } { const int ia[] = {1, 3, 2, 4, 6}; CHECK(ranges::partition_point(::as_lvalue(ranges::views::counted(Iter(ranges::begin(ia)), ranges::size(ia))), is_odd()) == ranges::counted_iterator<Iter>(Iter(ia + 2), ranges::size(ia) - 2)); } { const int ia[] = {1, 3, 5, 2, 4, 6}; CHECK(ranges::partition_point(::as_lvalue(ranges::views::counted(Iter(ranges::begin(ia)), ranges::size(ia))), is_odd()) == ranges::counted_iterator<Iter>(Iter(ia + 3), ranges::size(ia) - 3)); } { const int ia[] = {1, 3, 5, 7, 2, 4}; CHECK(ranges::partition_point(::as_lvalue(ranges::views::counted(Iter(ranges::begin(ia)), ranges::size(ia))), is_odd()) == ranges::counted_iterator<Iter>(Iter(ia + 4), ranges::size(ia) - 4)); } { const int ia[] = {1, 3, 5, 7, 9, 2}; CHECK(ranges::partition_point(::as_lvalue(ranges::views::counted(Iter(ranges::begin(ia)), ranges::size(ia))), is_odd()) == ranges::counted_iterator<Iter>(Iter(ia + 5), ranges::size(ia) - 5)); } { const int ia[] = {1, 3, 5, 7, 9, 11}; CHECK(ranges::partition_point(::as_lvalue(ranges::views::counted(Iter(ranges::begin(ia)), ranges::size(ia))), is_odd()) == ranges::counted_iterator<Iter>(Iter(ia + 6), ranges::size(ia) - 6)); } { const int ia[] = {1, 3, 5, 2, 4, 6, 7}; CHECK(ranges::partition_point(::as_lvalue(ranges::views::counted(Iter(ranges::begin(ia)), 0)), is_odd()) == ranges::counted_iterator<Iter>(Iter(ia), 0)); } } struct S { int i; }; int main() { test_iter<ForwardIterator<const int*> >(); test_iter<ForwardIterator<const int*>, Sentinel<const int*>>(); test_range<ForwardIterator<const int*> >(); test_range<ForwardIterator<const int*>, Sentinel<const int*>>(); test_counted<ForwardIterator<const int*> >(); // Test projections const S ia[] = {S{1}, S{3}, S{5}, S{2}, S{4}, S{6}}; CHECK(ranges::partition_point(ia, is_odd(), &S::i) == ia + 3); { constexpr test::array<int, 6> a{{1, 3, 5, 2, 4, 6}}; STATIC_CHECK(ranges::partition_point(a, is_odd()) == ranges::begin(a) + 3); } return ::test_result(); }
0
repos/range-v3/test
repos/range-v3/test/algorithm/lexicographical_compare.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 <range/v3/core.hpp> #include <range/v3/algorithm/lexicographical_compare.hpp> #include "../array.hpp" #include "../simple_test.hpp" #include "../test_utils.hpp" #include "../test_iterators.hpp" template<class Iter1, class Iter2, class Sent1 = Iter1, class Sent2 = Iter2> void test_iter1() { int ia[] = {1, 2, 3, 4}; constexpr auto sa = ranges::size(ia); int ib[] = {1, 2, 3}; CHECK(!ranges::lexicographical_compare(Iter1(ia), Sent1(ia+sa), Iter2(ib), Sent2(ib+2))); CHECK(ranges::lexicographical_compare(Iter1(ib), Sent1(ib+2), Iter2(ia), Sent2(ia+sa))); CHECK(!ranges::lexicographical_compare(Iter1(ia), Sent1(ia+sa), Iter2(ib), Sent2(ib+3))); CHECK(ranges::lexicographical_compare(Iter1(ib), Sent1(ib+3), Iter2(ia), Sent2(ia+sa))); CHECK(ranges::lexicographical_compare(Iter1(ia), Sent1(ia+sa), Iter2(ib+1), Sent2(ib+3))); CHECK(!ranges::lexicographical_compare(Iter1(ib+1), Sent1(ib+3), Iter2(ia), Sent2(ia+sa))); } void test_iter() { typedef Sentinel<const int*> S; test_iter1<InputIterator<const int*>, InputIterator<const int*> >(); test_iter1<InputIterator<const int*>, ForwardIterator<const int*> >(); test_iter1<InputIterator<const int*>, BidirectionalIterator<const int*> >(); test_iter1<InputIterator<const int*>, RandomAccessIterator<const int*> >(); test_iter1<InputIterator<const int*>, InputIterator<const int*>, S, S>(); test_iter1<InputIterator<const int*>, ForwardIterator<const int*>, S, S>(); test_iter1<InputIterator<const int*>, BidirectionalIterator<const int*>, S, S>(); test_iter1<InputIterator<const int*>, RandomAccessIterator<const int*>, S, S>(); test_iter1<InputIterator<const int*>, const int*>(); test_iter1<ForwardIterator<const int*>, InputIterator<const int*> >(); test_iter1<ForwardIterator<const int*>, ForwardIterator<const int*> >(); test_iter1<ForwardIterator<const int*>, BidirectionalIterator<const int*> >(); test_iter1<ForwardIterator<const int*>, RandomAccessIterator<const int*> >(); test_iter1<ForwardIterator<const int*>, InputIterator<const int*>, S, S>(); test_iter1<ForwardIterator<const int*>, ForwardIterator<const int*>, S, S>(); test_iter1<ForwardIterator<const int*>, BidirectionalIterator<const int*>, S, S>(); test_iter1<ForwardIterator<const int*>, RandomAccessIterator<const int*>, S, S>(); test_iter1<ForwardIterator<const int*>, const int*>(); test_iter1<BidirectionalIterator<const int*>, InputIterator<const int*> >(); test_iter1<BidirectionalIterator<const int*>, ForwardIterator<const int*> >(); test_iter1<BidirectionalIterator<const int*>, BidirectionalIterator<const int*> >(); test_iter1<BidirectionalIterator<const int*>, RandomAccessIterator<const int*> >(); test_iter1<BidirectionalIterator<const int*>, InputIterator<const int*>, S, S>(); test_iter1<BidirectionalIterator<const int*>, ForwardIterator<const int*>, S, S>(); test_iter1<BidirectionalIterator<const int*>, BidirectionalIterator<const int*>, S, S>(); test_iter1<BidirectionalIterator<const int*>, RandomAccessIterator<const int*>, S, S>(); test_iter1<BidirectionalIterator<const int*>, const int*>(); test_iter1<RandomAccessIterator<const int*>, InputIterator<const int*> >(); test_iter1<RandomAccessIterator<const int*>, ForwardIterator<const int*> >(); test_iter1<RandomAccessIterator<const int*>, BidirectionalIterator<const int*> >(); test_iter1<RandomAccessIterator<const int*>, RandomAccessIterator<const int*> >(); test_iter1<RandomAccessIterator<const int*>, InputIterator<const int*>, S, S>(); test_iter1<RandomAccessIterator<const int*>, ForwardIterator<const int*>, S, S>(); test_iter1<RandomAccessIterator<const int*>, BidirectionalIterator<const int*>, S, S>(); test_iter1<RandomAccessIterator<const int*>, RandomAccessIterator<const int*>, S, S>(); test_iter1<RandomAccessIterator<const int*>, const int*>(); test_iter1<const int*, InputIterator<const int*> >(); test_iter1<const int*, ForwardIterator<const int*> >(); test_iter1<const int*, BidirectionalIterator<const int*> >(); test_iter1<const int*, RandomAccessIterator<const int*> >(); test_iter1<const int*, InputIterator<const int*>, const int*, S>(); test_iter1<const int*, ForwardIterator<const int*>, const int*, S>(); test_iter1<const int*, BidirectionalIterator<const int*>, const int*, S>(); test_iter1<const int*, RandomAccessIterator<const int*>, const int*, S>(); test_iter1<const int*, const int*>(); } template<class Iter1, class Iter2, class Sent1 = Iter1, class Sent2 = Iter2> void test_iter_comp1() { int ia[] = {1, 2, 3, 4}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); int ib[] = {1, 2, 3}; typedef std::greater<int> C; C c; CHECK(!ranges::lexicographical_compare(Iter1(ia), Sent1(ia+sa), Iter2(ib), Sent2(ib+2), c)); CHECK(ranges::lexicographical_compare(Iter1(ib), Sent1(ib+2), Iter2(ia), Sent2(ia+sa), c)); CHECK(!ranges::lexicographical_compare(Iter1(ia), Sent1(ia+sa), Iter2(ib), Sent2(ib+3), c)); CHECK(ranges::lexicographical_compare(Iter1(ib), Sent1(ib+3), Iter2(ia), Sent2(ia+sa), c)); CHECK(!ranges::lexicographical_compare(Iter1(ia), Sent1(ia+sa), Iter2(ib+1), Sent2(ib+3), c)); CHECK(ranges::lexicographical_compare(Iter1(ib+1), Sent1(ib+3), Iter2(ia), Sent2(ia+sa), c)); } void test_iter_comp() { typedef Sentinel<const int*> S; test_iter_comp1<InputIterator<const int*>, InputIterator<const int*> >(); test_iter_comp1<InputIterator<const int*>, ForwardIterator<const int*> >(); test_iter_comp1<InputIterator<const int*>, BidirectionalIterator<const int*> >(); test_iter_comp1<InputIterator<const int*>, RandomAccessIterator<const int*> >(); test_iter_comp1<InputIterator<const int*>, InputIterator<const int*>, S, S>(); test_iter_comp1<InputIterator<const int*>, ForwardIterator<const int*>, S, S>(); test_iter_comp1<InputIterator<const int*>, BidirectionalIterator<const int*>, S, S>(); test_iter_comp1<InputIterator<const int*>, RandomAccessIterator<const int*>, S, S>(); test_iter_comp1<InputIterator<const int*>, const int*>(); test_iter_comp1<ForwardIterator<const int*>, InputIterator<const int*> >(); test_iter_comp1<ForwardIterator<const int*>, ForwardIterator<const int*> >(); test_iter_comp1<ForwardIterator<const int*>, BidirectionalIterator<const int*> >(); test_iter_comp1<ForwardIterator<const int*>, RandomAccessIterator<const int*> >(); test_iter_comp1<ForwardIterator<const int*>, InputIterator<const int*>, S, S>(); test_iter_comp1<ForwardIterator<const int*>, ForwardIterator<const int*>, S, S>(); test_iter_comp1<ForwardIterator<const int*>, BidirectionalIterator<const int*>, S, S>(); test_iter_comp1<ForwardIterator<const int*>, RandomAccessIterator<const int*>, S, S>(); test_iter_comp1<ForwardIterator<const int*>, const int*>(); test_iter_comp1<BidirectionalIterator<const int*>, InputIterator<const int*> >(); test_iter_comp1<BidirectionalIterator<const int*>, ForwardIterator<const int*> >(); test_iter_comp1<BidirectionalIterator<const int*>, BidirectionalIterator<const int*> >(); test_iter_comp1<BidirectionalIterator<const int*>, RandomAccessIterator<const int*> >(); test_iter_comp1<BidirectionalIterator<const int*>, InputIterator<const int*>, S, S>(); test_iter_comp1<BidirectionalIterator<const int*>, ForwardIterator<const int*>, S, S>(); test_iter_comp1<BidirectionalIterator<const int*>, BidirectionalIterator<const int*>, S, S>(); test_iter_comp1<BidirectionalIterator<const int*>, RandomAccessIterator<const int*>, S, S>(); test_iter_comp1<BidirectionalIterator<const int*>, const int*>(); test_iter_comp1<RandomAccessIterator<const int*>, InputIterator<const int*> >(); test_iter_comp1<RandomAccessIterator<const int*>, ForwardIterator<const int*> >(); test_iter_comp1<RandomAccessIterator<const int*>, BidirectionalIterator<const int*> >(); test_iter_comp1<RandomAccessIterator<const int*>, RandomAccessIterator<const int*> >(); test_iter_comp1<RandomAccessIterator<const int*>, InputIterator<const int*>, S, S>(); test_iter_comp1<RandomAccessIterator<const int*>, ForwardIterator<const int*>, S, S>(); test_iter_comp1<RandomAccessIterator<const int*>, BidirectionalIterator<const int*>, S, S>(); test_iter_comp1<RandomAccessIterator<const int*>, RandomAccessIterator<const int*>, S, S>(); test_iter_comp1<RandomAccessIterator<const int*>, const int*>(); test_iter_comp1<const int*, InputIterator<const int*> >(); test_iter_comp1<const int*, ForwardIterator<const int*> >(); test_iter_comp1<const int*, BidirectionalIterator<const int*> >(); test_iter_comp1<const int*, RandomAccessIterator<const int*> >(); test_iter_comp1<const int*, InputIterator<const int*>, const int*, S>(); test_iter_comp1<const int*, ForwardIterator<const int*>, const int*, S>(); test_iter_comp1<const int*, BidirectionalIterator<const int*>, const int*, S>(); test_iter_comp1<const int*, RandomAccessIterator<const int*>, const int*, S>(); test_iter_comp1<const int*, const int*>(); } constexpr bool test_constexpr() { test::array<int, 4> ia{{1, 2, 3, 4}}; test::array<int, 3> ib{{1, 2, 3}}; auto ia_b = ranges::begin(ia); auto ia_e = ranges::end(ia); auto ib_b = ranges::begin(ib); auto ib_1 = ib_b + 1; auto ib_2 = ib_b + 2; auto ib_3 = ib_b + 3; STATIC_CHECK_RETURN(!ranges::lexicographical_compare(ia_b, ia_e, ib_b, ib_2)); STATIC_CHECK_RETURN(ranges::lexicographical_compare(ib_b, ib_2, ia_b, ia_e)); STATIC_CHECK_RETURN(!ranges::lexicographical_compare(ia_b, ia_e, ib_b, ib_3)); STATIC_CHECK_RETURN(ranges::lexicographical_compare(ib_b, ib_3, ia_b, ia_e)); STATIC_CHECK_RETURN(ranges::lexicographical_compare(ia_b, ia_e, ib_1, ib_3)); STATIC_CHECK_RETURN(!ranges::lexicographical_compare(ib_1, ib_3, ia_b, ia_e)); typedef std::greater<int> C; C c{}; STATIC_CHECK_RETURN(!ranges::lexicographical_compare(ia_b, ia_e, ib_b, ib_2, c)); STATIC_CHECK_RETURN(ranges::lexicographical_compare(ib_b, ib_2, ia_b, ia_e, c)); STATIC_CHECK_RETURN(!ranges::lexicographical_compare(ia_b, ia_e, ib_b, ib_3, c)); STATIC_CHECK_RETURN(ranges::lexicographical_compare(ib_b, ib_3, ia_b, ia_e, c)); STATIC_CHECK_RETURN(!ranges::lexicographical_compare(ia_b, ia_e, ib_1, ib_3, c)); STATIC_CHECK_RETURN(ranges::lexicographical_compare(ib_1, ib_3, ia_b, ia_e, c)); return true; } int main() { test_iter(); test_iter_comp(); { STATIC_CHECK(test_constexpr()); } return test_result(); }
0
repos/range-v3/test
repos/range-v3/test/algorithm/make_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); CHECK(ranges::make_heap(ia, ia+N) == ia+N); CHECK(std::is_heap(ia, ia+N)); 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); CHECK(ranges::make_heap(ia, Sentinel<int*>(ia+N)) == ia+N); CHECK(std::is_heap(ia, ia+N)); 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); CHECK(ranges::make_heap(ranges::make_subrange(ia, ia+N)) == ia+N); CHECK(std::is_heap(ia, ia+N)); std::shuffle(ia, ia+N, gen); CHECK(::is_dangling(ranges::make_heap(::MakeTestRange(ia, ia+N)))); CHECK(std::is_heap(ia, ia+N)); 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); CHECK(ranges::make_heap(ranges::make_subrange(ia, Sentinel<int*>(ia+N))) == ia+N); CHECK(std::is_heap(ia, ia+N)); std::shuffle(ia, ia+N, gen); CHECK(::is_dangling(ranges::make_heap(::MakeTestRange(ia, Sentinel<int*>(ia+N))))); CHECK(std::is_heap(ia, ia+N)); 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); CHECK(ranges::make_heap(ia, ia+N, std::greater<int>()) == ia+N); CHECK(std::is_heap(ia, ia+N, std::greater<int>())); 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); CHECK(ranges::make_heap(ia, Sentinel<int*>(ia+N), std::greater<int>()) == ia+N); CHECK(std::is_heap(ia, ia+N, std::greater<int>())); 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); CHECK(ranges::make_heap(ranges::make_subrange(ia, ia+N), std::greater<int>()) == ia+N); CHECK(std::is_heap(ia, ia+N, std::greater<int>())); std::shuffle(ia, ia+N, gen); CHECK(::is_dangling(ranges::make_heap(::MakeTestRange(ia, ia+N), std::greater<int>()))); CHECK(std::is_heap(ia, ia+N, std::greater<int>())); 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); CHECK(ranges::make_heap(ranges::make_subrange(ia, Sentinel<int*>(ia+N)), std::greater<int>()) == ia+N); CHECK(std::is_heap(ia, ia+N, std::greater<int>())); std::shuffle(ia, ia+N, gen); CHECK(::is_dangling(ranges::make_heap(::MakeTestRange(ia, Sentinel<int*>(ia+N)), std::greater<int>()))); CHECK(std::is_heap(ia, ia+N, std::greater<int>())); 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); CHECK(ranges::make_heap(ia, ia+N, indirect_less()) == ia+N); CHECK(std::is_heap(ia, ia+N, indirect_less())); delete [] ia; } 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) ib[i].i = i; std::shuffle(ia, ia+N, gen); CHECK(ranges::make_heap(ib, ib+N, std::less<int>(), &S::i) == ib+N); std::transform(ib, ib+N, ia, std::mem_fn(&S::i)); CHECK(std::is_heap(ia, ia+N)); delete [] ia; delete [] ib; } void test_all(int N) { test_1(N); test_2(N); test_3(N); test_4(N); test_5(N); test_6(N); test_7(N); test_8(N); } 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] = N - 1 - i; STATIC_CHECK_RETURN(make_heap(begin(ia), end(ia), std::less<int>{}) == end(ia)); STATIC_CHECK_RETURN(is_heap(begin(ia), end(ia))); return true; } } int main() { test_all(0); test_all(1); test_all(2); test_all(3); test_all(10); test_all(1000); test_9(1000); test_10(1000); { STATIC_CHECK(test_constexpr()); } return test_result(); }
0
repos/range-v3/test
repos/range-v3/test/algorithm/fill_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 //===----------------------------------------------------------------------===// // // 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/algorithm/equal.hpp> #include <range/v3/algorithm/fill.hpp> #include <range/v3/core.hpp> #include "../array.hpp" #include "../simple_test.hpp" #include "../test_iterators.hpp" #include "../test_utils.hpp" #ifdef RANGES_CXX_GREATER_THAN_11 RANGES_CXX14_CONSTEXPR auto fives() { array<int, 4> a{{0}}; ranges::fill(a, 5); return a; } RANGES_CXX14_CONSTEXPR auto fives(int n) { array<int, 4> a{{0}}; ranges::fill_n(ranges::begin(a), n, 5); return a; } #endif int main() { test_char<forward_iterator<char *>>(); test_char<bidirectional_iterator<char *>>(); test_char<random_access_iterator<char *>>(); test_char<char *>(); test_char<forward_iterator<char *>, sentinel<char *>>(); test_char<bidirectional_iterator<char *>, sentinel<char *>>(); test_char<random_access_iterator<char *>, sentinel<char *>>(); test_int<forward_iterator<int *>>(); test_int<bidirectional_iterator<int *>>(); test_int<random_access_iterator<int *>>(); test_int<int *>(); test_int<forward_iterator<int *>, sentinel<int *>>(); test_int<bidirectional_iterator<int *>, sentinel<int *>>(); test_int<random_access_iterator<int *>, sentinel<int *>>(); #ifdef RANGES_CXX_GREATER_THAN_11 { STATIC_CHECK(ranges::equal(fives(), {5, 5, 5, 5})); STATIC_CHECK(ranges::equal(fives(2), {5, 5, 0, 0})); STATIC_CHECK(!ranges::equal(fives(2), {5, 5, 5, 5})); } #endif return ::test_result(); }
0
repos/range-v3/test
repos/range-v3/test/algorithm/set_symmetric_difference.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 // //===----------------------------------------------------------------------===// // // 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 <functional> #include <vector> #include <range/v3/core.hpp> #include <range/v3/algorithm/fill.hpp> #include <range/v3/algorithm/set_algorithm.hpp> #include <range/v3/algorithm/lexicographical_compare.hpp> #include "../simple_test.hpp" #include "../test_utils.hpp" #include "../test_iterators.hpp" template<class Iter1, class Iter2, class OutIter> void test_iter() { int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4}; static const int sa = sizeof(ia)/sizeof(ia[0]); int ib[] = {2, 4, 4, 6}; static const int sb = sizeof(ib)/sizeof(ib[0]); int ic[20]; int ir[] = {1, 2, 3, 3, 3, 4, 4, 6}; static const int sr = sizeof(ir)/sizeof(ir[0]); auto set_symmetric_difference = ::make_testable_2(ranges::set_symmetric_difference); set_symmetric_difference(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+sb), OutIter(ic)). check([&](ranges::set_symmetric_difference_result<Iter1, Iter2, OutIter> res) { CHECK((base(res.out) - ic) == sr); CHECK(std::lexicographical_compare(ic, base(res.out), ir, ir+sr) == false); ranges::fill(ic, 0); } ); set_symmetric_difference(Iter1(ib), Iter1(ib+sb), Iter2(ia), Iter2(ia+sa), OutIter(ic)). check([&](ranges::set_symmetric_difference_result<Iter1, Iter2, OutIter> res) { CHECK((base(res.out) - ic) == sr); CHECK(std::lexicographical_compare(ic, base(res.out), ir, ir+sr) == false); ranges::fill(ic, 0); } ); } template<class Iter1, class Iter2, class OutIter> void test_comp() { int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4}; static const int sa = sizeof(ia)/sizeof(ia[0]); int ib[] = {2, 4, 4, 6}; static const int sb = sizeof(ib)/sizeof(ib[0]); int ic[20]; int ir[] = {1, 2, 3, 3, 3, 4, 4, 6}; static const int sr = sizeof(ir)/sizeof(ir[0]); auto set_symmetric_difference = ::make_testable_2(ranges::set_symmetric_difference); set_symmetric_difference(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+sb), OutIter(ic), std::less<int>()). check([&](ranges::set_symmetric_difference_result<Iter1, Iter2, OutIter> res) { CHECK((base(res.out) - ic) == sr); CHECK(std::lexicographical_compare(ic, base(res.out), ir, ir+sr) == false); ranges::fill(ic, 0); } ); set_symmetric_difference(Iter1(ib), Iter1(ib+sb), Iter2(ia), Iter2(ia+sa), OutIter(ic), std::less<int>()). check([&](ranges::set_symmetric_difference_result<Iter1, Iter2, OutIter> res) { CHECK((base(res.out) - ic) == sr); CHECK(std::lexicographical_compare(ic, base(res.out), ir, ir+sr) == false); ranges::fill(ic, 0); } ); } template<class Iter1, class Iter2, class OutIter> void test() { test_iter<Iter1, Iter2, OutIter>(); test_comp<Iter1, Iter2, OutIter>(); } struct S { int i; }; struct T { int j; }; struct U { int k; U& operator=(S s) { k = s.i; return *this;} U& operator=(T t) { k = t.j; return *this;} }; constexpr bool test_constexpr() { using namespace ranges; int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4}; int ib[] = {2, 4, 4, 6}; int ic[20] = {0}; int ir[] = {1, 2, 3, 3, 3, 4, 4, 6}; const int sr = sizeof(ir) / sizeof(ir[0]); const auto res1 = set_symmetric_difference(ia, ib, ic, less{}); STATIC_CHECK_RETURN(res1.in1 == end(ia)); STATIC_CHECK_RETURN(res1.in2 == end(ib)); STATIC_CHECK_RETURN((res1.out - begin(ic)) == sr); STATIC_CHECK_RETURN(lexicographical_compare(ic, res1.out, ir, ir + sr, less{}) == 0); fill(ic, 0); const auto res2 = set_symmetric_difference(ib, ia, ic, less{}); STATIC_CHECK_RETURN(res2.in1 == end(ib)); STATIC_CHECK_RETURN(res2.in2 == end(ia)); STATIC_CHECK_RETURN(res2.out - begin(ic) == sr); STATIC_CHECK_RETURN(lexicographical_compare(ic, res2.out, ir, ir + sr, less{}) == 0); return true; } int main() { #ifdef SET_SYMMETRIC_DIFFERENCE_1 test<InputIterator<const int*>, InputIterator<const int*>, OutputIterator<int*> >(); test<InputIterator<const int*>, InputIterator<const int*>, ForwardIterator<int*> >(); test<InputIterator<const int*>, InputIterator<const int*>, BidirectionalIterator<int*> >(); test<InputIterator<const int*>, InputIterator<const int*>, RandomAccessIterator<int*> >(); test<InputIterator<const int*>, InputIterator<const int*>, int*>(); test<InputIterator<const int*>, ForwardIterator<const int*>, OutputIterator<int*> >(); test<InputIterator<const int*>, ForwardIterator<const int*>, ForwardIterator<int*> >(); test<InputIterator<const int*>, ForwardIterator<const int*>, BidirectionalIterator<int*> >(); test<InputIterator<const int*>, ForwardIterator<const int*>, RandomAccessIterator<int*> >(); test<InputIterator<const int*>, ForwardIterator<const int*>, int*>(); test<InputIterator<const int*>, BidirectionalIterator<const int*>, OutputIterator<int*> >(); test<InputIterator<const int*>, BidirectionalIterator<const int*>, ForwardIterator<int*> >(); test<InputIterator<const int*>, BidirectionalIterator<const int*>, BidirectionalIterator<int*> >(); test<InputIterator<const int*>, BidirectionalIterator<const int*>, RandomAccessIterator<int*> >(); test<InputIterator<const int*>, BidirectionalIterator<const int*>, int*>(); test<InputIterator<const int*>, RandomAccessIterator<const int*>, OutputIterator<int*> >(); test<InputIterator<const int*>, RandomAccessIterator<const int*>, ForwardIterator<int*> >(); test<InputIterator<const int*>, RandomAccessIterator<const int*>, BidirectionalIterator<int*> >(); test<InputIterator<const int*>, RandomAccessIterator<const int*>, RandomAccessIterator<int*> >(); test<InputIterator<const int*>, RandomAccessIterator<const int*>, int*>(); test<InputIterator<const int*>, const int*, OutputIterator<int*> >(); test<InputIterator<const int*>, const int*, ForwardIterator<int*> >(); test<InputIterator<const int*>, const int*, BidirectionalIterator<int*> >(); test<InputIterator<const int*>, const int*, RandomAccessIterator<int*> >(); test<InputIterator<const int*>, const int*, int*>(); #endif #ifdef SET_SYMMETRIC_DIFFERENCE_2 test<ForwardIterator<const int*>, InputIterator<const int*>, OutputIterator<int*> >(); test<ForwardIterator<const int*>, InputIterator<const int*>, ForwardIterator<int*> >(); test<ForwardIterator<const int*>, InputIterator<const int*>, BidirectionalIterator<int*> >(); test<ForwardIterator<const int*>, InputIterator<const int*>, RandomAccessIterator<int*> >(); test<ForwardIterator<const int*>, InputIterator<const int*>, int*>(); test<ForwardIterator<const int*>, ForwardIterator<const int*>, OutputIterator<int*> >(); test<ForwardIterator<const int*>, ForwardIterator<const int*>, ForwardIterator<int*> >(); test<ForwardIterator<const int*>, ForwardIterator<const int*>, BidirectionalIterator<int*> >(); test<ForwardIterator<const int*>, ForwardIterator<const int*>, RandomAccessIterator<int*> >(); test<ForwardIterator<const int*>, ForwardIterator<const int*>, int*>(); test<ForwardIterator<const int*>, BidirectionalIterator<const int*>, OutputIterator<int*> >(); test<ForwardIterator<const int*>, BidirectionalIterator<const int*>, ForwardIterator<int*> >(); test<ForwardIterator<const int*>, BidirectionalIterator<const int*>, BidirectionalIterator<int*> >(); test<ForwardIterator<const int*>, BidirectionalIterator<const int*>, RandomAccessIterator<int*> >(); test<ForwardIterator<const int*>, BidirectionalIterator<const int*>, int*>(); test<ForwardIterator<const int*>, RandomAccessIterator<const int*>, OutputIterator<int*> >(); test<ForwardIterator<const int*>, RandomAccessIterator<const int*>, ForwardIterator<int*> >(); test<ForwardIterator<const int*>, RandomAccessIterator<const int*>, BidirectionalIterator<int*> >(); test<ForwardIterator<const int*>, RandomAccessIterator<const int*>, RandomAccessIterator<int*> >(); test<ForwardIterator<const int*>, RandomAccessIterator<const int*>, int*>(); test<ForwardIterator<const int*>, const int*, OutputIterator<int*> >(); test<ForwardIterator<const int*>, const int*, ForwardIterator<int*> >(); test<ForwardIterator<const int*>, const int*, BidirectionalIterator<int*> >(); test<ForwardIterator<const int*>, const int*, RandomAccessIterator<int*> >(); test<ForwardIterator<const int*>, const int*, int*>(); #endif #ifdef SET_SYMMETRIC_DIFFERENCE_3 test<BidirectionalIterator<const int*>, InputIterator<const int*>, OutputIterator<int*> >(); test<BidirectionalIterator<const int*>, InputIterator<const int*>, ForwardIterator<int*> >(); test<BidirectionalIterator<const int*>, InputIterator<const int*>, BidirectionalIterator<int*> >(); test<BidirectionalIterator<const int*>, InputIterator<const int*>, RandomAccessIterator<int*> >(); test<BidirectionalIterator<const int*>, InputIterator<const int*>, int*>(); test<BidirectionalIterator<const int*>, ForwardIterator<const int*>, OutputIterator<int*> >(); test<BidirectionalIterator<const int*>, ForwardIterator<const int*>, ForwardIterator<int*> >(); test<BidirectionalIterator<const int*>, ForwardIterator<const int*>, BidirectionalIterator<int*> >(); test<BidirectionalIterator<const int*>, ForwardIterator<const int*>, RandomAccessIterator<int*> >(); test<BidirectionalIterator<const int*>, ForwardIterator<const int*>, int*>(); test<BidirectionalIterator<const int*>, BidirectionalIterator<const int*>, OutputIterator<int*> >(); test<BidirectionalIterator<const int*>, BidirectionalIterator<const int*>, ForwardIterator<int*> >(); test<BidirectionalIterator<const int*>, BidirectionalIterator<const int*>, BidirectionalIterator<int*> >(); test<BidirectionalIterator<const int*>, BidirectionalIterator<const int*>, RandomAccessIterator<int*> >(); test<BidirectionalIterator<const int*>, BidirectionalIterator<const int*>, int*>(); test<BidirectionalIterator<const int*>, RandomAccessIterator<const int*>, OutputIterator<int*> >(); test<BidirectionalIterator<const int*>, RandomAccessIterator<const int*>, ForwardIterator<int*> >(); test<BidirectionalIterator<const int*>, RandomAccessIterator<const int*>, BidirectionalIterator<int*> >(); test<BidirectionalIterator<const int*>, RandomAccessIterator<const int*>, RandomAccessIterator<int*> >(); test<BidirectionalIterator<const int*>, RandomAccessIterator<const int*>, int*>(); test<BidirectionalIterator<const int*>, const int*, OutputIterator<int*> >(); test<BidirectionalIterator<const int*>, const int*, ForwardIterator<int*> >(); test<BidirectionalIterator<const int*>, const int*, BidirectionalIterator<int*> >(); test<BidirectionalIterator<const int*>, const int*, RandomAccessIterator<int*> >(); test<BidirectionalIterator<const int*>, const int*, int*>(); #endif #ifdef SET_SYMMETRIC_DIFFERENCE_4 test<RandomAccessIterator<const int*>, InputIterator<const int*>, OutputIterator<int*> >(); test<RandomAccessIterator<const int*>, InputIterator<const int*>, ForwardIterator<int*> >(); test<RandomAccessIterator<const int*>, InputIterator<const int*>, BidirectionalIterator<int*> >(); test<RandomAccessIterator<const int*>, InputIterator<const int*>, RandomAccessIterator<int*> >(); test<RandomAccessIterator<const int*>, InputIterator<const int*>, int*>(); test<RandomAccessIterator<const int*>, ForwardIterator<const int*>, OutputIterator<int*> >(); test<RandomAccessIterator<const int*>, ForwardIterator<const int*>, ForwardIterator<int*> >(); test<RandomAccessIterator<const int*>, ForwardIterator<const int*>, BidirectionalIterator<int*> >(); test<RandomAccessIterator<const int*>, ForwardIterator<const int*>, RandomAccessIterator<int*> >(); test<RandomAccessIterator<const int*>, ForwardIterator<const int*>, int*>(); test<RandomAccessIterator<const int*>, BidirectionalIterator<const int*>, OutputIterator<int*> >(); test<RandomAccessIterator<const int*>, BidirectionalIterator<const int*>, ForwardIterator<int*> >(); test<RandomAccessIterator<const int*>, BidirectionalIterator<const int*>, BidirectionalIterator<int*> >(); test<RandomAccessIterator<const int*>, BidirectionalIterator<const int*>, RandomAccessIterator<int*> >(); test<RandomAccessIterator<const int*>, BidirectionalIterator<const int*>, int*>(); test<RandomAccessIterator<const int*>, RandomAccessIterator<const int*>, OutputIterator<int*> >(); test<RandomAccessIterator<const int*>, RandomAccessIterator<const int*>, ForwardIterator<int*> >(); test<RandomAccessIterator<const int*>, RandomAccessIterator<const int*>, BidirectionalIterator<int*> >(); test<RandomAccessIterator<const int*>, RandomAccessIterator<const int*>, RandomAccessIterator<int*> >(); test<RandomAccessIterator<const int*>, RandomAccessIterator<const int*>, int*>(); test<RandomAccessIterator<const int*>, const int*, OutputIterator<int*> >(); test<RandomAccessIterator<const int*>, const int*, ForwardIterator<int*> >(); test<RandomAccessIterator<const int*>, const int*, BidirectionalIterator<int*> >(); test<RandomAccessIterator<const int*>, const int*, RandomAccessIterator<int*> >(); test<RandomAccessIterator<const int*>, const int*, int*>(); #endif #ifdef SET_SYMMETRIC_DIFFERENCE_5 test<const int*, InputIterator<const int*>, OutputIterator<int*> >(); test<const int*, InputIterator<const int*>, BidirectionalIterator<int*> >(); test<const int*, InputIterator<const int*>, BidirectionalIterator<int*> >(); test<const int*, InputIterator<const int*>, RandomAccessIterator<int*> >(); test<const int*, InputIterator<const int*>, int*>(); test<const int*, ForwardIterator<const int*>, OutputIterator<int*> >(); test<const int*, ForwardIterator<const int*>, ForwardIterator<int*> >(); test<const int*, ForwardIterator<const int*>, BidirectionalIterator<int*> >(); test<const int*, ForwardIterator<const int*>, RandomAccessIterator<int*> >(); test<const int*, ForwardIterator<const int*>, int*>(); test<const int*, BidirectionalIterator<const int*>, OutputIterator<int*> >(); test<const int*, BidirectionalIterator<const int*>, ForwardIterator<int*> >(); test<const int*, BidirectionalIterator<const int*>, BidirectionalIterator<int*> >(); test<const int*, BidirectionalIterator<const int*>, RandomAccessIterator<int*> >(); test<const int*, BidirectionalIterator<const int*>, int*>(); test<const int*, RandomAccessIterator<const int*>, OutputIterator<int*> >(); test<const int*, RandomAccessIterator<const int*>, ForwardIterator<int*> >(); test<const int*, RandomAccessIterator<const int*>, BidirectionalIterator<int*> >(); test<const int*, RandomAccessIterator<const int*>, RandomAccessIterator<int*> >(); test<const int*, RandomAccessIterator<const int*>, int*>(); test<const int*, const int*, OutputIterator<int*> >(); test<const int*, const int*, ForwardIterator<int*> >(); test<const int*, const int*, BidirectionalIterator<int*> >(); test<const int*, const int*, RandomAccessIterator<int*> >(); test<const int*, const int*, int*>(); #endif #ifdef SET_SYMMETRIC_DIFFERENCE_6 // Test projections { S ia[] = {S{1}, S{2}, S{2}, S{3}, S{3}, S{3}, S{4}, S{4}, S{4}, S{4}}; T ib[] = {T{2}, T{4}, T{4}, T{6}}; U ic[20]; int ir[] = {1, 2, 3, 3, 3, 4, 4, 6}; static const int sr = sizeof(ir)/sizeof(ir[0]); ranges::set_symmetric_difference_result<S *, T *, U *> res1 = ranges::set_symmetric_difference(ia, ib, ic, std::less<int>(), &S::i, &T::j); CHECK((res1.out - ic) == sr); CHECK(ranges::lexicographical_compare(ic, res1.out, ir, ir+sr, std::less<int>(), &U::k) == false); ranges::fill(ic, U{0}); ranges::set_symmetric_difference_result<T *, S *, U *> res2 = ranges::set_symmetric_difference(ib, ia, ic, std::less<int>(), &T::j, &S::i); CHECK((res2.out - ic) == sr); CHECK(ranges::lexicographical_compare(ic, res2.out, ir, ir+sr, std::less<int>(), &U::k) == false); } // Test rvalue ranges #ifndef RANGES_WORKAROUND_MSVC_573728 { S ia[] = {S{1}, S{2}, S{2}, S{3}, S{3}, S{3}, S{4}, S{4}, S{4}, S{4}}; T ib[] = {T{2}, T{4}, T{4}, T{6}}; U ic[20]; int ir[] = {1, 2, 3, 3, 3, 4, 4, 6}; static const int sr = sizeof(ir)/sizeof(ir[0]); auto res1 = ranges::set_symmetric_difference(std::move(ia), ranges::views::all(ib), ic, std::less<int>(), &S::i, &T::j); CHECK(::is_dangling(res1.in1)); CHECK(res1.in2 == ranges::end(ib)); CHECK((res1.out - ic) == sr); CHECK(ranges::lexicographical_compare(ic, res1.out, ir, ir+sr, std::less<int>(), &U::k) == false); ranges::fill(ic, U{0}); auto res2 = ranges::set_symmetric_difference(ranges::views::all(ib), std::move(ia), ic, std::less<int>(), &T::j, &S::i); CHECK(res2.in1 == ranges::end(ib)); CHECK(::is_dangling(res2.in2)); CHECK((res2.out - ic) == sr); CHECK(ranges::lexicographical_compare(ic, res2.out, ir, ir+sr, std::less<int>(), &U::k) == false); } #endif // RANGES_WORKAROUND_MSVC_573728 { std::vector<S> ia{S{1}, S{2}, S{2}, S{3}, S{3}, S{3}, S{4}, S{4}, S{4}, S{4}}; std::vector<T> ib{T{2}, T{4}, T{4}, T{6}}; U ic[20]; int ir[] = {1, 2, 3, 3, 3, 4, 4, 6}; static const int sr = sizeof(ir)/sizeof(ir[0]); auto res1 = ranges::set_symmetric_difference(std::move(ia), ranges::views::all(ib), ic, std::less<int>(), &S::i, &T::j); CHECK(::is_dangling(res1.in1)); CHECK(res1.in2 == ranges::end(ib)); CHECK((res1.out - ic) == sr); CHECK(ranges::lexicographical_compare(ic, res1.out, ir, ir+sr, std::less<int>(), &U::k) == false); ranges::fill(ic, U{0}); auto res2 = ranges::set_symmetric_difference(ranges::views::all(ib), std::move(ia), ic, std::less<int>(), &T::j, &S::i); CHECK(res2.in1 == ranges::end(ib)); CHECK(::is_dangling(res2.in2)); CHECK((res2.out - ic) == sr); CHECK(ranges::lexicographical_compare(ic, res2.out, ir, ir+sr, std::less<int>(), &U::k) == false); } { STATIC_CHECK(test_constexpr()); } #endif return ::test_result(); }
0
repos/range-v3/test
repos/range-v3/test/algorithm/sort_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 <range/v3/algorithm/is_sorted.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 { constexpr bool test_constexpr() { using namespace ranges; bool r = true; constexpr int N = 100; test::array<int, N> ia{{0}}; for(int i = 0; i < N; ++i) ia[i] = N - 1 - i; make_heap(begin(ia), end(ia)); STATIC_CHECK_RETURN(sort_heap(begin(ia), end(ia), ranges::less{}) == end(ia)); STATIC_CHECK_RETURN(is_sorted(ia)); return r; } 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); CHECK(ranges::sort_heap(ia, ia+N) == ia+N); CHECK(std::is_sorted(ia, ia+N)); 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); CHECK(ranges::sort_heap(ia, Sentinel<int*>(ia+N)) == ia+N); CHECK(std::is_sorted(ia, ia+N)); 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); CHECK(ranges::sort_heap(::as_lvalue(ranges::make_subrange(ia, ia+N))) == ia+N); CHECK(std::is_sorted(ia, ia+N)); 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); CHECK(ranges::sort_heap(::as_lvalue(ranges::make_subrange(ia, Sentinel<int*>(ia+N)))) == ia+N); CHECK(std::is_sorted(ia, ia+N)); 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>()); CHECK(ranges::sort_heap(ia, ia+N, std::greater<int>()) == ia+N); CHECK(std::is_sorted(ia, ia+N, std::greater<int>())); 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>()); CHECK(ranges::sort_heap(ia, Sentinel<int*>(ia+N), std::greater<int>()) == ia+N); CHECK(std::is_sorted(ia, ia+N, std::greater<int>())); 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>()); CHECK(ranges::sort_heap(::as_lvalue(ranges::make_subrange(ia, ia+N)), std::greater<int>()) == ia+N); CHECK(std::is_sorted(ia, ia+N, std::greater<int>())); 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>()); CHECK(ranges::sort_heap(ranges::make_subrange(ia, Sentinel<int*>(ia+N)), std::greater<int>()) == ia+N); CHECK(std::is_sorted(ia, ia+N, std::greater<int>())); 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()); CHECK(ranges::sort_heap(ia, ia+N, indirect_less()) == ia+N); CHECK(std::is_sorted(ia, ia+N, indirect_less())); delete[] ia; } struct S { int i; }; void test_10(int N) { S* ia = new S[N]; int* ib = new int[N]; for (int i = 0; i < N; ++i) ib[i] = i; std::shuffle(ib, ib+N, gen); std::make_heap(ib, ib+N); std::transform(ib, ib+N, ia, [](int i){return S{i};}); CHECK(ranges::sort_heap(ia, ia+N, std::less<int>(), &S::i) == ia+N); std::transform(ia, ia+N, ib, std::mem_fn(&S::i)); CHECK(std::is_sorted(ib, ib+N)); delete[] ia; delete[] ib; } void test_all(int N) { test_1(N); test_2(N); test_3(N); test_4(N); test_5(N); test_6(N); test_7(N); test_8(N); } } int main() { test_all(0); test_all(1); test_all(2); test_all(3); test_all(10); test_all(1000); test_9(1000); test_10(1000); { STATIC_CHECK(test_constexpr()); } return test_result(); }
0
repos/range-v3/test
repos/range-v3/test/algorithm/set_union.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 // //===----------------------------------------------------------------------===// // // 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 <functional> #include <vector> #include <range/v3/core.hpp> #include <range/v3/algorithm/fill.hpp> #include <range/v3/algorithm/set_algorithm.hpp> #include <range/v3/algorithm/lexicographical_compare.hpp> #include "../simple_test.hpp" #include "../test_utils.hpp" #include "../test_iterators.hpp" template<class Iter1, class Iter2, class OutIter> void test() { int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4}; static const int sa = sizeof(ia)/sizeof(ia[0]); int ib[] = {2, 4, 4, 6}; static const int sb = sizeof(ib)/sizeof(ib[0]); int ic[20]; int ir[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 6}; static const int sr = sizeof(ir)/sizeof(ir[0]); using R = ranges::set_union_result<Iter1, Iter2, OutIter>; auto set_union = make_testable_2(ranges::set_union); auto checker = [&](R res) { CHECK((base(res.out) - ic) == sr); CHECK(std::lexicographical_compare(ic, base(res.out), ir, ir+sr) == false); ranges::fill(ic, 0); }; set_union(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+sb), OutIter(ic)).check(checker); set_union(Iter1(ib), Iter1(ib+sb), Iter2(ia), Iter2(ia+sa), OutIter(ic)).check(checker); set_union(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+sb), OutIter(ic), std::less<int>()).check(checker); set_union(Iter1(ib), Iter1(ib+sb), Iter2(ia), Iter2(ia+sa), OutIter(ic), std::less<int>()).check(checker); } struct S { int i; }; struct T { int j; }; struct U { int k; U& operator=(S s) { k = s.i; return *this;} U& operator=(T t) { k = t.j; return *this;} }; constexpr bool test_constexpr() { using namespace ranges; int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4}; int ib[] = {2, 4, 4, 6}; int ic[20] = {0}; int ir[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 6}; const int sr = sizeof(ir) / sizeof(ir[0]); const auto res1 = set_union(ia, ib, ic, less{}); STATIC_CHECK_RETURN(res1.in1 == end(ia)); STATIC_CHECK_RETURN(res1.in2 == end(ib)); STATIC_CHECK_RETURN((res1.out - begin(ic)) == sr); STATIC_CHECK_RETURN(lexicographical_compare(ic, res1.out, ir, ir + sr, less{}) == 0); fill(ic, 0); const auto res2 = set_union(ib, ia, ic, less{}); STATIC_CHECK_RETURN(res2.in1 == end(ib)); STATIC_CHECK_RETURN(res2.in2 == end(ia)); STATIC_CHECK_RETURN(res2.out - begin(ic) == sr); STATIC_CHECK_RETURN(lexicographical_compare(ic, res2.out, ir, ir + sr, less{}) == 0); return true; } int main() { #ifdef SET_UNION_1 test<InputIterator<const int*>, InputIterator<const int*>, OutputIterator<int*> >(); test<InputIterator<const int*>, InputIterator<const int*>, ForwardIterator<int*> >(); test<InputIterator<const int*>, InputIterator<const int*>, BidirectionalIterator<int*> >(); test<InputIterator<const int*>, InputIterator<const int*>, RandomAccessIterator<int*> >(); test<InputIterator<const int*>, InputIterator<const int*>, int*>(); test<InputIterator<const int*>, ForwardIterator<const int*>, OutputIterator<int*> >(); test<InputIterator<const int*>, ForwardIterator<const int*>, ForwardIterator<int*> >(); test<InputIterator<const int*>, ForwardIterator<const int*>, BidirectionalIterator<int*> >(); test<InputIterator<const int*>, ForwardIterator<const int*>, RandomAccessIterator<int*> >(); test<InputIterator<const int*>, ForwardIterator<const int*>, int*>(); test<InputIterator<const int*>, BidirectionalIterator<const int*>, OutputIterator<int*> >(); test<InputIterator<const int*>, BidirectionalIterator<const int*>, ForwardIterator<int*> >(); test<InputIterator<const int*>, BidirectionalIterator<const int*>, BidirectionalIterator<int*> >(); test<InputIterator<const int*>, BidirectionalIterator<const int*>, RandomAccessIterator<int*> >(); test<InputIterator<const int*>, BidirectionalIterator<const int*>, int*>(); test<InputIterator<const int*>, RandomAccessIterator<const int*>, OutputIterator<int*> >(); test<InputIterator<const int*>, RandomAccessIterator<const int*>, ForwardIterator<int*> >(); test<InputIterator<const int*>, RandomAccessIterator<const int*>, BidirectionalIterator<int*> >(); test<InputIterator<const int*>, RandomAccessIterator<const int*>, RandomAccessIterator<int*> >(); test<InputIterator<const int*>, RandomAccessIterator<const int*>, int*>(); test<InputIterator<const int*>, const int*, OutputIterator<int*> >(); test<InputIterator<const int*>, const int*, ForwardIterator<int*> >(); test<InputIterator<const int*>, const int*, BidirectionalIterator<int*> >(); test<InputIterator<const int*>, const int*, RandomAccessIterator<int*> >(); test<InputIterator<const int*>, const int*, int*>(); #endif #ifdef SET_UNION_2 test<ForwardIterator<const int*>, InputIterator<const int*>, OutputIterator<int*> >(); test<ForwardIterator<const int*>, InputIterator<const int*>, ForwardIterator<int*> >(); test<ForwardIterator<const int*>, InputIterator<const int*>, BidirectionalIterator<int*> >(); test<ForwardIterator<const int*>, InputIterator<const int*>, RandomAccessIterator<int*> >(); test<ForwardIterator<const int*>, InputIterator<const int*>, int*>(); test<ForwardIterator<const int*>, ForwardIterator<const int*>, OutputIterator<int*> >(); test<ForwardIterator<const int*>, ForwardIterator<const int*>, ForwardIterator<int*> >(); test<ForwardIterator<const int*>, ForwardIterator<const int*>, BidirectionalIterator<int*> >(); test<ForwardIterator<const int*>, ForwardIterator<const int*>, RandomAccessIterator<int*> >(); test<ForwardIterator<const int*>, ForwardIterator<const int*>, int*>(); test<ForwardIterator<const int*>, BidirectionalIterator<const int*>, OutputIterator<int*> >(); test<ForwardIterator<const int*>, BidirectionalIterator<const int*>, ForwardIterator<int*> >(); test<ForwardIterator<const int*>, BidirectionalIterator<const int*>, BidirectionalIterator<int*> >(); test<ForwardIterator<const int*>, BidirectionalIterator<const int*>, RandomAccessIterator<int*> >(); test<ForwardIterator<const int*>, BidirectionalIterator<const int*>, int*>(); test<ForwardIterator<const int*>, RandomAccessIterator<const int*>, OutputIterator<int*> >(); test<ForwardIterator<const int*>, RandomAccessIterator<const int*>, ForwardIterator<int*> >(); test<ForwardIterator<const int*>, RandomAccessIterator<const int*>, BidirectionalIterator<int*> >(); test<ForwardIterator<const int*>, RandomAccessIterator<const int*>, RandomAccessIterator<int*> >(); test<ForwardIterator<const int*>, RandomAccessIterator<const int*>, int*>(); test<ForwardIterator<const int*>, const int*, OutputIterator<int*> >(); test<ForwardIterator<const int*>, const int*, ForwardIterator<int*> >(); test<ForwardIterator<const int*>, const int*, BidirectionalIterator<int*> >(); test<ForwardIterator<const int*>, const int*, RandomAccessIterator<int*> >(); test<ForwardIterator<const int*>, const int*, int*>(); #endif #ifdef SET_UNION_3 test<BidirectionalIterator<const int*>, InputIterator<const int*>, OutputIterator<int*> >(); test<BidirectionalIterator<const int*>, InputIterator<const int*>, ForwardIterator<int*> >(); test<BidirectionalIterator<const int*>, InputIterator<const int*>, BidirectionalIterator<int*> >(); test<BidirectionalIterator<const int*>, InputIterator<const int*>, RandomAccessIterator<int*> >(); test<BidirectionalIterator<const int*>, InputIterator<const int*>, int*>(); test<BidirectionalIterator<const int*>, ForwardIterator<const int*>, OutputIterator<int*> >(); test<BidirectionalIterator<const int*>, ForwardIterator<const int*>, ForwardIterator<int*> >(); test<BidirectionalIterator<const int*>, ForwardIterator<const int*>, BidirectionalIterator<int*> >(); test<BidirectionalIterator<const int*>, ForwardIterator<const int*>, RandomAccessIterator<int*> >(); test<BidirectionalIterator<const int*>, ForwardIterator<const int*>, int*>(); test<BidirectionalIterator<const int*>, BidirectionalIterator<const int*>, OutputIterator<int*> >(); test<BidirectionalIterator<const int*>, BidirectionalIterator<const int*>, ForwardIterator<int*> >(); test<BidirectionalIterator<const int*>, BidirectionalIterator<const int*>, BidirectionalIterator<int*> >(); test<BidirectionalIterator<const int*>, BidirectionalIterator<const int*>, RandomAccessIterator<int*> >(); test<BidirectionalIterator<const int*>, BidirectionalIterator<const int*>, int*>(); test<BidirectionalIterator<const int*>, RandomAccessIterator<const int*>, OutputIterator<int*> >(); test<BidirectionalIterator<const int*>, RandomAccessIterator<const int*>, ForwardIterator<int*> >(); test<BidirectionalIterator<const int*>, RandomAccessIterator<const int*>, BidirectionalIterator<int*> >(); test<BidirectionalIterator<const int*>, RandomAccessIterator<const int*>, RandomAccessIterator<int*> >(); test<BidirectionalIterator<const int*>, RandomAccessIterator<const int*>, int*>(); test<BidirectionalIterator<const int*>, const int*, OutputIterator<int*> >(); test<BidirectionalIterator<const int*>, const int*, ForwardIterator<int*> >(); test<BidirectionalIterator<const int*>, const int*, BidirectionalIterator<int*> >(); test<BidirectionalIterator<const int*>, const int*, RandomAccessIterator<int*> >(); test<BidirectionalIterator<const int*>, const int*, int*>(); #endif #ifdef SET_UNION_4 test<RandomAccessIterator<const int*>, InputIterator<const int*>, OutputIterator<int*> >(); test<RandomAccessIterator<const int*>, InputIterator<const int*>, ForwardIterator<int*> >(); test<RandomAccessIterator<const int*>, InputIterator<const int*>, BidirectionalIterator<int*> >(); test<RandomAccessIterator<const int*>, InputIterator<const int*>, RandomAccessIterator<int*> >(); test<RandomAccessIterator<const int*>, InputIterator<const int*>, int*>(); test<RandomAccessIterator<const int*>, ForwardIterator<const int*>, OutputIterator<int*> >(); test<RandomAccessIterator<const int*>, ForwardIterator<const int*>, ForwardIterator<int*> >(); test<RandomAccessIterator<const int*>, ForwardIterator<const int*>, BidirectionalIterator<int*> >(); test<RandomAccessIterator<const int*>, ForwardIterator<const int*>, RandomAccessIterator<int*> >(); test<RandomAccessIterator<const int*>, ForwardIterator<const int*>, int*>(); test<RandomAccessIterator<const int*>, BidirectionalIterator<const int*>, OutputIterator<int*> >(); test<RandomAccessIterator<const int*>, BidirectionalIterator<const int*>, ForwardIterator<int*> >(); test<RandomAccessIterator<const int*>, BidirectionalIterator<const int*>, BidirectionalIterator<int*> >(); test<RandomAccessIterator<const int*>, BidirectionalIterator<const int*>, RandomAccessIterator<int*> >(); test<RandomAccessIterator<const int*>, BidirectionalIterator<const int*>, int*>(); test<RandomAccessIterator<const int*>, RandomAccessIterator<const int*>, OutputIterator<int*> >(); test<RandomAccessIterator<const int*>, RandomAccessIterator<const int*>, ForwardIterator<int*> >(); test<RandomAccessIterator<const int*>, RandomAccessIterator<const int*>, BidirectionalIterator<int*> >(); test<RandomAccessIterator<const int*>, RandomAccessIterator<const int*>, RandomAccessIterator<int*> >(); test<RandomAccessIterator<const int*>, RandomAccessIterator<const int*>, int*>(); test<RandomAccessIterator<const int*>, const int*, OutputIterator<int*> >(); test<RandomAccessIterator<const int*>, const int*, ForwardIterator<int*> >(); test<RandomAccessIterator<const int*>, const int*, BidirectionalIterator<int*> >(); test<RandomAccessIterator<const int*>, const int*, RandomAccessIterator<int*> >(); test<RandomAccessIterator<const int*>, const int*, int*>(); #endif #ifdef SET_UNION_5 test<const int*, InputIterator<const int*>, OutputIterator<int*> >(); test<const int*, InputIterator<const int*>, BidirectionalIterator<int*> >(); test<const int*, InputIterator<const int*>, BidirectionalIterator<int*> >(); test<const int*, InputIterator<const int*>, RandomAccessIterator<int*> >(); test<const int*, InputIterator<const int*>, int*>(); test<const int*, ForwardIterator<const int*>, OutputIterator<int*> >(); test<const int*, ForwardIterator<const int*>, ForwardIterator<int*> >(); test<const int*, ForwardIterator<const int*>, BidirectionalIterator<int*> >(); test<const int*, ForwardIterator<const int*>, RandomAccessIterator<int*> >(); test<const int*, ForwardIterator<const int*>, int*>(); test<const int*, BidirectionalIterator<const int*>, OutputIterator<int*> >(); test<const int*, BidirectionalIterator<const int*>, ForwardIterator<int*> >(); test<const int*, BidirectionalIterator<const int*>, BidirectionalIterator<int*> >(); test<const int*, BidirectionalIterator<const int*>, RandomAccessIterator<int*> >(); test<const int*, BidirectionalIterator<const int*>, int*>(); test<const int*, RandomAccessIterator<const int*>, OutputIterator<int*> >(); test<const int*, RandomAccessIterator<const int*>, ForwardIterator<int*> >(); test<const int*, RandomAccessIterator<const int*>, BidirectionalIterator<int*> >(); test<const int*, RandomAccessIterator<const int*>, RandomAccessIterator<int*> >(); test<const int*, RandomAccessIterator<const int*>, int*>(); test<const int*, const int*, OutputIterator<int*> >(); test<const int*, const int*, ForwardIterator<int*> >(); test<const int*, const int*, BidirectionalIterator<int*> >(); test<const int*, const int*, RandomAccessIterator<int*> >(); test<const int*, const int*, int*>(); #endif #ifdef SET_UNION_6 // Test projections { S ia[] = {S{1}, S{2}, S{2}, S{3}, S{3}, S{3}, S{4}, S{4}, S{4}, S{4}}; T ib[] = {T{2}, T{4}, T{4}, T{6}}; U ic[20]; int ir[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 6}; static const int sr = sizeof(ir)/sizeof(ir[0]); using R = ranges::set_union_result<S *, T*, U*>; R res = ranges::set_union(ia, ib, ic, std::less<int>(), &S::i, &T::j); CHECK((res.out - ic) == sr); CHECK(ranges::lexicographical_compare(ic, res.out, ir, ir+sr, std::less<int>(), &U::k) == false); ranges::fill(ic, U{0}); using R2 = ranges::set_union_result<T *, S*, U*>; R2 res2 = ranges::set_union(ib, ia, ic, std::less<int>(), &T::j, &S::i); CHECK((res2.out - ic) == sr); CHECK(ranges::lexicographical_compare(ic, res2.out, ir, ir+sr, std::less<int>(), &U::k) == false); } // Test projections #ifndef RANGES_WORKAROUND_MSVC_573728 { S ia[] = {S{1}, S{2}, S{2}, S{3}, S{3}, S{3}, S{4}, S{4}, S{4}, S{4}}; T ib[] = {T{2}, T{4}, T{4}, T{6}}; U ic[20]; int ir[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 6}; static const int sr = sizeof(ir)/sizeof(ir[0]); auto res = ranges::set_union(std::move(ia), ranges::views::all(ib), ic, std::less<int>(), &S::i, &T::j); CHECK(::is_dangling(res.in1)); CHECK(res.in2 == ranges::end(ib)); CHECK((res.out - ic) == sr); CHECK(ranges::lexicographical_compare(ic, res.out, ir, ir+sr, std::less<int>(), &U::k) == false); ranges::fill(ic, U{0}); auto res2 = ranges::set_union(std::move(ib), ranges::views::all(ia), ic, std::less<int>(), &T::j, &S::i); CHECK(res2.in2 == ranges::end(ia)); CHECK(::is_dangling(res2.in1)); CHECK((res2.out - ic) == sr); CHECK(ranges::lexicographical_compare(ic, res2.out, ir, ir+sr, std::less<int>(), &U::k) == false); } #endif // RANGES_WORKAROUND_MSVC_573728 { std::vector<S> ia{S{1}, S{2}, S{2}, S{3}, S{3}, S{3}, S{4}, S{4}, S{4}, S{4}}; std::vector<T> ib{T{2}, T{4}, T{4}, T{6}}; U ic[20]; int ir[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 6}; static const int sr = sizeof(ir)/sizeof(ir[0]); auto res = ranges::set_union(std::move(ia), ranges::views::all(ib), ic, std::less<int>(), &S::i, &T::j); CHECK(::is_dangling(res.in1)); CHECK(res.in2 == ranges::end(ib)); CHECK((res.out - ic) == sr); CHECK(ranges::lexicographical_compare(ic, res.out, ir, ir+sr, std::less<int>(), &U::k) == false); ranges::fill(ic, U{0}); auto res2 = ranges::set_union(std::move(ib), ranges::views::all(ia), ic, std::less<int>(), &T::j, &S::i); CHECK(res2.in2 == ranges::end(ia)); CHECK(::is_dangling(res2.in1)); CHECK((res2.out - ic) == sr); CHECK(ranges::lexicographical_compare(ic, res2.out, ir, ir+sr, std::less<int>(), &U::k) == false); } { STATIC_CHECK(test_constexpr()); } #endif return ::test_result(); }
0
repos/range-v3/test
repos/range-v3/test/algorithm/is_sorted.cpp
// Range v3 library // // Copyright Eric Niebler 2014-present // 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 // // 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 <range/v3/core.hpp> #include <range/v3/algorithm/is_sorted.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 &&b, E &&e, Args &&... args) -> decltype(ranges::is_sorted(begin_t{b}, sentinel_t{e}, std::forward<Args>(args)...)) { return ranges::is_sorted(begin_t{b}, 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> auto operator()(B && b, E && e) -> decltype(ranges::is_sorted(ranges::make_subrange(begin_t{b}, sentinel_t{e}))) { return ranges::is_sorted(ranges::make_subrange(begin_t{b}, sentinel_t{e})); } template<class B, class E, class A0> auto operator()(B && b, E && e, A0 && a0) -> decltype(ranges::is_sorted(ranges::make_subrange(begin_t{b}, sentinel_t{e}), static_cast<A0 &&>(a0))) { return ranges::is_sorted(ranges::make_subrange(begin_t{b}, sentinel_t{e}), static_cast<A0 &&>(a0)); } template<class B, class E, class A0, class A1> auto operator()(B && b, E && e, A0 && a0, A1 && a1) -> decltype(ranges::is_sorted(ranges::make_subrange(begin_t{b}, sentinel_t{e}), static_cast<A0 &&>(a0), static_cast<A1 &&>(a1))) { return ranges::is_sorted(ranges::make_subrange(begin_t{b}, sentinel_t{e}), static_cast<A0 &&>(a0), static_cast<A1 &&>(a1)); } }; template<class Fun> void test() { { int a[] = {0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a)); CHECK(Fun{}(a, a + sa)); } { int a[] = {0, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa)); } { int a[] = {0, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa)); } { int a[] = {1, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(!Fun{}(a, a + sa)); } { int a[] = {1, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa)); } { int a[] = {0, 0, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa)); } { int a[] = {0, 0, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa)); } { int a[] = {0, 1, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(!Fun{}(a, a + sa)); } { int a[] = {0, 1, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa)); } { int a[] = {1, 0, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(!Fun{}(a, a + sa)); } { int a[] = {1, 0, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(!Fun{}(a, a + sa)); } { int a[] = {1, 1, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(!Fun{}(a, a + sa)); } { int a[] = {1, 1, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa)); } { int a[] = {0, 0, 0, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa)); } { int a[] = {0, 0, 0, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa)); } { int a[] = {0, 0, 1, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(!Fun{}(a, a + sa)); } { int a[] = {0, 0, 1, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa)); } { int a[] = {0, 1, 0, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(!Fun{}(a, a + sa)); } { int a[] = {0, 1, 0, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(!Fun{}(a, a + sa)); } { int a[] = {0, 1, 1, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(!Fun{}(a, a + sa)); } { int a[] = {0, 1, 1, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa)); } { int a[] = {1, 0, 0, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(!Fun{}(a, a + sa)); } { int a[] = {1, 0, 0, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(!Fun{}(a, a + sa)); } { int a[] = {1, 0, 1, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(!Fun{}(a, a + sa)); } { int a[] = {1, 0, 1, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(!Fun{}(a, a + sa)); } { int a[] = {1, 1, 0, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(!Fun{}(a, a + sa)); } { int a[] = {1, 1, 0, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(!Fun{}(a, a + sa)); } { int a[] = {1, 1, 1, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(!Fun{}(a, a + sa)); } { int a[] = {1, 1, 1, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa)); } { int a[] = {0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a)); CHECK(Fun{}(a, a + sa, std::greater<int>())); } { int a[] = {0, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>())); } { int a[] = {0, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(!Fun{}(a, a + sa, std::greater<int>())); } { int a[] = {1, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>())); } { int a[] = {1, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>())); } { int a[] = {0, 0, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>())); } { int a[] = {0, 0, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(!Fun{}(a, a + sa, std::greater<int>())); } { int a[] = {0, 1, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(!Fun{}(a, a + sa, std::greater<int>())); } { int a[] = {0, 1, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(!Fun{}(a, a + sa, std::greater<int>())); } { int a[] = {1, 0, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>())); } { int a[] = {1, 0, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(!Fun{}(a, a + sa, std::greater<int>())); } { int a[] = {1, 1, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>())); } { int a[] = {1, 1, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>())); } { int a[] = {0, 0, 0, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>())); } { int a[] = {0, 0, 0, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(!Fun{}(a, a + sa, std::greater<int>())); } { int a[] = {0, 0, 1, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(!Fun{}(a, a + sa, std::greater<int>())); } { int a[] = {0, 0, 1, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(!Fun{}(a, a + sa, std::greater<int>())); } { int a[] = {0, 1, 0, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(!Fun{}(a, a + sa, std::greater<int>())); } { int a[] = {0, 1, 0, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(!Fun{}(a, a + sa, std::greater<int>())); } { int a[] = {0, 1, 1, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(!Fun{}(a, a + sa, std::greater<int>())); } { int a[] = {0, 1, 1, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(!Fun{}(a, a + sa, std::greater<int>())); } { int a[] = {1, 0, 0, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>())); } { int a[] = {1, 0, 0, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(!Fun{}(a, a + sa, std::greater<int>())); } { int a[] = {1, 0, 1, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(!Fun{}(a, a + sa, std::greater<int>())); } { int a[] = {1, 0, 1, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(!Fun{}(a, a + sa, std::greater<int>())); } { int a[] = {1, 1, 0, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>())); } { int a[] = {1, 1, 0, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(!Fun{}(a, a + sa, std::greater<int>())); } { int a[] = {1, 1, 1, 0}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>())); } { int a[] = {1, 1, 1, 1}; unsigned sa = sizeof(a) / sizeof(a[0]); CHECK(Fun{}(a, a + sa, std::greater<int>())); } } struct A { int a; }; int main() { test<iter_call<ForwardIterator<const int *>>>(); test<iter_call<BidirectionalIterator<const int *>>>(); test<iter_call<RandomAccessIterator<const int *>>>(); test<iter_call<const int *>>(); test<range_call<ForwardIterator<const int *>>>(); test<range_call<BidirectionalIterator<const int *>>>(); test<range_call<RandomAccessIterator<const int *>>>(); test<range_call<const int *>>(); /// Projection test: { A as[] = {{0}, {1}, {2}, {3}, {4}}; CHECK(ranges::is_sorted(as, std::less<int>{}, &A::a)); CHECK(!ranges::is_sorted(as, std::greater<int>{}, &A::a)); } { using IL = std::initializer_list<int>; STATIC_CHECK(ranges::is_sorted(IL{0, 1, 2, 3})); STATIC_CHECK(ranges::is_sorted(IL{0, 1, 2, 3}, std::less<>{})); STATIC_CHECK(!ranges::is_sorted(IL{3, 2, 1, 0})); STATIC_CHECK(ranges::is_sorted(IL{3, 2, 1, 0}, std::greater<>{})); } return ::test_result(); }
0
repos/range-v3/test
repos/range-v3/test/algorithm/is_heap_until.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 <vector> #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" void test_basic() { #ifdef IS_HEAP_UNTIL_1 auto is_heap_until = make_testable_1(ranges::is_heap_until); int i1[] = {0, 0}; is_heap_until(i1, i1).check([&](int*r){CHECK(r == i1);}); is_heap_until(i1, i1).check([&](int *r){ CHECK(r == i1); }); is_heap_until(i1, i1+1).check([&](int *r){ CHECK(r == i1+1); }); int i2[] = {0, 1}; int i3[] = {1, 0}; is_heap_until(i1, i1+2).check([&](int *r){ CHECK(r == i1+2); }); is_heap_until(i2, i2+2).check([&](int *r){ CHECK(r == i2+1); }); is_heap_until(i3, i3+2).check([&](int *r){ CHECK(r == 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_until(i4, i4+3).check([&](int *r){ CHECK(r == i4+3); }); is_heap_until(i5, i5+3).check([&](int *r){ CHECK(r == i5+2); }); is_heap_until(i6, i6+3).check([&](int *r){ CHECK(r == i6+1); }); is_heap_until(i7, i7+3).check([&](int *r){ CHECK(r == i7+1); }); is_heap_until(i8, i8+3).check([&](int *r){ CHECK(r == i8+3); }); is_heap_until(i9, i9+3).check([&](int *r){ CHECK(r == i9+3); }); is_heap_until(i10, i10+3).check([&](int *r){ CHECK(r == 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_until(i11, i11+4).check([&](int *r){ CHECK(r == i11+4); }); is_heap_until(i12, i12+4).check([&](int *r){ CHECK(r == i12+3); }); is_heap_until(i13, i13+4).check([&](int *r){ CHECK(r == i13+2); }); is_heap_until(i14, i14+4).check([&](int *r){ CHECK(r == i14+2); }); is_heap_until(i15, i15+4).check([&](int *r){ CHECK(r == i15+1); }); is_heap_until(i16, i16+4).check([&](int *r){ CHECK(r == i16+1); }); is_heap_until(i17, i17+4).check([&](int *r){ CHECK(r == i17+1); }); is_heap_until(i18, i18+4).check([&](int *r){ CHECK(r == i18+1); }); is_heap_until(i19, i19+4).check([&](int *r){ CHECK(r == i19+4); }); is_heap_until(i20, i20+4).check([&](int *r){ CHECK(r == i20+3); }); is_heap_until(i21, i21+4).check([&](int *r){ CHECK(r == i21+4); }); is_heap_until(i22, i22+4).check([&](int *r){ CHECK(r == i22+3); }); is_heap_until(i23, i23+4).check([&](int *r){ CHECK(r == i23+4); }); is_heap_until(i24, i24+4).check([&](int *r){ CHECK(r == i24+4); }); is_heap_until(i25, i25+4).check([&](int *r){ CHECK(r == 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_until(i26, i26+5).check([&](int *r){ CHECK(r == i26+5); }); is_heap_until(i27, i27+5).check([&](int *r){ CHECK(r == i27+4); }); is_heap_until(i28, i28+5).check([&](int *r){ CHECK(r == i28+3); }); is_heap_until(i29, i29+5).check([&](int *r){ CHECK(r == i29+3); }); is_heap_until(i30, i30+5).check([&](int *r){ CHECK(r == i30+2); }); is_heap_until(i31, i31+5).check([&](int *r){ CHECK(r == i31+2); }); is_heap_until(i32, i32+5).check([&](int *r){ CHECK(r == i32+2); }); is_heap_until(i33, i33+5).check([&](int *r){ CHECK(r == i33+2); }); is_heap_until(i34, i34+5).check([&](int *r){ CHECK(r == i34+1); }); is_heap_until(i35, i35+5).check([&](int *r){ CHECK(r == i35+1); }); is_heap_until(i36, i36+5).check([&](int *r){ CHECK(r == i36+1); }); is_heap_until(i37, i37+5).check([&](int *r){ CHECK(r == i37+1); }); is_heap_until(i38, i38+5).check([&](int *r){ CHECK(r == i38+1); }); is_heap_until(i39, i39+5).check([&](int *r){ CHECK(r == i39+1); }); is_heap_until(i40, i40+5).check([&](int *r){ CHECK(r == i40+1); }); is_heap_until(i41, i41+5).check([&](int *r){ CHECK(r == i41+1); }); is_heap_until(i42, i42+5).check([&](int *r){ CHECK(r == i42+5); }); is_heap_until(i43, i43+5).check([&](int *r){ CHECK(r == i43+4); }); is_heap_until(i44, i44+5).check([&](int *r){ CHECK(r == i44+3); }); is_heap_until(i45, i45+5).check([&](int *r){ CHECK(r == i45+3); }); is_heap_until(i46, i46+5).check([&](int *r){ CHECK(r == i46+5); }); is_heap_until(i47, i47+5).check([&](int *r){ CHECK(r == i47+4); }); is_heap_until(i48, i48+5).check([&](int *r){ CHECK(r == i48+3); }); is_heap_until(i49, i49+5).check([&](int *r){ CHECK(r == i49+3); }); is_heap_until(i50, i50+5).check([&](int *r){ CHECK(r == i50+5); }); is_heap_until(i51, i51+5).check([&](int *r){ CHECK(r == i51+5); }); is_heap_until(i52, i52+5).check([&](int *r){ CHECK(r == i52+5); }); is_heap_until(i53, i53+5).check([&](int *r){ CHECK(r == i53+5); }); is_heap_until(i54, i54+5).check([&](int *r){ CHECK(r == i54+5); }); is_heap_until(i55, i55+5).check([&](int *r){ CHECK(r == i55+5); }); is_heap_until(i56, i56+5).check([&](int *r){ CHECK(r == 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_until(i57, i57+6).check([&](int *r){ CHECK(r == i57+6); }); is_heap_until(i58, i58+6).check([&](int *r){ CHECK(r == i58+5); }); is_heap_until(i59, i59+6).check([&](int *r){ CHECK(r == i59+4); }); is_heap_until(i60, i60+6).check([&](int *r){ CHECK(r == i60+4); }); is_heap_until(i61, i61+6).check([&](int *r){ CHECK(r == i61+3); }); is_heap_until(i62, i62+6).check([&](int *r){ CHECK(r == i62+3); }); is_heap_until(i63, i63+6).check([&](int *r){ CHECK(r == i63+3); }); is_heap_until(i64, i64+6).check([&](int *r){ CHECK(r == i64+3); }); is_heap_until(i65, i65+6).check([&](int *r){ CHECK(r == i65+2); }); is_heap_until(i66, i66+6).check([&](int *r){ CHECK(r == i66+2); }); is_heap_until(i67, i67+6).check([&](int *r){ CHECK(r == i67+2); }); is_heap_until(i68, i68+6).check([&](int *r){ CHECK(r == i68+2); }); is_heap_until(i69, i69+6).check([&](int *r){ CHECK(r == i69+2); }); is_heap_until(i70, i70+6).check([&](int *r){ CHECK(r == i70+2); }); is_heap_until(i71, i71+6).check([&](int *r){ CHECK(r == i71+2); }); is_heap_until(i72, i72+6).check([&](int *r){ CHECK(r == i72+2); }); is_heap_until(i73, i73+6).check([&](int *r){ CHECK(r == i73+1); }); is_heap_until(i74, i74+6).check([&](int *r){ CHECK(r == i74+1); }); is_heap_until(i75, i75+6).check([&](int *r){ CHECK(r == i75+1); }); is_heap_until(i76, i76+6).check([&](int *r){ CHECK(r == i76+1); }); is_heap_until(i77, i77+6).check([&](int *r){ CHECK(r == i77+1); }); is_heap_until(i78, i78+6).check([&](int *r){ CHECK(r == i78+1); }); is_heap_until(i79, i79+6).check([&](int *r){ CHECK(r == i79+1); }); is_heap_until(i80, i80+6).check([&](int *r){ CHECK(r == i80+1); }); is_heap_until(i81, i81+6).check([&](int *r){ CHECK(r == i81+1); }); is_heap_until(i82, i82+6).check([&](int *r){ CHECK(r == i82+1); }); is_heap_until(i83, i83+6).check([&](int *r){ CHECK(r == i83+1); }); is_heap_until(i84, i84+6).check([&](int *r){ CHECK(r == i84+1); }); is_heap_until(i85, i85+6).check([&](int *r){ CHECK(r == i85+1); }); is_heap_until(i86, i86+6).check([&](int *r){ CHECK(r == i86+1); }); is_heap_until(i87, i87+6).check([&](int *r){ CHECK(r == i87+1); }); is_heap_until(i88, i88+6).check([&](int *r){ CHECK(r == i88+1); }); is_heap_until(i89, i89+6).check([&](int *r){ CHECK(r == i89+6); }); is_heap_until(i90, i90+6).check([&](int *r){ CHECK(r == i90+5); }); is_heap_until(i91, i91+6).check([&](int *r){ CHECK(r == i91+4); }); is_heap_until(i92, i92+6).check([&](int *r){ CHECK(r == i92+4); }); is_heap_until(i93, i93+6).check([&](int *r){ CHECK(r == i93+3); }); is_heap_until(i94, i94+6).check([&](int *r){ CHECK(r == i94+3); }); is_heap_until(i95, i95+6).check([&](int *r){ CHECK(r == i95+3); }); is_heap_until(i96, i96+6).check([&](int *r){ CHECK(r == i96+3); }); is_heap_until(i97, i97+6).check([&](int *r){ CHECK(r == i97+6); }); is_heap_until(i98, i98+6).check([&](int *r){ CHECK(r == i98+6); }); is_heap_until(i99, i99+6).check([&](int *r){ CHECK(r == i99+4); }); is_heap_until(i100, i100+6).check([&](int *r){ CHECK(r == i100+4); }); is_heap_until(i101, i101+6).check([&](int *r){ CHECK(r == i101+3); }); is_heap_until(i102, i102+6).check([&](int *r){ CHECK(r == i102+3); }); is_heap_until(i103, i103+6).check([&](int *r){ CHECK(r == i103+3); }); is_heap_until(i104, i104+6).check([&](int *r){ CHECK(r == i104+3); }); is_heap_until(i105, i105+6).check([&](int *r){ CHECK(r == i105+6); }); is_heap_until(i106, i106+6).check([&](int *r){ CHECK(r == i106+5); }); is_heap_until(i107, i107+6).check([&](int *r){ CHECK(r == i107+6); }); is_heap_until(i108, i108+6).check([&](int *r){ CHECK(r == i108+5); }); is_heap_until(i109, i109+6).check([&](int *r){ CHECK(r == i109+6); }); is_heap_until(i110, i110+6).check([&](int *r){ CHECK(r == i110+5); }); is_heap_until(i111, i111+6).check([&](int *r){ CHECK(r == i111+6); }); is_heap_until(i112, i112+6).check([&](int *r){ CHECK(r == i112+5); }); is_heap_until(i113, i113+6).check([&](int *r){ CHECK(r == i113+6); }); is_heap_until(i114, i114+6).check([&](int *r){ CHECK(r == i114+6); }); is_heap_until(i115, i115+6).check([&](int *r){ CHECK(r == i115+6); }); is_heap_until(i116, i116+6).check([&](int *r){ CHECK(r == i116+6); }); is_heap_until(i117, i117+6).check([&](int *r){ CHECK(r == i117+6); }); is_heap_until(i118, i118+6).check([&](int *r){ CHECK(r == i118+6); }); is_heap_until(i119, i119+6).check([&](int *r){ CHECK(r == i119+6); }); #endif #ifdef IS_HEAP_UNTIL_2 auto is_heap_until = make_testable_1(ranges::is_heap_until); 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_until(i120, i120+7).check([&](int *r){ CHECK(r == i120+7); }); is_heap_until(i121, i121+7).check([&](int *r){ CHECK(r == i121+6); }); is_heap_until(i122, i122+7).check([&](int *r){ CHECK(r == i122+5); }); is_heap_until(i123, i123+7).check([&](int *r){ CHECK(r == i123+5); }); is_heap_until(i124, i124+7).check([&](int *r){ CHECK(r == i124+4); }); is_heap_until(i125, i125+7).check([&](int *r){ CHECK(r == i125+4); }); is_heap_until(i126, i126+7).check([&](int *r){ CHECK(r == i126+4); }); is_heap_until(i127, i127+7).check([&](int *r){ CHECK(r == i127+4); }); is_heap_until(i128, i128+7).check([&](int *r){ CHECK(r == i128+3); }); is_heap_until(i129, i129+7).check([&](int *r){ CHECK(r == i129+3); }); is_heap_until(i130, i130+7).check([&](int *r){ CHECK(r == i130+3); }); is_heap_until(i131, i131+7).check([&](int *r){ CHECK(r == i131+3); }); is_heap_until(i132, i132+7).check([&](int *r){ CHECK(r == i132+3); }); is_heap_until(i133, i133+7).check([&](int *r){ CHECK(r == i133+3); }); is_heap_until(i134, i134+7).check([&](int *r){ CHECK(r == i134+3); }); is_heap_until(i135, i135+7).check([&](int *r){ CHECK(r == i135+3); }); is_heap_until(i136, i136+7).check([&](int *r){ CHECK(r == i136+2); }); is_heap_until(i137, i137+7).check([&](int *r){ CHECK(r == i137+2); }); is_heap_until(i138, i138+7).check([&](int *r){ CHECK(r == i138+2); }); is_heap_until(i139, i139+7).check([&](int *r){ CHECK(r == i139+2); }); is_heap_until(i140, i140+7).check([&](int *r){ CHECK(r == i140+2); }); is_heap_until(i141, i141+7).check([&](int *r){ CHECK(r == i141+2); }); is_heap_until(i142, i142+7).check([&](int *r){ CHECK(r == i142+2); }); is_heap_until(i143, i143+7).check([&](int *r){ CHECK(r == i143+2); }); is_heap_until(i144, i144+7).check([&](int *r){ CHECK(r == i144+2); }); is_heap_until(i145, i145+7).check([&](int *r){ CHECK(r == i145+2); }); is_heap_until(i146, i146+7).check([&](int *r){ CHECK(r == i146+2); }); is_heap_until(i147, i147+7).check([&](int *r){ CHECK(r == i147+2); }); is_heap_until(i148, i148+7).check([&](int *r){ CHECK(r == i148+2); }); is_heap_until(i149, i149+7).check([&](int *r){ CHECK(r == i149+2); }); is_heap_until(i150, i150+7).check([&](int *r){ CHECK(r == i150+2); }); is_heap_until(i151, i151+7).check([&](int *r){ CHECK(r == i151+2); }); is_heap_until(i152, i152+7).check([&](int *r){ CHECK(r == i152+1); }); is_heap_until(i153, i153+7).check([&](int *r){ CHECK(r == i153+1); }); is_heap_until(i154, i154+7).check([&](int *r){ CHECK(r == i154+1); }); is_heap_until(i155, i155+7).check([&](int *r){ CHECK(r == i155+1); }); is_heap_until(i156, i156+7).check([&](int *r){ CHECK(r == i156+1); }); is_heap_until(i157, i157+7).check([&](int *r){ CHECK(r == i157+1); }); is_heap_until(i158, i158+7).check([&](int *r){ CHECK(r == i158+1); }); is_heap_until(i159, i159+7).check([&](int *r){ CHECK(r == i159+1); }); is_heap_until(i160, i160+7).check([&](int *r){ CHECK(r == i160+1); }); is_heap_until(i161, i161+7).check([&](int *r){ CHECK(r == i161+1); }); is_heap_until(i162, i162+7).check([&](int *r){ CHECK(r == i162+1); }); is_heap_until(i163, i163+7).check([&](int *r){ CHECK(r == i163+1); }); is_heap_until(i164, i164+7).check([&](int *r){ CHECK(r == i164+1); }); is_heap_until(i165, i165+7).check([&](int *r){ CHECK(r == i165+1); }); is_heap_until(i166, i166+7).check([&](int *r){ CHECK(r == i166+1); }); is_heap_until(i167, i167+7).check([&](int *r){ CHECK(r == i167+1); }); is_heap_until(i168, i168+7).check([&](int *r){ CHECK(r == i168+1); }); is_heap_until(i169, i169+7).check([&](int *r){ CHECK(r == i169+1); }); is_heap_until(i170, i170+7).check([&](int *r){ CHECK(r == i170+1); }); is_heap_until(i171, i171+7).check([&](int *r){ CHECK(r == i171+1); }); is_heap_until(i172, i172+7).check([&](int *r){ CHECK(r == i172+1); }); is_heap_until(i173, i173+7).check([&](int *r){ CHECK(r == i173+1); }); is_heap_until(i174, i174+7).check([&](int *r){ CHECK(r == i174+1); }); is_heap_until(i175, i175+7).check([&](int *r){ CHECK(r == i175+1); }); is_heap_until(i176, i176+7).check([&](int *r){ CHECK(r == i176+1); }); is_heap_until(i177, i177+7).check([&](int *r){ CHECK(r == i177+1); }); is_heap_until(i178, i178+7).check([&](int *r){ CHECK(r == i178+1); }); is_heap_until(i179, i179+7).check([&](int *r){ CHECK(r == i179+1); }); is_heap_until(i180, i180+7).check([&](int *r){ CHECK(r == i180+1); }); is_heap_until(i181, i181+7).check([&](int *r){ CHECK(r == i181+1); }); is_heap_until(i182, i182+7).check([&](int *r){ CHECK(r == i182+1); }); is_heap_until(i183, i183+7).check([&](int *r){ CHECK(r == i183+1); }); is_heap_until(i184, i184+7).check([&](int *r){ CHECK(r == i184+7); }); is_heap_until(i185, i185+7).check([&](int *r){ CHECK(r == i185+6); }); is_heap_until(i186, i186+7).check([&](int *r){ CHECK(r == i186+5); }); is_heap_until(i187, i187+7).check([&](int *r){ CHECK(r == i187+5); }); is_heap_until(i188, i188+7).check([&](int *r){ CHECK(r == i188+4); }); is_heap_until(i189, i189+7).check([&](int *r){ CHECK(r == i189+4); }); is_heap_until(i190, i190+7).check([&](int *r){ CHECK(r == i190+4); }); is_heap_until(i191, i191+7).check([&](int *r){ CHECK(r == i191+4); }); is_heap_until(i192, i192+7).check([&](int *r){ CHECK(r == i192+3); }); is_heap_until(i193, i193+7).check([&](int *r){ CHECK(r == i193+3); }); is_heap_until(i194, i194+7).check([&](int *r){ CHECK(r == i194+3); }); is_heap_until(i195, i195+7).check([&](int *r){ CHECK(r == i195+3); }); is_heap_until(i196, i196+7).check([&](int *r){ CHECK(r == i196+3); }); is_heap_until(i197, i197+7).check([&](int *r){ CHECK(r == i197+3); }); is_heap_until(i198, i198+7).check([&](int *r){ CHECK(r == i198+3); }); is_heap_until(i199, i199+7).check([&](int *r){ CHECK(r == i199+3); }); is_heap_until(i200, i200+7).check([&](int *r){ CHECK(r == i200+7); }); is_heap_until(i201, i201+7).check([&](int *r){ CHECK(r == i201+7); }); is_heap_until(i202, i202+7).check([&](int *r){ CHECK(r == i202+7); }); is_heap_until(i203, i203+7).check([&](int *r){ CHECK(r == i203+7); }); is_heap_until(i204, i204+7).check([&](int *r){ CHECK(r == i204+4); }); is_heap_until(i205, i205+7).check([&](int *r){ CHECK(r == i205+4); }); is_heap_until(i206, i206+7).check([&](int *r){ CHECK(r == i206+4); }); is_heap_until(i207, i207+7).check([&](int *r){ CHECK(r == i207+4); }); is_heap_until(i208, i208+7).check([&](int *r){ CHECK(r == i208+3); }); is_heap_until(i209, i209+7).check([&](int *r){ CHECK(r == i209+3); }); is_heap_until(i210, i210+7).check([&](int *r){ CHECK(r == i210+3); }); is_heap_until(i211, i211+7).check([&](int *r){ CHECK(r == i211+3); }); is_heap_until(i212, i212+7).check([&](int *r){ CHECK(r == i212+3); }); is_heap_until(i213, i213+7).check([&](int *r){ CHECK(r == i213+3); }); is_heap_until(i214, i214+7).check([&](int *r){ CHECK(r == i214+3); }); is_heap_until(i215, i215+7).check([&](int *r){ CHECK(r == i215+3); }); is_heap_until(i216, i216+7).check([&](int *r){ CHECK(r == i216+7); }); is_heap_until(i217, i217+7).check([&](int *r){ CHECK(r == i217+6); }); is_heap_until(i218, i218+7).check([&](int *r){ CHECK(r == i218+5); }); is_heap_until(i219, i219+7).check([&](int *r){ CHECK(r == i219+5); }); is_heap_until(i220, i220+7).check([&](int *r){ CHECK(r == i220+7); }); is_heap_until(i221, i221+7).check([&](int *r){ CHECK(r == i221+6); }); is_heap_until(i222, i222+7).check([&](int *r){ CHECK(r == i222+5); }); is_heap_until(i223, i223+7).check([&](int *r){ CHECK(r == i223+5); }); is_heap_until(i224, i224+7).check([&](int *r){ CHECK(r == i224+7); }); is_heap_until(i225, i225+7).check([&](int *r){ CHECK(r == i225+6); }); is_heap_until(i226, i226+7).check([&](int *r){ CHECK(r == i226+5); }); is_heap_until(i227, i227+7).check([&](int *r){ CHECK(r == i227+5); }); is_heap_until(i228, i228+7).check([&](int *r){ CHECK(r == i228+7); }); is_heap_until(i229, i229+7).check([&](int *r){ CHECK(r == i229+6); }); is_heap_until(i230, i230+7).check([&](int *r){ CHECK(r == i230+5); }); is_heap_until(i231, i231+7).check([&](int *r){ CHECK(r == i231+5); }); is_heap_until(i232, i232+7).check([&](int *r){ CHECK(r == i232+7); }); is_heap_until(i233, i233+7).check([&](int *r){ CHECK(r == i233+7); }); is_heap_until(i234, i234+7).check([&](int *r){ CHECK(r == i234+7); }); is_heap_until(i235, i235+7).check([&](int *r){ CHECK(r == i235+7); }); is_heap_until(i236, i236+7).check([&](int *r){ CHECK(r == i236+7); }); is_heap_until(i237, i237+7).check([&](int *r){ CHECK(r == i237+7); }); is_heap_until(i238, i238+7).check([&](int *r){ CHECK(r == i238+7); }); is_heap_until(i239, i239+7).check([&](int *r){ CHECK(r == i239+7); }); is_heap_until(i240, i240+7).check([&](int *r){ CHECK(r == i240+7); }); is_heap_until(i241, i241+7).check([&](int *r){ CHECK(r == i241+7); }); is_heap_until(i242, i242+7).check([&](int *r){ CHECK(r == i242+7); }); is_heap_until(i243, i243+7).check([&](int *r){ CHECK(r == i243+7); }); is_heap_until(i244, i244+7).check([&](int *r){ CHECK(r == i244+7); }); is_heap_until(i245, i245+7).check([&](int *r){ CHECK(r == i245+7); }); is_heap_until(i246, i246+7).check([&](int *r){ CHECK(r == i246+7); }); #endif } void test_pred() { #ifdef IS_HEAP_UNTIL_3 auto is_heap_until = ::make_testable_1(ranges::is_heap_until); int i1[] = {0, 0}; is_heap_until(i1, i1, std::greater<int>()).check([&](int *r){ CHECK(r == i1); }); is_heap_until(i1, i1+1, std::greater<int>()).check([&](int *r){ CHECK(r == i1+1); }); int i2[] = {0, 1}; int i3[] = {1, 0}; is_heap_until(i1, i1+2, std::greater<int>()).check([&](int *r){ CHECK(r == i1+2); }); is_heap_until(i2, i2+2, std::greater<int>()).check([&](int *r){ CHECK(r == i2+2); }); is_heap_until(i3, i3+2, std::greater<int>()).check([&](int *r){ CHECK(r == i3+1); }); 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_until(i4, i4+3, std::greater<int>()).check([&](int *r){ CHECK(r == i4+3); }); is_heap_until(i5, i5+3, std::greater<int>()).check([&](int *r){ CHECK(r == i5+3); }); is_heap_until(i6, i6+3, std::greater<int>()).check([&](int *r){ CHECK(r == i6+3); }); is_heap_until(i7, i7+3, std::greater<int>()).check([&](int *r){ CHECK(r == i7+3); }); is_heap_until(i8, i8+3, std::greater<int>()).check([&](int *r){ CHECK(r == i8+1); }); is_heap_until(i9, i9+3, std::greater<int>()).check([&](int *r){ CHECK(r == i9+1); }); is_heap_until(i10, i10+3, std::greater<int>()).check([&](int *r){ CHECK(r == i10+2); }); 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_until(i11, i11+4, std::greater<int>()).check([&](int *r){ CHECK(r == i11+4); }); is_heap_until(i12, i12+4, std::greater<int>()).check([&](int *r){ CHECK(r == i12+4); }); is_heap_until(i13, i13+4, std::greater<int>()).check([&](int *r){ CHECK(r == i13+4); }); is_heap_until(i14, i14+4, std::greater<int>()).check([&](int *r){ CHECK(r == i14+4); }); is_heap_until(i15, i15+4, std::greater<int>()).check([&](int *r){ CHECK(r == i15+3); }); is_heap_until(i16, i16+4, std::greater<int>()).check([&](int *r){ CHECK(r == i16+4); }); is_heap_until(i17, i17+4, std::greater<int>()).check([&](int *r){ CHECK(r == i17+3); }); is_heap_until(i18, i18+4, std::greater<int>()).check([&](int *r){ CHECK(r == i18+4); }); is_heap_until(i19, i19+4, std::greater<int>()).check([&](int *r){ CHECK(r == i19+1); }); is_heap_until(i20, i20+4, std::greater<int>()).check([&](int *r){ CHECK(r == i20+1); }); is_heap_until(i21, i21+4, std::greater<int>()).check([&](int *r){ CHECK(r == i21+1); }); is_heap_until(i22, i22+4, std::greater<int>()).check([&](int *r){ CHECK(r == i22+1); }); is_heap_until(i23, i23+4, std::greater<int>()).check([&](int *r){ CHECK(r == i23+2); }); is_heap_until(i24, i24+4, std::greater<int>()).check([&](int *r){ CHECK(r == i24+2); }); is_heap_until(i25, i25+4, std::greater<int>()).check([&](int *r){ CHECK(r == i25+3); }); 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_until(i26, i26+5, std::greater<int>()).check([&](int *r){ CHECK(r == i26+5); }); is_heap_until(i27, i27+5, std::greater<int>()).check([&](int *r){ CHECK(r == i27+5); }); is_heap_until(i28, i28+5, std::greater<int>()).check([&](int *r){ CHECK(r == i28+5); }); is_heap_until(i29, i29+5, std::greater<int>()).check([&](int *r){ CHECK(r == i29+5); }); is_heap_until(i30, i30+5, std::greater<int>()).check([&](int *r){ CHECK(r == i30+5); }); is_heap_until(i31, i31+5, std::greater<int>()).check([&](int *r){ CHECK(r == i31+5); }); is_heap_until(i32, i32+5, std::greater<int>()).check([&](int *r){ CHECK(r == i32+5); }); is_heap_until(i33, i33+5, std::greater<int>()).check([&](int *r){ CHECK(r == i33+5); }); is_heap_until(i34, i34+5, std::greater<int>()).check([&](int *r){ CHECK(r == i34+3); }); is_heap_until(i35, i35+5, std::greater<int>()).check([&](int *r){ CHECK(r == i35+3); }); is_heap_until(i36, i36+5, std::greater<int>()).check([&](int *r){ CHECK(r == i36+4); }); is_heap_until(i37, i37+5, std::greater<int>()).check([&](int *r){ CHECK(r == i37+5); }); is_heap_until(i38, i38+5, std::greater<int>()).check([&](int *r){ CHECK(r == i38+3); }); is_heap_until(i39, i39+5, std::greater<int>()).check([&](int *r){ CHECK(r == i39+3); }); is_heap_until(i40, i40+5, std::greater<int>()).check([&](int *r){ CHECK(r == i40+4); }); is_heap_until(i41, i41+5, std::greater<int>()).check([&](int *r){ CHECK(r == i41+5); }); is_heap_until(i42, i42+5, std::greater<int>()).check([&](int *r){ CHECK(r == i42+1); }); is_heap_until(i43, i43+5, std::greater<int>()).check([&](int *r){ CHECK(r == i43+1); }); is_heap_until(i44, i44+5, std::greater<int>()).check([&](int *r){ CHECK(r == i44+1); }); is_heap_until(i45, i45+5, std::greater<int>()).check([&](int *r){ CHECK(r == i45+1); }); is_heap_until(i46, i46+5, std::greater<int>()).check([&](int *r){ CHECK(r == i46+1); }); is_heap_until(i47, i47+5, std::greater<int>()).check([&](int *r){ CHECK(r == i47+1); }); is_heap_until(i48, i48+5, std::greater<int>()).check([&](int *r){ CHECK(r == i48+1); }); is_heap_until(i49, i49+5, std::greater<int>()).check([&](int *r){ CHECK(r == i49+1); }); is_heap_until(i50, i50+5, std::greater<int>()).check([&](int *r){ CHECK(r == i50+2); }); is_heap_until(i51, i51+5, std::greater<int>()).check([&](int *r){ CHECK(r == i51+2); }); is_heap_until(i52, i52+5, std::greater<int>()).check([&](int *r){ CHECK(r == i52+2); }); is_heap_until(i53, i53+5, std::greater<int>()).check([&](int *r){ CHECK(r == i53+2); }); is_heap_until(i54, i54+5, std::greater<int>()).check([&](int *r){ CHECK(r == i54+3); }); is_heap_until(i55, i55+5, std::greater<int>()).check([&](int *r){ CHECK(r == i55+3); }); is_heap_until(i56, i56+5, std::greater<int>()).check([&](int *r){ CHECK(r == i56+4); }); 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_until(i57, i57+6, std::greater<int>()).check([&](int *r){ CHECK(r == i57+6); }); is_heap_until(i58, i58+6, std::greater<int>()).check([&](int *r){ CHECK(r == i58+6); }); is_heap_until(i59, i59+6, std::greater<int>()).check([&](int *r){ CHECK(r == i59+6); }); is_heap_until(i60, i60+6, std::greater<int>()).check([&](int *r){ CHECK(r == i60+6); }); is_heap_until(i61, i61+6, std::greater<int>()).check([&](int *r){ CHECK(r == i61+6); }); is_heap_until(i62, i62+6, std::greater<int>()).check([&](int *r){ CHECK(r == i62+6); }); is_heap_until(i63, i63+6, std::greater<int>()).check([&](int *r){ CHECK(r == i63+6); }); is_heap_until(i64, i64+6, std::greater<int>()).check([&](int *r){ CHECK(r == i64+6); }); is_heap_until(i65, i65+6, std::greater<int>()).check([&](int *r){ CHECK(r == i65+5); }); is_heap_until(i66, i66+6, std::greater<int>()).check([&](int *r){ CHECK(r == i66+6); }); is_heap_until(i67, i67+6, std::greater<int>()).check([&](int *r){ CHECK(r == i67+5); }); is_heap_until(i68, i68+6, std::greater<int>()).check([&](int *r){ CHECK(r == i68+6); }); is_heap_until(i69, i69+6, std::greater<int>()).check([&](int *r){ CHECK(r == i69+5); }); is_heap_until(i70, i70+6, std::greater<int>()).check([&](int *r){ CHECK(r == i70+6); }); is_heap_until(i71, i71+6, std::greater<int>()).check([&](int *r){ CHECK(r == i71+5); }); is_heap_until(i72, i72+6, std::greater<int>()).check([&](int *r){ CHECK(r == i72+6); }); is_heap_until(i73, i73+6, std::greater<int>()).check([&](int *r){ CHECK(r == i73+3); }); is_heap_until(i74, i74+6, std::greater<int>()).check([&](int *r){ CHECK(r == i74+3); }); is_heap_until(i75, i75+6, std::greater<int>()).check([&](int *r){ CHECK(r == i75+3); }); is_heap_until(i76, i76+6, std::greater<int>()).check([&](int *r){ CHECK(r == i76+3); }); is_heap_until(i77, i77+6, std::greater<int>()).check([&](int *r){ CHECK(r == i77+4); }); is_heap_until(i78, i78+6, std::greater<int>()).check([&](int *r){ CHECK(r == i78+4); }); is_heap_until(i79, i79+6, std::greater<int>()).check([&](int *r){ CHECK(r == i79+6); }); is_heap_until(i80, i80+6, std::greater<int>()).check([&](int *r){ CHECK(r == i80+6); }); is_heap_until(i81, i81+6, std::greater<int>()).check([&](int *r){ CHECK(r == i81+3); }); is_heap_until(i82, i82+6, std::greater<int>()).check([&](int *r){ CHECK(r == i82+3); }); is_heap_until(i83, i83+6, std::greater<int>()).check([&](int *r){ CHECK(r == i83+3); }); is_heap_until(i84, i84+6, std::greater<int>()).check([&](int *r){ CHECK(r == i84+3); }); is_heap_until(i85, i85+6, std::greater<int>()).check([&](int *r){ CHECK(r == i85+4); }); is_heap_until(i86, i86+6, std::greater<int>()).check([&](int *r){ CHECK(r == i86+4); }); is_heap_until(i87, i87+6, std::greater<int>()).check([&](int *r){ CHECK(r == i87+5); }); is_heap_until(i88, i88+6, std::greater<int>()).check([&](int *r){ CHECK(r == i88+6); }); is_heap_until(i89, i89+6, std::greater<int>()).check([&](int *r){ CHECK(r == i89+1); }); is_heap_until(i90, i90+6, std::greater<int>()).check([&](int *r){ CHECK(r == i90+1); }); is_heap_until(i91, i91+6, std::greater<int>()).check([&](int *r){ CHECK(r == i91+1); }); is_heap_until(i92, i92+6, std::greater<int>()).check([&](int *r){ CHECK(r == i92+1); }); is_heap_until(i93, i93+6, std::greater<int>()).check([&](int *r){ CHECK(r == i93+1); }); is_heap_until(i94, i94+6, std::greater<int>()).check([&](int *r){ CHECK(r == i94+1); }); is_heap_until(i95, i95+6, std::greater<int>()).check([&](int *r){ CHECK(r == i95+1); }); is_heap_until(i96, i96+6, std::greater<int>()).check([&](int *r){ CHECK(r == i96+1); }); is_heap_until(i97, i97+6, std::greater<int>()).check([&](int *r){ CHECK(r == i97+1); }); is_heap_until(i98, i98+6, std::greater<int>()).check([&](int *r){ CHECK(r == i98+1); }); is_heap_until(i99, i99+6, std::greater<int>()).check([&](int *r){ CHECK(r == i99+1); }); is_heap_until(i100, i100+6, std::greater<int>()).check([&](int *r){ CHECK(r == i100+1); }); is_heap_until(i101, i101+6, std::greater<int>()).check([&](int *r){ CHECK(r == i101+1); }); is_heap_until(i102, i102+6, std::greater<int>()).check([&](int *r){ CHECK(r == i102+1); }); is_heap_until(i103, i103+6, std::greater<int>()).check([&](int *r){ CHECK(r == i103+1); }); is_heap_until(i104, i104+6, std::greater<int>()).check([&](int *r){ CHECK(r == i104+1); }); is_heap_until(i105, i105+6, std::greater<int>()).check([&](int *r){ CHECK(r == i105+2); }); is_heap_until(i106, i106+6, std::greater<int>()).check([&](int *r){ CHECK(r == i106+2); }); is_heap_until(i107, i107+6, std::greater<int>()).check([&](int *r){ CHECK(r == i107+2); }); is_heap_until(i108, i108+6, std::greater<int>()).check([&](int *r){ CHECK(r == i108+2); }); is_heap_until(i109, i109+6, std::greater<int>()).check([&](int *r){ CHECK(r == i109+2); }); is_heap_until(i110, i110+6, std::greater<int>()).check([&](int *r){ CHECK(r == i110+2); }); is_heap_until(i111, i111+6, std::greater<int>()).check([&](int *r){ CHECK(r == i111+2); }); is_heap_until(i112, i112+6, std::greater<int>()).check([&](int *r){ CHECK(r == i112+2); }); is_heap_until(i113, i113+6, std::greater<int>()).check([&](int *r){ CHECK(r == i113+3); }); is_heap_until(i114, i114+6, std::greater<int>()).check([&](int *r){ CHECK(r == i114+3); }); is_heap_until(i115, i115+6, std::greater<int>()).check([&](int *r){ CHECK(r == i115+3); }); is_heap_until(i116, i116+6, std::greater<int>()).check([&](int *r){ CHECK(r == i116+3); }); is_heap_until(i117, i117+6, std::greater<int>()).check([&](int *r){ CHECK(r == i117+4); }); is_heap_until(i118, i118+6, std::greater<int>()).check([&](int *r){ CHECK(r == i118+4); }); is_heap_until(i119, i119+6, std::greater<int>()).check([&](int *r){ CHECK(r == i119+5); }); #endif #ifdef IS_HEAP_UNTIL_4 auto is_heap_until = ::make_testable_1(ranges::is_heap_until); 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_until(i120, i120+7, std::greater<int>()).check([&](int *r){ CHECK(r == i120+7); }); is_heap_until(i121, i121+7, std::greater<int>()).check([&](int *r){ CHECK(r == i121+7); }); is_heap_until(i122, i122+7, std::greater<int>()).check([&](int *r){ CHECK(r == i122+7); }); is_heap_until(i123, i123+7, std::greater<int>()).check([&](int *r){ CHECK(r == i123+7); }); is_heap_until(i124, i124+7, std::greater<int>()).check([&](int *r){ CHECK(r == i124+7); }); is_heap_until(i125, i125+7, std::greater<int>()).check([&](int *r){ CHECK(r == i125+7); }); is_heap_until(i126, i126+7, std::greater<int>()).check([&](int *r){ CHECK(r == i126+7); }); is_heap_until(i127, i127+7, std::greater<int>()).check([&](int *r){ CHECK(r == i127+7); }); is_heap_until(i128, i128+7, std::greater<int>()).check([&](int *r){ CHECK(r == i128+7); }); is_heap_until(i129, i129+7, std::greater<int>()).check([&](int *r){ CHECK(r == i129+7); }); is_heap_until(i130, i130+7, std::greater<int>()).check([&](int *r){ CHECK(r == i130+7); }); is_heap_until(i131, i131+7, std::greater<int>()).check([&](int *r){ CHECK(r == i131+7); }); is_heap_until(i132, i132+7, std::greater<int>()).check([&](int *r){ CHECK(r == i132+7); }); is_heap_until(i133, i133+7, std::greater<int>()).check([&](int *r){ CHECK(r == i133+7); }); is_heap_until(i134, i134+7, std::greater<int>()).check([&](int *r){ CHECK(r == i134+7); }); is_heap_until(i135, i135+7, std::greater<int>()).check([&](int *r){ CHECK(r == i135+7); }); is_heap_until(i136, i136+7, std::greater<int>()).check([&](int *r){ CHECK(r == i136+5); }); is_heap_until(i137, i137+7, std::greater<int>()).check([&](int *r){ CHECK(r == i137+5); }); is_heap_until(i138, i138+7, std::greater<int>()).check([&](int *r){ CHECK(r == i138+6); }); is_heap_until(i139, i139+7, std::greater<int>()).check([&](int *r){ CHECK(r == i139+7); }); is_heap_until(i140, i140+7, std::greater<int>()).check([&](int *r){ CHECK(r == i140+5); }); is_heap_until(i141, i141+7, std::greater<int>()).check([&](int *r){ CHECK(r == i141+5); }); is_heap_until(i142, i142+7, std::greater<int>()).check([&](int *r){ CHECK(r == i142+6); }); is_heap_until(i143, i143+7, std::greater<int>()).check([&](int *r){ CHECK(r == i143+7); }); is_heap_until(i144, i144+7, std::greater<int>()).check([&](int *r){ CHECK(r == i144+5); }); is_heap_until(i145, i145+7, std::greater<int>()).check([&](int *r){ CHECK(r == i145+5); }); is_heap_until(i146, i146+7, std::greater<int>()).check([&](int *r){ CHECK(r == i146+6); }); is_heap_until(i147, i147+7, std::greater<int>()).check([&](int *r){ CHECK(r == i147+7); }); is_heap_until(i148, i148+7, std::greater<int>()).check([&](int *r){ CHECK(r == i148+5); }); is_heap_until(i149, i149+7, std::greater<int>()).check([&](int *r){ CHECK(r == i149+5); }); is_heap_until(i150, i150+7, std::greater<int>()).check([&](int *r){ CHECK(r == i150+6); }); is_heap_until(i151, i151+7, std::greater<int>()).check([&](int *r){ CHECK(r == i151+7); }); is_heap_until(i152, i152+7, std::greater<int>()).check([&](int *r){ CHECK(r == i152+3); }); is_heap_until(i153, i153+7, std::greater<int>()).check([&](int *r){ CHECK(r == i153+3); }); is_heap_until(i154, i154+7, std::greater<int>()).check([&](int *r){ CHECK(r == i154+3); }); is_heap_until(i155, i155+7, std::greater<int>()).check([&](int *r){ CHECK(r == i155+3); }); is_heap_until(i156, i156+7, std::greater<int>()).check([&](int *r){ CHECK(r == i156+3); }); is_heap_until(i157, i157+7, std::greater<int>()).check([&](int *r){ CHECK(r == i157+3); }); is_heap_until(i158, i158+7, std::greater<int>()).check([&](int *r){ CHECK(r == i158+3); }); is_heap_until(i159, i159+7, std::greater<int>()).check([&](int *r){ CHECK(r == i159+3); }); is_heap_until(i160, i160+7, std::greater<int>()).check([&](int *r){ CHECK(r == i160+4); }); is_heap_until(i161, i161+7, std::greater<int>()).check([&](int *r){ CHECK(r == i161+4); }); is_heap_until(i162, i162+7, std::greater<int>()).check([&](int *r){ CHECK(r == i162+4); }); is_heap_until(i163, i163+7, std::greater<int>()).check([&](int *r){ CHECK(r == i163+4); }); is_heap_until(i164, i164+7, std::greater<int>()).check([&](int *r){ CHECK(r == i164+7); }); is_heap_until(i165, i165+7, std::greater<int>()).check([&](int *r){ CHECK(r == i165+7); }); is_heap_until(i166, i166+7, std::greater<int>()).check([&](int *r){ CHECK(r == i166+7); }); is_heap_until(i167, i167+7, std::greater<int>()).check([&](int *r){ CHECK(r == i167+7); }); is_heap_until(i168, i168+7, std::greater<int>()).check([&](int *r){ CHECK(r == i168+3); }); is_heap_until(i169, i169+7, std::greater<int>()).check([&](int *r){ CHECK(r == i169+3); }); is_heap_until(i170, i170+7, std::greater<int>()).check([&](int *r){ CHECK(r == i170+3); }); is_heap_until(i171, i171+7, std::greater<int>()).check([&](int *r){ CHECK(r == i171+3); }); is_heap_until(i172, i172+7, std::greater<int>()).check([&](int *r){ CHECK(r == i172+3); }); is_heap_until(i173, i173+7, std::greater<int>()).check([&](int *r){ CHECK(r == i173+3); }); is_heap_until(i174, i174+7, std::greater<int>()).check([&](int *r){ CHECK(r == i174+3); }); is_heap_until(i175, i175+7, std::greater<int>()).check([&](int *r){ CHECK(r == i175+3); }); is_heap_until(i176, i176+7, std::greater<int>()).check([&](int *r){ CHECK(r == i176+4); }); is_heap_until(i177, i177+7, std::greater<int>()).check([&](int *r){ CHECK(r == i177+4); }); is_heap_until(i178, i178+7, std::greater<int>()).check([&](int *r){ CHECK(r == i178+4); }); is_heap_until(i179, i179+7, std::greater<int>()).check([&](int *r){ CHECK(r == i179+4); }); is_heap_until(i180, i180+7, std::greater<int>()).check([&](int *r){ CHECK(r == i180+5); }); is_heap_until(i181, i181+7, std::greater<int>()).check([&](int *r){ CHECK(r == i181+5); }); is_heap_until(i182, i182+7, std::greater<int>()).check([&](int *r){ CHECK(r == i182+6); }); is_heap_until(i183, i183+7, std::greater<int>()).check([&](int *r){ CHECK(r == i183+7); }); is_heap_until(i184, i184+7, std::greater<int>()).check([&](int *r){ CHECK(r == i184+1); }); is_heap_until(i185, i185+7, std::greater<int>()).check([&](int *r){ CHECK(r == i185+1); }); is_heap_until(i186, i186+7, std::greater<int>()).check([&](int *r){ CHECK(r == i186+1); }); is_heap_until(i187, i187+7, std::greater<int>()).check([&](int *r){ CHECK(r == i187+1); }); is_heap_until(i188, i188+7, std::greater<int>()).check([&](int *r){ CHECK(r == i188+1); }); is_heap_until(i189, i189+7, std::greater<int>()).check([&](int *r){ CHECK(r == i189+1); }); is_heap_until(i190, i190+7, std::greater<int>()).check([&](int *r){ CHECK(r == i190+1); }); is_heap_until(i191, i191+7, std::greater<int>()).check([&](int *r){ CHECK(r == i191+1); }); is_heap_until(i192, i192+7, std::greater<int>()).check([&](int *r){ CHECK(r == i192+1); }); is_heap_until(i193, i193+7, std::greater<int>()).check([&](int *r){ CHECK(r == i193+1); }); is_heap_until(i194, i194+7, std::greater<int>()).check([&](int *r){ CHECK(r == i194+1); }); is_heap_until(i195, i195+7, std::greater<int>()).check([&](int *r){ CHECK(r == i195+1); }); is_heap_until(i196, i196+7, std::greater<int>()).check([&](int *r){ CHECK(r == i196+1); }); is_heap_until(i197, i197+7, std::greater<int>()).check([&](int *r){ CHECK(r == i197+1); }); is_heap_until(i198, i198+7, std::greater<int>()).check([&](int *r){ CHECK(r == i198+1); }); is_heap_until(i199, i199+7, std::greater<int>()).check([&](int *r){ CHECK(r == i199+1); }); is_heap_until(i200, i200+7, std::greater<int>()).check([&](int *r){ CHECK(r == i200+1); }); is_heap_until(i201, i201+7, std::greater<int>()).check([&](int *r){ CHECK(r == i201+1); }); is_heap_until(i202, i202+7, std::greater<int>()).check([&](int *r){ CHECK(r == i202+1); }); is_heap_until(i203, i203+7, std::greater<int>()).check([&](int *r){ CHECK(r == i203+1); }); is_heap_until(i204, i204+7, std::greater<int>()).check([&](int *r){ CHECK(r == i204+1); }); is_heap_until(i205, i205+7, std::greater<int>()).check([&](int *r){ CHECK(r == i205+1); }); is_heap_until(i206, i206+7, std::greater<int>()).check([&](int *r){ CHECK(r == i206+1); }); is_heap_until(i207, i207+7, std::greater<int>()).check([&](int *r){ CHECK(r == i207+1); }); is_heap_until(i208, i208+7, std::greater<int>()).check([&](int *r){ CHECK(r == i208+1); }); is_heap_until(i209, i209+7, std::greater<int>()).check([&](int *r){ CHECK(r == i209+1); }); is_heap_until(i210, i210+7, std::greater<int>()).check([&](int *r){ CHECK(r == i210+1); }); is_heap_until(i211, i211+7, std::greater<int>()).check([&](int *r){ CHECK(r == i211+1); }); is_heap_until(i212, i212+7, std::greater<int>()).check([&](int *r){ CHECK(r == i212+1); }); is_heap_until(i213, i213+7, std::greater<int>()).check([&](int *r){ CHECK(r == i213+1); }); is_heap_until(i214, i214+7, std::greater<int>()).check([&](int *r){ CHECK(r == i214+1); }); is_heap_until(i215, i215+7, std::greater<int>()).check([&](int *r){ CHECK(r == i215+1); }); is_heap_until(i216, i216+7, std::greater<int>()).check([&](int *r){ CHECK(r == i216+2); }); is_heap_until(i217, i217+7, std::greater<int>()).check([&](int *r){ CHECK(r == i217+2); }); is_heap_until(i218, i218+7, std::greater<int>()).check([&](int *r){ CHECK(r == i218+2); }); is_heap_until(i219, i219+7, std::greater<int>()).check([&](int *r){ CHECK(r == i219+2); }); is_heap_until(i220, i220+7, std::greater<int>()).check([&](int *r){ CHECK(r == i220+2); }); is_heap_until(i221, i221+7, std::greater<int>()).check([&](int *r){ CHECK(r == i221+2); }); is_heap_until(i222, i222+7, std::greater<int>()).check([&](int *r){ CHECK(r == i222+2); }); is_heap_until(i223, i223+7, std::greater<int>()).check([&](int *r){ CHECK(r == i223+2); }); is_heap_until(i224, i224+7, std::greater<int>()).check([&](int *r){ CHECK(r == i224+2); }); is_heap_until(i225, i225+7, std::greater<int>()).check([&](int *r){ CHECK(r == i225+2); }); is_heap_until(i226, i226+7, std::greater<int>()).check([&](int *r){ CHECK(r == i226+2); }); is_heap_until(i227, i227+7, std::greater<int>()).check([&](int *r){ CHECK(r == i227+2); }); is_heap_until(i228, i228+7, std::greater<int>()).check([&](int *r){ CHECK(r == i228+2); }); is_heap_until(i229, i229+7, std::greater<int>()).check([&](int *r){ CHECK(r == i229+2); }); is_heap_until(i230, i230+7, std::greater<int>()).check([&](int *r){ CHECK(r == i230+2); }); is_heap_until(i231, i231+7, std::greater<int>()).check([&](int *r){ CHECK(r == i231+2); }); is_heap_until(i232, i232+7, std::greater<int>()).check([&](int *r){ CHECK(r == i232+3); }); is_heap_until(i233, i233+7, std::greater<int>()).check([&](int *r){ CHECK(r == i233+3); }); is_heap_until(i234, i234+7, std::greater<int>()).check([&](int *r){ CHECK(r == i234+3); }); is_heap_until(i235, i235+7, std::greater<int>()).check([&](int *r){ CHECK(r == i235+3); }); is_heap_until(i236, i236+7, std::greater<int>()).check([&](int *r){ CHECK(r == i236+3); }); is_heap_until(i237, i237+7, std::greater<int>()).check([&](int *r){ CHECK(r == i237+3); }); is_heap_until(i238, i238+7, std::greater<int>()).check([&](int *r){ CHECK(r == i238+3); }); is_heap_until(i239, i239+7, std::greater<int>()).check([&](int *r){ CHECK(r == i239+3); }); is_heap_until(i240, i240+7, std::greater<int>()).check([&](int *r){ CHECK(r == i240+4); }); is_heap_until(i241, i241+7, std::greater<int>()).check([&](int *r){ CHECK(r == i241+4); }); is_heap_until(i242, i242+7, std::greater<int>()).check([&](int *r){ CHECK(r == i242+4); }); is_heap_until(i243, i243+7, std::greater<int>()).check([&](int *r){ CHECK(r == i243+4); }); is_heap_until(i244, i244+7, std::greater<int>()).check([&](int *r){ CHECK(r == i244+5); }); is_heap_until(i245, i245+7, std::greater<int>()).check([&](int *r){ CHECK(r == i245+5); }); is_heap_until(i246, i246+7, std::greater<int>()).check([&](int *r){ CHECK(r == i246+6); }); #endif } struct S { int i; }; int main() { test_basic(); test_pred(); // Test projections: S i185[] = {S{1}, S{0}, S{0}, S{0}, S{0}, S{0}, S{1}}; ::make_testable_1(ranges::is_heap_until)(i185, i185+7, std::greater<int>(), &S::i) .check([&](S *r){ CHECK(r == i185+1); }); // Test rvalue range #ifndef RANGES_WORKAROUND_MSVC_573728 auto res0 = ranges::is_heap_until(std::move(i185), std::greater<int>(), &S::i); CHECK(::is_dangling(res0)); #endif // RANGES_WORKAROUND_MSVC_573728 std::vector<S> vec(ranges::begin(i185), ranges::end(i185)); auto res1 = ranges::is_heap_until(std::move(vec), std::greater<int>(), &S::i); CHECK(::is_dangling(res1)); #ifdef IS_HEAP_UNTIL_3 { constexpr test::array<int, 7> i{{1, 0, 0, 0, 0, 0, 1}}; STATIC_CHECK(ranges::is_heap_until(i, ranges::greater{}) == ranges::begin(i) + 1); } #endif return ::test_result(); }
0
repos/range-v3/test
repos/range-v3/test/algorithm/set_intersection.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 // //===----------------------------------------------------------------------===// // // 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 <functional> #include <range/v3/core.hpp> #include <range/v3/algorithm/fill.hpp> #include <range/v3/algorithm/set_algorithm.hpp> #include <range/v3/algorithm/lexicographical_compare.hpp> #include "../simple_test.hpp" #include "../test_utils.hpp" #include "../test_iterators.hpp" template<class Iter1, class Iter2, class OutIter> void test() { int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4}; static const int sa = sizeof(ia)/sizeof(ia[0]); int ib[] = {2, 4, 4, 6}; static const int sb = sizeof(ib)/sizeof(ib[0]); int ic[20]; int ir[] = {2, 4, 4}; static const int sr = sizeof(ir)/sizeof(ir[0]); auto set_intersection = ::make_testable_2<true, true>(ranges::set_intersection); set_intersection(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+sb), OutIter(ic)).check([&](OutIter ce) { CHECK((base(ce) - ic) == sr); CHECK(std::lexicographical_compare(ic, base(ce), ir, ir+sr) == false); ranges::fill(ic, 0); }); set_intersection(Iter1(ib), Iter1(ib+sb), Iter2(ia), Iter2(ia+sa), OutIter(ic)).check([&](OutIter ce) { CHECK((base(ce) - ic) == sr); CHECK(std::lexicographical_compare(ic, base(ce), ir, ir+sr) == false); ranges::fill(ic, 0); }); set_intersection(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+sb), OutIter(ic), std::less<int>()).check([&](OutIter ce) { CHECK((base(ce) - ic) == sr); CHECK(std::lexicographical_compare(ic, base(ce), ir, ir+sr) == false); ranges::fill(ic, 0); }); set_intersection(Iter1(ib), Iter1(ib+sb), Iter2(ia), Iter2(ia+sa), OutIter(ic), std::less<int>()).check([&](OutIter ce) { CHECK((base(ce) - ic) == sr); CHECK(std::lexicographical_compare(ic, base(ce), ir, ir+sr) == false); ranges::fill(ic, 0); }); } struct S { int i; }; struct T { int j; }; struct U { int k; U& operator=(S s) { k = s.i; return *this;} U& operator=(T t) { k = t.j; return *this;} }; constexpr bool test_constexpr() { using namespace ranges; int ic[20] = {0}; int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4}; int ib[4] = {2, 4, 4, 6}; int ir[3] = {2, 4, 4}; constexpr auto sr = size(ir); int * res = set_intersection(ia, ib, ic, less{}); STATIC_CHECK_RETURN((res - ic) == sr); STATIC_CHECK_RETURN(lexicographical_compare(ic, res, ir, ir + sr, less{}) == 0); return true; } int main() { #ifdef SET_INTERSECTION_1 test<InputIterator<const int*>, InputIterator<const int*>, OutputIterator<int*> >(); test<InputIterator<const int*>, InputIterator<const int*>, ForwardIterator<int*> >(); test<InputIterator<const int*>, InputIterator<const int*>, BidirectionalIterator<int*> >(); test<InputIterator<const int*>, InputIterator<const int*>, RandomAccessIterator<int*> >(); test<InputIterator<const int*>, InputIterator<const int*>, int*>(); test<InputIterator<const int*>, ForwardIterator<const int*>, OutputIterator<int*> >(); test<InputIterator<const int*>, ForwardIterator<const int*>, ForwardIterator<int*> >(); test<InputIterator<const int*>, ForwardIterator<const int*>, BidirectionalIterator<int*> >(); test<InputIterator<const int*>, ForwardIterator<const int*>, RandomAccessIterator<int*> >(); test<InputIterator<const int*>, ForwardIterator<const int*>, int*>(); test<InputIterator<const int*>, BidirectionalIterator<const int*>, OutputIterator<int*> >(); test<InputIterator<const int*>, BidirectionalIterator<const int*>, ForwardIterator<int*> >(); test<InputIterator<const int*>, BidirectionalIterator<const int*>, BidirectionalIterator<int*> >(); test<InputIterator<const int*>, BidirectionalIterator<const int*>, RandomAccessIterator<int*> >(); test<InputIterator<const int*>, BidirectionalIterator<const int*>, int*>(); test<InputIterator<const int*>, RandomAccessIterator<const int*>, OutputIterator<int*> >(); test<InputIterator<const int*>, RandomAccessIterator<const int*>, ForwardIterator<int*> >(); test<InputIterator<const int*>, RandomAccessIterator<const int*>, BidirectionalIterator<int*> >(); test<InputIterator<const int*>, RandomAccessIterator<const int*>, RandomAccessIterator<int*> >(); test<InputIterator<const int*>, RandomAccessIterator<const int*>, int*>(); test<InputIterator<const int*>, const int*, OutputIterator<int*> >(); test<InputIterator<const int*>, const int*, ForwardIterator<int*> >(); test<InputIterator<const int*>, const int*, BidirectionalIterator<int*> >(); test<InputIterator<const int*>, const int*, RandomAccessIterator<int*> >(); test<InputIterator<const int*>, const int*, int*>(); #endif #ifdef SET_INTERSECTION_2 test<ForwardIterator<const int*>, InputIterator<const int*>, OutputIterator<int*> >(); test<ForwardIterator<const int*>, InputIterator<const int*>, ForwardIterator<int*> >(); test<ForwardIterator<const int*>, InputIterator<const int*>, BidirectionalIterator<int*> >(); test<ForwardIterator<const int*>, InputIterator<const int*>, RandomAccessIterator<int*> >(); test<ForwardIterator<const int*>, InputIterator<const int*>, int*>(); test<ForwardIterator<const int*>, ForwardIterator<const int*>, OutputIterator<int*> >(); test<ForwardIterator<const int*>, ForwardIterator<const int*>, ForwardIterator<int*> >(); test<ForwardIterator<const int*>, ForwardIterator<const int*>, BidirectionalIterator<int*> >(); test<ForwardIterator<const int*>, ForwardIterator<const int*>, RandomAccessIterator<int*> >(); test<ForwardIterator<const int*>, ForwardIterator<const int*>, int*>(); test<ForwardIterator<const int*>, BidirectionalIterator<const int*>, OutputIterator<int*> >(); test<ForwardIterator<const int*>, BidirectionalIterator<const int*>, ForwardIterator<int*> >(); test<ForwardIterator<const int*>, BidirectionalIterator<const int*>, BidirectionalIterator<int*> >(); test<ForwardIterator<const int*>, BidirectionalIterator<const int*>, RandomAccessIterator<int*> >(); test<ForwardIterator<const int*>, BidirectionalIterator<const int*>, int*>(); test<ForwardIterator<const int*>, RandomAccessIterator<const int*>, OutputIterator<int*> >(); test<ForwardIterator<const int*>, RandomAccessIterator<const int*>, ForwardIterator<int*> >(); test<ForwardIterator<const int*>, RandomAccessIterator<const int*>, BidirectionalIterator<int*> >(); test<ForwardIterator<const int*>, RandomAccessIterator<const int*>, RandomAccessIterator<int*> >(); test<ForwardIterator<const int*>, RandomAccessIterator<const int*>, int*>(); test<ForwardIterator<const int*>, const int*, OutputIterator<int*> >(); test<ForwardIterator<const int*>, const int*, ForwardIterator<int*> >(); test<ForwardIterator<const int*>, const int*, BidirectionalIterator<int*> >(); test<ForwardIterator<const int*>, const int*, RandomAccessIterator<int*> >(); test<ForwardIterator<const int*>, const int*, int*>(); #endif #ifdef SET_INTERSECTION_3 test<BidirectionalIterator<const int*>, InputIterator<const int*>, OutputIterator<int*> >(); test<BidirectionalIterator<const int*>, InputIterator<const int*>, ForwardIterator<int*> >(); test<BidirectionalIterator<const int*>, InputIterator<const int*>, BidirectionalIterator<int*> >(); test<BidirectionalIterator<const int*>, InputIterator<const int*>, RandomAccessIterator<int*> >(); test<BidirectionalIterator<const int*>, InputIterator<const int*>, int*>(); test<BidirectionalIterator<const int*>, ForwardIterator<const int*>, OutputIterator<int*> >(); test<BidirectionalIterator<const int*>, ForwardIterator<const int*>, ForwardIterator<int*> >(); test<BidirectionalIterator<const int*>, ForwardIterator<const int*>, BidirectionalIterator<int*> >(); test<BidirectionalIterator<const int*>, ForwardIterator<const int*>, RandomAccessIterator<int*> >(); test<BidirectionalIterator<const int*>, ForwardIterator<const int*>, int*>(); test<BidirectionalIterator<const int*>, BidirectionalIterator<const int*>, OutputIterator<int*> >(); test<BidirectionalIterator<const int*>, BidirectionalIterator<const int*>, ForwardIterator<int*> >(); test<BidirectionalIterator<const int*>, BidirectionalIterator<const int*>, BidirectionalIterator<int*> >(); test<BidirectionalIterator<const int*>, BidirectionalIterator<const int*>, RandomAccessIterator<int*> >(); test<BidirectionalIterator<const int*>, BidirectionalIterator<const int*>, int*>(); test<BidirectionalIterator<const int*>, RandomAccessIterator<const int*>, OutputIterator<int*> >(); test<BidirectionalIterator<const int*>, RandomAccessIterator<const int*>, ForwardIterator<int*> >(); test<BidirectionalIterator<const int*>, RandomAccessIterator<const int*>, BidirectionalIterator<int*> >(); test<BidirectionalIterator<const int*>, RandomAccessIterator<const int*>, RandomAccessIterator<int*> >(); test<BidirectionalIterator<const int*>, RandomAccessIterator<const int*>, int*>(); test<BidirectionalIterator<const int*>, const int*, OutputIterator<int*> >(); test<BidirectionalIterator<const int*>, const int*, ForwardIterator<int*> >(); test<BidirectionalIterator<const int*>, const int*, BidirectionalIterator<int*> >(); test<BidirectionalIterator<const int*>, const int*, RandomAccessIterator<int*> >(); test<BidirectionalIterator<const int*>, const int*, int*>(); #endif #ifdef SET_INTERSECTION_4 test<RandomAccessIterator<const int*>, InputIterator<const int*>, OutputIterator<int*> >(); test<RandomAccessIterator<const int*>, InputIterator<const int*>, ForwardIterator<int*> >(); test<RandomAccessIterator<const int*>, InputIterator<const int*>, BidirectionalIterator<int*> >(); test<RandomAccessIterator<const int*>, InputIterator<const int*>, RandomAccessIterator<int*> >(); test<RandomAccessIterator<const int*>, InputIterator<const int*>, int*>(); test<RandomAccessIterator<const int*>, ForwardIterator<const int*>, OutputIterator<int*> >(); test<RandomAccessIterator<const int*>, ForwardIterator<const int*>, ForwardIterator<int*> >(); test<RandomAccessIterator<const int*>, ForwardIterator<const int*>, BidirectionalIterator<int*> >(); test<RandomAccessIterator<const int*>, ForwardIterator<const int*>, RandomAccessIterator<int*> >(); test<RandomAccessIterator<const int*>, ForwardIterator<const int*>, int*>(); test<RandomAccessIterator<const int*>, BidirectionalIterator<const int*>, OutputIterator<int*> >(); test<RandomAccessIterator<const int*>, BidirectionalIterator<const int*>, ForwardIterator<int*> >(); test<RandomAccessIterator<const int*>, BidirectionalIterator<const int*>, BidirectionalIterator<int*> >(); test<RandomAccessIterator<const int*>, BidirectionalIterator<const int*>, RandomAccessIterator<int*> >(); test<RandomAccessIterator<const int*>, BidirectionalIterator<const int*>, int*>(); test<RandomAccessIterator<const int*>, RandomAccessIterator<const int*>, OutputIterator<int*> >(); test<RandomAccessIterator<const int*>, RandomAccessIterator<const int*>, ForwardIterator<int*> >(); test<RandomAccessIterator<const int*>, RandomAccessIterator<const int*>, BidirectionalIterator<int*> >(); test<RandomAccessIterator<const int*>, RandomAccessIterator<const int*>, RandomAccessIterator<int*> >(); test<RandomAccessIterator<const int*>, RandomAccessIterator<const int*>, int*>(); test<RandomAccessIterator<const int*>, const int*, OutputIterator<int*> >(); test<RandomAccessIterator<const int*>, const int*, ForwardIterator<int*> >(); test<RandomAccessIterator<const int*>, const int*, BidirectionalIterator<int*> >(); test<RandomAccessIterator<const int*>, const int*, RandomAccessIterator<int*> >(); test<RandomAccessIterator<const int*>, const int*, int*>(); #endif #ifdef SET_INTERSECTION_5 test<const int*, InputIterator<const int*>, OutputIterator<int*> >(); test<const int*, InputIterator<const int*>, BidirectionalIterator<int*> >(); test<const int*, InputIterator<const int*>, BidirectionalIterator<int*> >(); test<const int*, InputIterator<const int*>, RandomAccessIterator<int*> >(); test<const int*, InputIterator<const int*>, int*>(); test<const int*, ForwardIterator<const int*>, OutputIterator<int*> >(); test<const int*, ForwardIterator<const int*>, ForwardIterator<int*> >(); test<const int*, ForwardIterator<const int*>, BidirectionalIterator<int*> >(); test<const int*, ForwardIterator<const int*>, RandomAccessIterator<int*> >(); test<const int*, ForwardIterator<const int*>, int*>(); test<const int*, BidirectionalIterator<const int*>, OutputIterator<int*> >(); test<const int*, BidirectionalIterator<const int*>, ForwardIterator<int*> >(); test<const int*, BidirectionalIterator<const int*>, BidirectionalIterator<int*> >(); test<const int*, BidirectionalIterator<const int*>, RandomAccessIterator<int*> >(); test<const int*, BidirectionalIterator<const int*>, int*>(); test<const int*, RandomAccessIterator<const int*>, OutputIterator<int*> >(); test<const int*, RandomAccessIterator<const int*>, ForwardIterator<int*> >(); test<const int*, RandomAccessIterator<const int*>, BidirectionalIterator<int*> >(); test<const int*, RandomAccessIterator<const int*>, RandomAccessIterator<int*> >(); test<const int*, RandomAccessIterator<const int*>, int*>(); test<const int*, const int*, OutputIterator<int*> >(); test<const int*, const int*, ForwardIterator<int*> >(); test<const int*, const int*, BidirectionalIterator<int*> >(); test<const int*, const int*, RandomAccessIterator<int*> >(); test<const int*, const int*, int*>(); #endif #ifdef SET_INTERSECTION_6 // Test projections { S ia[] = {S{1}, S{2}, S{2}, S{3}, S{3}, S{3}, S{4}, S{4}, S{4}, S{4}}; T ib[] = {T{2}, T{4}, T{4}, T{6}}; U ic[20]; int ir[] = {2, 4, 4}; static const int sr = sizeof(ir)/sizeof(ir[0]); U * res = ranges::set_intersection(ranges::views::all(ia), ranges::views::all(ib), ic, std::less<int>(), &S::i, &T::j); CHECK((res - ic) == sr); CHECK(ranges::lexicographical_compare(ic, res, ir, ir+sr, std::less<int>(), &U::k) == false); } { STATIC_CHECK(test_constexpr()); } #endif return ::test_result(); }
0
repos/range-v3/test
repos/range-v3/test/algorithm/set_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_DIFFERENCE_1 #include "./set_difference.hpp"
0
repos/range-v3/test
repos/range-v3/test/algorithm/generate.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.hpp> #include <range/v3/iterator/insert_iterators.hpp> #include <range/v3/view/counted.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_result<Iter, gen_test> res = ranges::generate(Iter(ia), Sent(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); auto rng = ::MakeTestRange(Iter(ia), Sent(ia + n)); res = ranges::generate(rng, res.fun); CHECK(ia[0] == 5); CHECK(ia[1] == 6); CHECK(ia[2] == 7); CHECK(ia[3] == 8); CHECK(res.out == Iter(ia + n)); CHECK(res.fun.i_ == 9); auto res2 = ranges::generate(std::move(rng), res.fun); CHECK(ia[0] == 9); CHECK(ia[1] == 10); CHECK(ia[2] == 11); CHECK(ia[3] == 12); CHECK(::is_dangling(res2.out)); CHECK(res2.fun.i_ == 13); } void test2() { // Test ranges::generate with a genuine output range std::vector<int> v; auto rng = ranges::views::counted(ranges::back_inserter(v), 5); ranges::generate(rng, 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() { const unsigned n = 4; int ia[n] = {0}; const auto res = ranges::generate(Iter(ia), Sent(ia + n), gen_test(1)); STATIC_CHECK_RETURN(ia[0] == 1); STATIC_CHECK_RETURN(ia[1] == 2); STATIC_CHECK_RETURN(ia[2] == 3); STATIC_CHECK_RETURN(ia[3] == 4); STATIC_CHECK_RETURN(res.out == Iter(ia + n)); STATIC_CHECK_RETURN(res.fun.i_ == 5); auto rng = ranges::make_subrange(Iter(ia), Sent(ia + n)); const auto res2 = ranges::generate(rng, res.fun); STATIC_CHECK_RETURN(ia[0] == 5); STATIC_CHECK_RETURN(ia[1] == 6); STATIC_CHECK_RETURN(ia[2] == 7); STATIC_CHECK_RETURN(ia[3] == 8); STATIC_CHECK_RETURN(res2.out == Iter(ia + n)); STATIC_CHECK_RETURN(res2.fun.i_ == 9); const auto res3 = ranges::generate(std::move(rng), res2.fun); STATIC_CHECK_RETURN(ia[0] == 9); STATIC_CHECK_RETURN(ia[1] == 10); STATIC_CHECK_RETURN(ia[2] == 11); STATIC_CHECK_RETURN(ia[3] == 12); STATIC_CHECK_RETURN(res3.out == Iter(ia + n)); STATIC_CHECK_RETURN(res3.fun.i_ == 13); return true; } 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/equal_range.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 <iterator> #include <range/v3/core.hpp> #include <range/v3/algorithm/copy.hpp> #include <range/v3/algorithm/equal_range.hpp> #include <range/v3/functional/identity.hpp> #include <range/v3/functional/invoke.hpp> #include <range/v3/iterator/operations.hpp> #include <range/v3/iterator/insert_iterators.hpp> #include <range/v3/view/iota.hpp> #include <range/v3/view/join.hpp> #include <range/v3/view/repeat_n.hpp> #include <range/v3/view/take.hpp> #include <range/v3/view/transform.hpp> #include "../array.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::equal_range(vec, my_int{10}, compare); } template<class Iter, class Sent, class T, class Proj = ranges::identity> void test_it(Iter first, Sent last, const T& value, Proj proj = Proj{}) { ranges::subrange<Iter, Iter> i = ranges::equal_range(first, last, value, ranges::less{}, proj); for (Iter j = first; j != i.begin(); ++j) CHECK(ranges::invoke(proj, *j) < value); for (Iter j = i.begin(); j != last; ++j) CHECK(!(ranges::invoke(proj, *j) < value)); for (Iter j = first; j != i.end(); ++j) CHECK(!(value < ranges::invoke(proj, *j))); for (Iter j = i.end(); j != last; ++j) CHECK(value < ranges::invoke(proj, *j)); auto res = ranges::equal_range( ranges::make_subrange(first, last), value, ranges::less{}, proj); for (Iter j = first; j != res.begin(); ++j) CHECK(ranges::invoke(proj, *j) < value); for (Iter j = res.begin(); j != last; ++j) CHECK(!(ranges::invoke(proj, *j) < value)); for (Iter j = first; j != res.end(); ++j) CHECK(!(value < ranges::invoke(proj, *j))); for (Iter j = res.end(); j != last; ++j) CHECK(value < ranges::invoke(proj, *j)); } template<class Iter, class Sent = Iter> void test_it() { using namespace ranges::views; static constexpr unsigned M = 10; std::vector<int> v; auto input = ints | take(100) | transform([](int i){return repeat_n(i,M);}) | join; ranges::copy(input, ranges::back_inserter(v)); for (int x = 0; x <= (int)M; ++x) test_it(Iter(v.data()), Sent(v.data()+v.size()), x); } template<class Iter, class Sent, class T> constexpr bool test_constexpr(Iter first, Sent last, const T & value) { bool result = true; const auto i = ranges::equal_range(first, last, value); for(Iter j = first; j != i.begin(); ++j) { STATIC_CHECK_RETURN(*j < value); } for(Iter j = i.begin(); j != last; ++j) { STATIC_CHECK_RETURN(!(*j < value)); } for(Iter j = first; j != i.end(); ++j) { STATIC_CHECK_RETURN(!(value < *j)); } for(Iter j = i.end(); j != last; ++j) { STATIC_CHECK_RETURN(value < *j); } const auto res = ranges::equal_range(ranges::make_subrange(first, last), value); for(Iter j = first; j != res.begin(); ++j) { STATIC_CHECK_RETURN(*j < value); } for(Iter j = res.begin(); j != last; ++j) { STATIC_CHECK_RETURN(!(*j < value)); } for(Iter j = first; j != res.end(); ++j) { STATIC_CHECK_RETURN(!(value < *j)); } for(Iter j = res.end(); j != last; ++j) { STATIC_CHECK_RETURN(value < *j); } return result; } template<class Iter, class Sent = Iter> constexpr bool test_constexpr() { constexpr unsigned M = 10; constexpr unsigned N = 10; test::array<int, N * M> v{{0}}; for(unsigned i = 0; i < N; ++i) { for(unsigned j = 0; j < M; ++j) { v[i * M + j] = (int)i; } } for(int x = 0; x <= (int)M; ++x) { STATIC_CHECK_RETURN(test_constexpr(Iter(v.data()), Sent(v.data() + v.size()), x)); } return true; } constexpr bool test_constexpr_some() { constexpr int d[] = {0, 1, 2, 3}; for(auto e = ranges::begin(d); e < ranges::end(d); ++e) { for(int x = -1; x <= 4; ++x) { STATIC_CHECK_RETURN(test_constexpr(d, e, x)); } } return true; } int main() { int d[] = {0, 1, 2, 3}; for (int* e = d; e <= d+4; ++e) for (int x = -1; x <= 4; ++x) test_it(d, e, x); test_it<ForwardIterator<const int*> >(); test_it<BidirectionalIterator<const int*> >(); test_it<RandomAccessIterator<const int*> >(); test_it<const int*>(); test_it<ForwardIterator<const int*>, Sentinel<const int*> >(); test_it<BidirectionalIterator<const int*>, Sentinel<const int*> >(); test_it<RandomAccessIterator<const int*>, Sentinel<const int*> >(); { struct foo { int i; }; foo some_foos[] = {{1}, {2}, {4}}; test_it(some_foos, some_foos + 3, 2, &foo::i); } { STATIC_CHECK(test_constexpr_some()); STATIC_CHECK(test_constexpr<ForwardIterator<const int *>>()); STATIC_CHECK(test_constexpr<BidirectionalIterator<const int *>>()); STATIC_CHECK(test_constexpr<RandomAccessIterator<const int *>>()); STATIC_CHECK(test_constexpr<const int *>()); STATIC_CHECK(test_constexpr<ForwardIterator<const int *>, Sentinel<const int *>>()); STATIC_CHECK(test_constexpr<BidirectionalIterator<const int *>, Sentinel<const int *>>()); STATIC_CHECK(test_constexpr<RandomAccessIterator<const int *>, Sentinel<const int *>>()); } return ::test_result(); }
0
repos/range-v3/test
repos/range-v3/test/algorithm/none_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/none_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::none_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::none_of(all_even.begin(), all_even.end(), even)); CHECK(!ranges::none_of(one_even.begin(), one_even.end(), even)); CHECK(ranges::none_of(none_even.begin(), none_even.end(), even)); CHECK(!ranges::none_of(all_even, even)); CHECK(!ranges::none_of(one_even, even)); CHECK(ranges::none_of(none_even, even)); using ILI = std::initializer_list<int>; CHECK(!ranges::none_of(ILI{0, 2, 4, 6}, [](int n) { return n % 2 == 0; })); CHECK(!ranges::none_of(ILI{1, 3, 4, 7}, [](int n) { return n % 2 == 0; })); CHECK(ranges::none_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::none_of(all_true.begin(), all_true.end(), &S::p)); CHECK(!ranges::none_of(one_true.begin(), one_true.end(), &S::p)); CHECK(ranges::none_of(none_true.begin(), none_true.end(), &S::p)); CHECK(!ranges::none_of(all_true, &S::p)); CHECK(!ranges::none_of(one_true, &S::p)); CHECK(ranges::none_of(none_true, &S::p)); using ILS = std::initializer_list<S>; CHECK(!ranges::none_of(ILS{S(true), S(true), S(true)}, &S::p)); CHECK(!ranges::none_of(ILS{S(false), S(true), S(false)}, &S::p)); CHECK(ranges::none_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/fold.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 <cmath> #include <functional> #include <range/v3/algorithm/fold.hpp> #include <range/v3/algorithm/min.hpp> #include <range/v3/core.hpp> #include "../simple_test.hpp" #include "../test_iterators.hpp" struct Approx { double value; Approx(double v) : value(v) {} friend bool operator==(Approx a, double d) { return std::fabs(a.value - d) < 0.001; } friend bool operator==(double d, Approx a) { return a == d; } }; template<class Iter, class Sent = Iter> void test_left() { double da[] = {0.25, 0.75}; CHECK(ranges::fold_left(Iter(da), Sent(da), 1, std::plus<>()) == Approx{1.0}); CHECK(ranges::fold_left(Iter(da), Sent(da + 2), 1, std::plus<>()) == Approx{2.0}); CHECK(ranges::fold_left_first(Iter(da), Sent(da), ranges::min) == ranges::nullopt); CHECK(ranges::fold_left_first(Iter(da), Sent(da + 2), ranges::min) == ranges::optional<Approx>(0.25)); using ranges::make_subrange; CHECK(ranges::fold_left(make_subrange(Iter(da), Sent(da)), 1, std::plus<>()) == Approx{1.0}); CHECK(ranges::fold_left(make_subrange(Iter(da), Sent(da + 2)), 1, std::plus<>()) == Approx{2.0}); CHECK(ranges::fold_left_first(make_subrange(Iter(da), Sent(da)), ranges::min) == ranges::nullopt); CHECK(ranges::fold_left_first(make_subrange(Iter(da), Sent(da + 2)), ranges::min) == ranges::optional<Approx>(0.25)); } void test_right() { double da[] = {0.25, 0.75}; CHECK(ranges::fold_right(da, da + 2, 1, std::plus<>()) == Approx{2.0}); CHECK(ranges::fold_right(da, 1, std::plus<>()) == Approx{2.0}); // f(0.25, f(0.75, 1)) CHECK(ranges::fold_right(da, da + 2, 1, std::minus<>()) == Approx{0.5}); CHECK(ranges::fold_right(da, 1, std::minus<>()) == Approx{0.5}); int xs[] = {1, 2, 3}; auto concat = [](int i, std::string s) { return s + std::to_string(i); }; CHECK(ranges::fold_right(xs, xs + 2, std::string(), concat) == "21"); CHECK(ranges::fold_right(xs, std::string(), concat) == "321"); } int main() { test_left<InputIterator<const double *>>(); test_left<ForwardIterator<const double *>>(); test_left<BidirectionalIterator<const double *>>(); test_left<RandomAccessIterator<const double *>>(); test_left<const double *>(); test_left<InputIterator<const double *>, Sentinel<const double *>>(); test_left<ForwardIterator<const double *>, Sentinel<const double *>>(); test_left<BidirectionalIterator<const double *>, Sentinel<const double *>>(); test_left<RandomAccessIterator<const double *>, Sentinel<const double *>>(); test_right(); return ::test_result(); }
0
repos/range-v3/test
repos/range-v3/test/algorithm/set_union3.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_3 #include "./set_union.hpp"
0
repos/range-v3/test
repos/range-v3/test/algorithm/copy_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 #include <cstring> #include <algorithm> #include <utility> #include <vector> #include <range/v3/core.hpp> #include <range/v3/algorithm/copy_backward.hpp> #include "../array.hpp" #include "../simple_test.hpp" #include "../test_iterators.hpp" #include "../test_utils.hpp" constexpr bool test_constexpr() { using IL = std::initializer_list<int>; constexpr test::array<int, 4> input{{0, 1, 2, 3}}; test::array<int, 4> a1{{0, 0, 0, 0}}; auto res = ranges::copy_backward(input, ranges::end(a1)); STATIC_CHECK_RETURN(res.in == ranges::end(input)); STATIC_CHECK_RETURN(res.out == ranges::begin(a1)); STATIC_CHECK_RETURN(ranges::equal(a1, 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_backward(begin(a), end(a), end(out)); CHECK(res.in == end(a)); CHECK(res.out == begin(out)); CHECK(std::equal(a, a + size(a), out)); } { std::fill_n(out, size(out), std::make_pair(0, 0)); auto res = ranges::copy_backward(a, end(out)); CHECK(res.in == end(a)); CHECK(res.out == begin(out)); CHECK(std::equal(a, a + size(a), out)); } #ifndef RANGES_WORKAROUND_MSVC_573728 { std::fill_n(out, size(out), std::make_pair(0, 0)); auto res = ranges::copy_backward(std::move(a), end(out)); CHECK(::is_dangling(res.in)); CHECK(res.out == begin(out)); CHECK(std::equal(a, a + size(a), out)); } #endif { std::fill_n(out, size(out), std::make_pair(0, 0)); std::vector<std::pair<int, int>> vec(begin(a), end(a)); auto res = ranges::copy_backward(std::move(vec), end(out)); CHECK(::is_dangling(res.in)); CHECK(res.out == begin(out)); CHECK(std::equal(a, a + size(a), out)); } { std::fill_n(out, size(out), std::make_pair(0, 0)); auto res = ranges::copy_backward(ranges::views::all(a), end(out)); CHECK(res.in == end(a)); CHECK(res.out == begin(out)); CHECK(std::equal(a, a + size(a), out)); } { STATIC_CHECK(test_constexpr()); } return test_result(); }
0
repos/range-v3/test
repos/range-v3/test/algorithm/is_heap4.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_4 #include "./is_heap.hpp"
0
repos/range-v3/test
repos/range-v3/test/algorithm/partition_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 <tuple> #include <vector> #include <range/v3/core.hpp> #include <range/v3/algorithm/partition_copy.hpp> #include <range/v3/view/counted.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, 6, 8, 5, 7}; int r1[10] = {0}; int r2[10] = {0}; typedef ranges::partition_copy_result<Iter, OutputIterator<int*>, int*> P; P p = ranges::partition_copy(Iter(std::begin(ia)), Sent(std::end(ia)), OutputIterator<int*>(r1), r2, is_odd()); CHECK(p.in == Iter(std::end(ia))); CHECK(p.out1.base() == r1 + 4); CHECK(r1[0] == 1); CHECK(r1[1] == 3); CHECK(r1[2] == 5); CHECK(r1[3] == 7); CHECK(p.out2 == r2 + 4); CHECK(r2[0] == 2); CHECK(r2[1] == 4); CHECK(r2[2] == 6); CHECK(r2[3] == 8); } template<class Iter, class Sent = Iter> void test_range() { const int ia[] = {1, 2, 3, 4, 6, 8, 5, 7}; int r1[10] = {0}; int r2[10] = {0}; typedef ranges::partition_copy_result<Iter, OutputIterator<int*>, int*> P; P p = ranges::partition_copy(::as_lvalue(ranges::make_subrange(Iter(std::begin(ia)), Sent(std::end(ia)))), OutputIterator<int*>(r1), r2, is_odd()); CHECK(p.in == Iter(std::end(ia))); CHECK(p.out1.base() == r1 + 4); CHECK(r1[0] == 1); CHECK(r1[1] == 3); CHECK(r1[2] == 5); CHECK(r1[3] == 7); CHECK(p.out2 == r2 + 4); CHECK(r2[0] == 2); CHECK(r2[1] == 4); CHECK(r2[2] == 6); CHECK(r2[3] == 8); } struct S { int i; }; void test_proj() { // Test projections const S ia[] = {S{1}, S{2}, S{3}, S{4}, S{6}, S{8}, S{5}, S{7}}; S r1[10] = {S{0}}; S r2[10] = {S{0}}; typedef ranges::partition_copy_result<S const *, S*, S*> P; P p = ranges::partition_copy(ia, r1, r2, is_odd(), &S::i); CHECK(p.in == std::end(ia)); CHECK(p.out1 == r1 + 4); CHECK(r1[0].i == 1); CHECK(r1[1].i == 3); CHECK(r1[2].i == 5); CHECK(r1[3].i == 7); CHECK(p.out2 == r2 + 4); CHECK(r2[0].i == 2); CHECK(r2[1].i == 4); CHECK(r2[2].i == 6); CHECK(r2[3].i == 8); } void test_rvalue() { // Test rvalue ranges const S ia[] = {S{1}, S{2}, S{3}, S{4}, S{6}, S{8}, S{5}, S{7}}; S r1[10] = {}; S r2[10] = {}; auto p = ranges::partition_copy(std::move(ia), r1, r2, is_odd(), &S::i); #ifndef RANGES_WORKAROUND_MSVC_573728 CHECK(::is_dangling(p.in)); #endif CHECK(p.out1 == r1 + 4); CHECK(r1[0].i == 1); CHECK(r1[1].i == 3); CHECK(r1[2].i == 5); CHECK(r1[3].i == 7); CHECK(p.out2 == r2 + 4); CHECK(r2[0].i == 2); CHECK(r2[1].i == 4); CHECK(r2[2].i == 6); CHECK(r2[3].i == 8); std::fill(r1 + 0, r1 + 10, S{}); std::fill(r2 + 0, r2 + 10, S{}); std::vector<S> vec(ranges::begin(ia), ranges::end(ia)); auto q = ranges::partition_copy(std::move(vec), r1, r2, is_odd(), &S::i); #ifndef RANGES_WORKAROUND_MSVC_573728 CHECK(::is_dangling(q.in)); #endif CHECK(q.out1 == r1 + 4); CHECK(r1[0].i == 1); CHECK(r1[1].i == 3); CHECK(r1[2].i == 5); CHECK(r1[3].i == 7); CHECK(q.out2 == r2 + 4); CHECK(r2[0].i == 2); CHECK(r2[1].i == 4); CHECK(r2[2].i == 6); CHECK(r2[3].i == 8); } 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}; const auto p = partition_copy(ia, r1, r2, is_odd()); STATIC_CHECK_RETURN(p.in == std::end(ia)); STATIC_CHECK_RETURN(p.out1 == 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(p.out2 == 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() { 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_proj(); test_rvalue(); { STATIC_CHECK(test_constexpr()); } return ::test_result(); }
0
repos/range-v3/test
repos/range-v3/test/algorithm/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) //===----------------------------------------------------------------------===// // // 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.hpp> #include <range/v3/view/counted.hpp> #include "../simple_test.hpp" #include "../test_utils.hpp" #include "../test_iterators.hpp" template<class Iter1, class Iter2, typename Sent1 = Iter1, typename Sent2 = Iter2> void test_iter_impl() { int ia[] = {0, 1, 2, 3, 4, 5}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::search(Iter1(ia), Sent1(ia+sa), Iter2(ia), Sent2(ia)).begin() == Iter1(ia)); CHECK(ranges::search(Iter1(ia), Sent1(ia+sa), Iter2(ia), Sent2(ia)).end() == Iter1(ia)); CHECK(ranges::search(Iter1(ia), Sent1(ia+sa), Iter2(ia), Sent2(ia+1)).begin() == Iter1(ia)); CHECK(ranges::search(Iter1(ia), Sent1(ia+sa), Iter2(ia), Sent2(ia+1)).end() == Iter1(ia+1)); CHECK(ranges::search(Iter1(ia), Sent1(ia+sa), Iter2(ia+1), Sent2(ia+2)).begin() == Iter1(ia+1)); CHECK(ranges::search(Iter1(ia), Sent1(ia+sa), Iter2(ia+1), Sent2(ia+2)).end() == Iter1(ia+2)); CHECK(ranges::search(Iter1(ia), Sent1(ia+sa), Iter2(ia+2), Sent2(ia+2)).begin() == Iter1(ia)); CHECK(ranges::search(Iter1(ia), Sent1(ia+sa), Iter2(ia+2), Sent2(ia+2)).end() == Iter1(ia)); CHECK(ranges::search(Iter1(ia), Sent1(ia+sa), Iter2(ia+2), Sent2(ia+3)).begin() == Iter1(ia+2)); CHECK(ranges::search(Iter1(ia), Sent1(ia+sa), Iter2(ia+2), Sent2(ia+3)).end() == Iter1(ia+3)); CHECK(ranges::search(Iter1(ia), Sent1(ia+sa), Iter2(ia+2), Sent2(ia+3)).begin() == Iter1(ia+2)); CHECK(ranges::search(Iter1(ia), Sent1(ia+sa), Iter2(ia+2), Sent2(ia+3)).end() == Iter1(ia+3)); CHECK(ranges::search(Iter1(ia), Sent1(ia), Iter2(ia+2), Sent2(ia+3)).begin() == Iter1(ia)); CHECK(ranges::search(Iter1(ia), Sent1(ia), Iter2(ia+2), Sent2(ia+3)).end() == Iter1(ia)); CHECK(ranges::search(Iter1(ia), Sent1(ia+sa), Iter2(ia+sa-1), Sent2(ia+sa)).begin() == Iter1(ia+sa-1)); CHECK(ranges::search(Iter1(ia), Sent1(ia+sa), Iter2(ia+sa-1), Sent2(ia+sa)).end() == Iter1(ia+sa)); CHECK(ranges::search(Iter1(ia), Sent1(ia+sa), Iter2(ia+sa-3), Sent2(ia+sa)).begin() == Iter1(ia+sa-3)); CHECK(ranges::search(Iter1(ia), Sent1(ia+sa), Iter2(ia+sa-3), Sent2(ia+sa)).end() == Iter1(ia+sa)); CHECK(ranges::search(Iter1(ia), Sent1(ia+sa), Iter2(ia), Sent2(ia+sa)).begin() == Iter1(ia)); CHECK(ranges::search(Iter1(ia), Sent1(ia+sa), Iter2(ia), Sent2(ia+sa)).end() == Iter1(ia+sa)); CHECK(ranges::search(Iter1(ia), Sent1(ia+sa-1), Iter2(ia), Sent2(ia+sa)).begin() == Iter1(ia+sa-1)); CHECK(ranges::search(Iter1(ia), Sent1(ia+sa-1), Iter2(ia), Sent2(ia+sa)).end() == Iter1(ia+sa-1)); CHECK(ranges::search(Iter1(ia), Sent1(ia+1), Iter2(ia), Sent2(ia+sa)).begin() == Iter1(ia+1)); CHECK(ranges::search(Iter1(ia), Sent1(ia+1), Iter2(ia), Sent2(ia+sa)).end() == Iter1(ia+1)); int ib[] = {0, 1, 2, 0, 1, 2, 3, 0, 1, 2, 3, 4}; const unsigned sb = sizeof(ib)/sizeof(ib[0]); int ic[] = {1}; CHECK(ranges::search(Iter1(ib), Sent1(ib+sb), Iter2(ic), Sent2(ic+1)).begin() == Iter1(ib+1)); CHECK(ranges::search(Iter1(ib), Sent1(ib+sb), Iter2(ic), Sent2(ic+1)).end() == Iter1(ib+2)); int id[] = {1, 2}; CHECK(ranges::search(Iter1(ib), Sent1(ib+sb), Iter2(id), Sent2(id+2)).begin() == Iter1(ib+1)); CHECK(ranges::search(Iter1(ib), Sent1(ib+sb), Iter2(id), Sent2(id+2)).end() == Iter1(ib+3)); int ie[] = {1, 2, 3}; CHECK(ranges::search(Iter1(ib), Sent1(ib+sb), Iter2(ie), Sent2(ie+3)).begin() == Iter1(ib+4)); CHECK(ranges::search(Iter1(ib), Sent1(ib+sb), Iter2(ie), Sent2(ie+3)).end() == Iter1(ib+7)); int ig[] = {1, 2, 3, 4}; CHECK(ranges::search(Iter1(ib), Sent1(ib+sb), Iter2(ig), Sent2(ig+4)).begin() == Iter1(ib+8)); CHECK(ranges::search(Iter1(ib), Sent1(ib+sb), Iter2(ig), Sent2(ig+4)).end() == Iter1(ib+12)); int ih[] = {0, 1, 1, 1, 1, 2, 3, 0, 1, 2, 3, 4}; const unsigned sh = sizeof(ih)/sizeof(ih[0]); int ii[] = {1, 1, 2}; CHECK(ranges::search(Iter1(ih), Sent1(ih+sh), Iter2(ii), Sent2(ii+3)).begin() == Iter1(ih+3)); CHECK(ranges::search(Iter1(ih), Sent1(ih+sh), Iter2(ii), Sent2(ii+3)).end() == Iter1(ih+6)); int ij[] = {0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0}; const unsigned sj = sizeof(ij)/sizeof(ij[0]); int ik[] = {0, 0, 0, 0, 1, 1, 1, 1, 0, 0}; const unsigned sk = sizeof(ik)/sizeof(ik[0]); CHECK(ranges::search(Iter1(ij), Sent1(ij+sj), Iter2(ik), Sent2(ik+sk)).begin() == Iter1(ij+6)); CHECK(ranges::search(Iter1(ij), Sent1(ij+sj), Iter2(ik), Sent2(ik+sk)).end() == Iter1(ij+6+sk)); } template<class Iter1, class Iter2> void test_iter() { using Sent1 = typename sentinel_type<Iter1>::type; using Sent2 = typename sentinel_type<Iter2>::type; test_iter_impl<Iter1, Iter2>(); test_iter_impl<Iter1, Iter2, Sent1>(); test_iter_impl<Iter1, Iter2, Iter1, Sent2>(); test_iter_impl<Iter1, Iter2, Sent1, Sent2>(); using SizedSent1 = typename sentinel_type<Iter1, true>::type; using SizedSent2 = typename sentinel_type<Iter2, true>::type; test_iter_impl<Iter1, Iter2, SizedSent1, SizedSent2>(); } template<class Iter1, class Iter2, typename Sent1 = Iter1, typename Sent2 = Iter2> void test_range_impl() { int ia[] = {0, 1, 2, 3, 4, 5}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); CHECK(ranges::search(ranges::make_subrange(Iter1(ia), Sent1(ia+sa)), ranges::make_subrange(Iter2(ia), Sent2(ia))).begin() == Iter1(ia)); CHECK(ranges::search(ranges::make_subrange(Iter1(ia), Sent1(ia+sa)), ranges::make_subrange(Iter2(ia), Sent2(ia+1))).begin() == Iter1(ia)); CHECK(ranges::search(ranges::make_subrange(Iter1(ia), Sent1(ia+sa)), ranges::make_subrange(Iter2(ia+1), Sent2(ia+2))).begin() == Iter1(ia+1)); CHECK(ranges::search(ranges::make_subrange(Iter1(ia), Sent1(ia+sa)), ranges::make_subrange(Iter2(ia+2), Sent2(ia+2))).begin() == Iter1(ia)); CHECK(ranges::search(ranges::make_subrange(Iter1(ia), Sent1(ia+sa)), ranges::make_subrange(Iter2(ia+2), Sent2(ia+3))).begin() == Iter1(ia+2)); CHECK(ranges::search(ranges::make_subrange(Iter1(ia), Sent1(ia+sa)), ranges::make_subrange(Iter2(ia+2), Sent2(ia+3))).begin() == Iter1(ia+2)); CHECK(ranges::search(ranges::make_subrange(Iter1(ia), Sent1(ia)), ranges::make_subrange(Iter2(ia+2), Sent2(ia+3))).begin() == Iter1(ia)); CHECK(ranges::search(ranges::make_subrange(Iter1(ia), Sent1(ia+sa)), ranges::make_subrange(Iter2(ia+sa-1), Sent2(ia+sa))).begin() == Iter1(ia+sa-1)); CHECK(ranges::search(ranges::make_subrange(Iter1(ia), Sent1(ia+sa)), ranges::make_subrange(Iter2(ia+sa-3), Sent2(ia+sa))).begin() == Iter1(ia+sa-3)); CHECK(ranges::search(ranges::make_subrange(Iter1(ia), Sent1(ia+sa)), ranges::make_subrange(Iter2(ia), Sent2(ia+sa))).begin() == Iter1(ia)); CHECK(ranges::search(ranges::make_subrange(Iter1(ia), Sent1(ia+sa-1)), ranges::make_subrange(Iter2(ia), Sent2(ia+sa))).begin() == Iter1(ia+sa-1)); CHECK(ranges::search(ranges::make_subrange(Iter1(ia), Sent1(ia+1)), ranges::make_subrange(Iter2(ia), Sent2(ia+sa))).begin() == Iter1(ia+1)); int ib[] = {0, 1, 2, 0, 1, 2, 3, 0, 1, 2, 3, 4}; const unsigned sb = sizeof(ib)/sizeof(ib[0]); int ic[] = {1}; CHECK(ranges::search(ranges::make_subrange(Iter1(ib), Sent1(ib+sb)), ranges::make_subrange(Iter2(ic), Sent2(ic+1))).begin() == Iter1(ib+1)); int id[] = {1, 2}; CHECK(ranges::search(ranges::make_subrange(Iter1(ib), Sent1(ib+sb)), ranges::make_subrange(Iter2(id), Sent2(id+2))).begin() == Iter1(ib+1)); int ie[] = {1, 2, 3}; CHECK(ranges::search(ranges::make_subrange(Iter1(ib), Sent1(ib+sb)), ranges::make_subrange(Iter2(ie), Sent2(ie+3))).begin() == Iter1(ib+4)); int ig[] = {1, 2, 3, 4}; CHECK(ranges::search(ranges::make_subrange(Iter1(ib), Sent1(ib+sb)), ranges::make_subrange(Iter2(ig), Sent2(ig+4))).begin() == Iter1(ib+8)); int ih[] = {0, 1, 1, 1, 1, 2, 3, 0, 1, 2, 3, 4}; const unsigned sh = sizeof(ih)/sizeof(ih[0]); int ii[] = {1, 1, 2}; CHECK(ranges::search(ranges::make_subrange(Iter1(ih), Sent1(ih+sh)), ranges::make_subrange(Iter2(ii), Sent2(ii+3))).begin() == Iter1(ih+3)); int ij[] = {0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0}; const unsigned sj = sizeof(ij)/sizeof(ij[0]); int ik[] = {0, 0, 0, 0, 1, 1, 1, 1, 0, 0}; const unsigned sk = sizeof(ik)/sizeof(ik[0]); CHECK(ranges::search(ranges::make_subrange(Iter1(ij), Sent1(ij+sj)), ranges::make_subrange(Iter2(ik), Sent2(ik+sk))).begin() == Iter1(ij+6)); } template<class Iter1, class Iter2> void test_range() { using Sent1 = typename sentinel_type<Iter1>::type; using Sent2 = typename sentinel_type<Iter2>::type; test_range_impl<Iter1, Iter2>(); test_range_impl<Iter1, Iter2, Sent1>(); test_range_impl<Iter1, Iter2, Iter1, Sent2>(); test_range_impl<Iter1, Iter2, Sent1, Sent2>(); using SizedSent1 = typename sentinel_type<Iter1, true>::type; using SizedSent2 = typename sentinel_type<Iter2, true>::type; test_range_impl<Iter1, Iter2, SizedSent1, SizedSent2>(); } template<class Iter1, class Iter2> void test() { test_iter<Iter1, Iter2>(); test_range<Iter1, Iter2>(); } struct S { int i; }; struct T { int i; }; constexpr bool test_constexpr() { using namespace ranges; int ia[] = {0, 1, 2, 3, 4}; int ib[] = {2, 3}; int ic[] = {2, 4}; constexpr auto sa = size(ia); auto r = search(ia, ib, equal_to{}); STATIC_CHECK_RETURN(r.begin() == ia + 2); auto r2 = search(ia, ic, equal_to{}); STATIC_CHECK_RETURN(r2.begin() == ia + sa); 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}, {3}, {4}, {5}}; T const pat[] = {{2}, {3}}; S const *p = ranges::search(in, pat, std::equal_to<int>{}, &S::i, &T::i).begin(); CHECK(p == in+2); } // Test counted ranges { int in[] = {0,1,2,3,4,5}; auto rng = ranges::views::counted(BidirectionalIterator<int*>(in), 6); auto sub = ranges::search(rng, std::initializer_list<int>{2,3}); CHECK(base(sub.begin().base()) == in+2); CHECK(base(sub.end().base()) == in+4); CHECK(sub.begin().count() == 4); CHECK(sub.end().count() == 2); sub = ranges::search(rng, std::initializer_list<int>{5,6}); CHECK(base(sub.begin().base()) == in+6); CHECK(base(sub.end().base()) == in+6); CHECK(sub.begin().count() == 0); CHECK(sub.end().count() == 0); } // Test rvalue ranges { int ib[] = {0, 1, 2, 0, 1, 2, 3, 0, 1, 2, 3, 4}; int ie[] = {1, 2, 3}; CHECK(ranges::search(ranges::views::all(ib), ie).begin() == ib+4); } #ifndef RANGES_WORKAROUND_MSVC_573728 { int ib[] = {0, 1, 2, 0, 1, 2, 3, 0, 1, 2, 3, 4}; int ie[] = {1, 2, 3}; CHECK(::is_dangling(ranges::search(std::move(ib), ie))); } #endif { std::vector<int> ib{0, 1, 2, 0, 1, 2, 3, 0, 1, 2, 3, 4}; int ie[] = {1, 2, 3}; CHECK(::is_dangling(ranges::search(std::move(ib), ie))); } { STATIC_CHECK(test_constexpr()); } return ::test_result(); }
0
repos/range-v3
repos/range-v3/cmake/TestHeaders.cmake
# Copyright Louis Dionne 2013-2017 # Distributed under the Boost Software License, Version 1.0. # (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) # # # This CMake module provides a function generating a unit test to make sure # that every public header can be included on its own. # # When a C++ library or application has many header files, it can happen that # a header does not include all the other headers it depends on. When this is # the case, it can happen that including that header file on its own will # break the compilation. This CMake module generates a dummy executable # comprised of many .cpp files, each of which includes a header file that # is part of the public API. In other words, the executable is comprised # of .cpp files of the form: # # #include <the/public/header.hpp> # # and then exactly one `main` function. If this succeeds to compile, it means # that the header can be included on its own, which is what clients expect. # Otherwise, you have a problem. Since writing these dumb unit tests by hand # is tedious and repetitive, you can use this CMake module to automate this # task. # add_header_test(<target> [EXCLUDE_FROM_ALL] [EXCLUDE excludes...] HEADERS headers...) # # Generates header-inclusion unit tests for all the specified headers. # # This function creates a target which builds a dummy executable including # each specified header file individually. If this target builds successfully, # it means that all the specified header files can be included individually. # # Parameters # ---------- # <target>: # The name of the target to generate. # # HEADERS headers: # A list of header files to generate the inclusion tests for. All headers # in this list must be represented as relative paths from the root of the # include directory added to the compiler's header search path. In other # words, it should be possible to include all headers in this list as # # #include <${header}> # # For example, for a library with the following structure: # # project/ # doc/ # test/ # ... # include/ # boost/ # hana.hpp # hana/ # transform.hpp # tuple.hpp # pair.hpp # ... # # When building the unit tests for that library, we'll add `-I project/include' # to the compiler's arguments. The list of public headers should therefore contain # # boost/hana.hpp # boost/hana/transform.hpp # boost/hana/tuple.hpp # boost/hana/pair.hpp # ... # # Usually, all the 'public' header files of a library should be tested for # standalone inclusion. A header is considered 'public' if a client should # be able to include that header on its own. # # [EXCLUDE excludes]: # An optional list of headers or regexes for which no unit test should be # generated. Basically, any header in the list specified by the `HEADERS` # argument that matches anything in `EXCLUDE` will be skipped. # # [EXCLUDE_FROM_ALL]: # If provided, the generated target is excluded from the 'all' target. # function(add_header_test target) cmake_parse_arguments(ARGS "EXCLUDE_FROM_ALL" # options "" # 1 value args "HEADERS;EXCLUDE" # multivalued args ${ARGN}) if (NOT ARGS_HEADERS) message(FATAL_ERROR "The `HEADERS` argument must be provided.") endif() if (ARGS_EXCLUDE_FROM_ALL) set(ARGS_EXCLUDE_FROM_ALL "EXCLUDE_FROM_ALL") else() set(ARGS_EXCLUDE_FROM_ALL "") endif() foreach(header ${ARGS_HEADERS}) set(skip FALSE) foreach(exclude ${ARGS_EXCLUDE}) if (${header} MATCHES ${exclude}) set(skip TRUE) break() endif() endforeach() if (skip) continue() endif() get_filename_component(filename "${header}" NAME_WE) get_filename_component(directory "${header}" DIRECTORY) set(source "${CMAKE_CURRENT_BINARY_DIR}/headers/${directory}/${filename}.cpp") if (NOT EXISTS "${source}") file(WRITE "${source}" "#include <${header}>") endif() list(APPEND sources "${source}") endforeach() set(standalone_main "${CMAKE_CURRENT_BINARY_DIR}/headers/_standalone_main.cpp") if (NOT EXISTS "${standalone_main}") file(WRITE "${standalone_main}" "int main() { }") endif() add_executable(${target} ${ARGS_EXCLUDE_FROM_ALL} ${sources} "${CMAKE_CURRENT_BINARY_DIR}/headers/_standalone_main.cpp" ) endfunction()
0
repos/range-v3
repos/range-v3/cmake/range-v3-config.cmake
if (TARGET range-v3::meta) return() endif() include("${CMAKE_CURRENT_LIST_DIR}/range-v3-targets.cmake") add_library(range-v3::meta INTERFACE IMPORTED) add_library(range-v3::concepts INTERFACE IMPORTED) add_library(range-v3::range-v3 INTERFACE IMPORTED) # workaround for target_link_libraries on lower cmake versions (< 3.11) # see https://cmake.org/cmake/help/latest/release/3.11.html#commands if(CMAKE_VERSION VERSION_LESS 3.11) set_target_properties(range-v3::meta PROPERTIES INTERFACE_LINK_LIBRARIES "range-v3-meta") set_target_properties(range-v3::concepts PROPERTIES INTERFACE_LINK_LIBRARIES "range-v3-concepts") set_target_properties(range-v3::range-v3 PROPERTIES INTERFACE_LINK_LIBRARIES "range-v3") else() target_link_libraries(range-v3::meta INTERFACE range-v3-meta) target_link_libraries(range-v3::concepts INTERFACE range-v3-concepts) target_link_libraries(range-v3::range-v3 INTERFACE range-v3) endif()
0
repos/range-v3
repos/range-v3/cmake/ranges_env.cmake
# Copyright Gonzalo Brito Gadeschi 2015 # Distributed under the Boost Software License, Version 1.0. # (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) # # Detects the C++ compiler, system, build-type, etc. include(CheckCXXCompilerFlag) if("x${CMAKE_CXX_COMPILER_ID}" MATCHES "x.*Clang") if("x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC") set (RANGES_CXX_COMPILER_CLANGCL TRUE) if (RANGES_VERBOSE_BUILD) message(STATUS "[range-v3]: compiler is clang-cl.") endif() else() set (RANGES_CXX_COMPILER_CLANG TRUE) if (RANGES_VERBOSE_BUILD) message(STATUS "[range-v3]: compiler is clang.") endif() endif() elseif(CMAKE_COMPILER_IS_GNUCXX) set (RANGES_CXX_COMPILER_GCC TRUE) if (RANGES_VERBOSE_BUILD) message(STATUS "[range-v3]: compiler is gcc.") endif() elseif("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC") set (RANGES_CXX_COMPILER_MSVC TRUE) if (RANGES_VERBOSE_BUILD) message(STATUS "[range-v3]: compiler is msvc.") endif() else() message(WARNING "[range-v3 warning]: unknown compiler ${CMAKE_CXX_COMPILER_ID} !") endif() if(CMAKE_SYSTEM_NAME MATCHES "Darwin") set (RANGES_ENV_MACOSX TRUE) if (RANGES_VERBOSE_BUILD) message(STATUS "[range-v3]: system is MacOSX.") endif() elseif(CMAKE_SYSTEM_NAME MATCHES "Linux") set (RANGES_ENV_LINUX TRUE) if (RANGES_VERBOSE_BUILD) message(STATUS "[range-v3]: system is Linux.") endif() elseif(CMAKE_SYSTEM_NAME MATCHES "Windows") set (RANGES_ENV_WINDOWS TRUE) if (RANGES_VERBOSE_BUILD) message(STATUS "[range-v3]: system is Windows.") endif() elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") set (RANGES_ENV_FREEBSD TRUE) if (RANGES_VERBOSE_BUILD) message(STATUS "[range-v3]: system is FreeBSD.") endif() elseif(CMAKE_SYSTEM_NAME MATCHES "OpenBSD") set (RANGES_ENV_OPENBSD TRUE) if (RANGES_VERBOSE_BUILD) message(STATUS "[range-v3]: system is OpenBSD.") endif() elseif(CMAKE_SYSTEM_NAME MATCHES "Emscripten") set (RANGES_ENV_EMSCRIPTEN TRUE) if (RANGES_VERBOSE_BUILD) message(STATUS "[range-v3]: system is Emscripten.") endif() else() message(WARNING "[range-v3 warning]: unknown system ${CMAKE_SYSTEM_NAME} !") endif() if(RANGES_CXX_STD MATCHES "^[0-9]+$") if(RANGES_CXX_COMPILER_MSVC AND RANGES_CXX_STD LESS 17) # MSVC is currently supported only in 17+ mode set(RANGES_CXX_STD 17) elseif(RANGES_CXX_STD LESS 14) set(RANGES_CXX_STD 14) endif() endif() # Build type set(RANGES_DEBUG_BUILD FALSE) set(RANGES_RELEASE_BUILD FALSE) if (CMAKE_BUILD_TYPE MATCHES "^Debug$") set(RANGES_DEBUG_BUILD TRUE) if (RANGES_VERBOSE_BUILD) message(STATUS "[range-v3]: build type is debug.") endif() elseif(CMAKE_BUILD_TYPE MATCHES "^(Release|RelWithDebInfo|MinSizeRel)$") set(RANGES_RELEASE_BUILD TRUE) if (RANGES_VERBOSE_BUILD) message(STATUS "[range-v3]: build type is release.") endif() else() message(WARNING "[range-v3 warning]: unknown build type, defaults to release!") set(CMAKE_BUILD_TYPE "Release") set(RANGES_RELEASE_BUILD TRUE) endif() if(RANGE_V3_DOCS) find_package(Doxygen) endif() find_package(Git)
0
repos/range-v3
repos/range-v3/cmake/GoogleTest.cmake.in
# Copyright Eric Niebler 2019 # Distributed under the Boost Software License, Version 1.0. # (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) cmake_minimum_required(VERSION 2.8.2) project(google-test-download NONE) include(ExternalProject) ExternalProject_Add(google-test GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG master SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/google-test-src" BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/google-test-build" CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" TEST_COMMAND "" )
0
repos/range-v3
repos/range-v3/cmake/aligned_new_probe.cpp
#include <new> int main() { struct alignas(__STDCPP_DEFAULT_NEW_ALIGNMENT__ * 4) S {}; (void) ::operator new(sizeof(S), static_cast<std::align_val_t>(alignof(S))); }
0
repos/range-v3
repos/range-v3/cmake/gtest.cmake
# Copyright 2019 Eric Niebler # Distributed under the Boost Software License, Version 1.0. # (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) # Download and unpack googletest at configure time configure_file(cmake/GoogleTest.cmake.in google-test-download/CMakeLists.txt) execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . RESULT_VARIABLE result WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/google-test-download ) if(result) message(FATAL_ERROR "CMake step for google-test failed: ${result}") endif() execute_process(COMMAND ${CMAKE_COMMAND} --build . RESULT_VARIABLE result WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/google-test-download ) if(result) message(FATAL_ERROR "Build step for google-test failed: ${result}") endif() # Prevent overriding the parent project's compiler/linker # settings on Windows set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) # Add google-test directly to our build. This defines # the gtest and gtest_main targets. add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/google-test-src ${CMAKE_CURRENT_BINARY_DIR}/google-test-build EXCLUDE_FROM_ALL)
0
repos/range-v3
repos/range-v3/cmake/ranges_options.cmake
# Copyright Gonzalo Brito Gadeschi 2015 # Distributed under the Boost Software License, Version 1.0. # (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) # # CMake options include(CMakeDependentOption) set(RANGES_CXX_STD default CACHE STRING "C++ standard version.") option(RANGES_BUILD_CALENDAR_EXAMPLE "Builds the calendar example." ON) option(RANGES_ASAN "Run the tests using AddressSanitizer." OFF) option(RANGES_MSAN "Run the tests using MemorySanitizer." OFF) option(RANGES_ASSERTIONS "Enable assertions." ON) option(RANGES_DEBUG_INFO "Include debug information in the binaries." ON) option(RANGES_MODULES "Enables use of Clang modules (experimental)." OFF) option(RANGES_NATIVE "Enables -march/-mtune=native." ON) option(RANGES_VERBOSE_BUILD "Enables debug output from CMake." OFF) option(RANGES_LLVM_POLLY "Enables LLVM Polly." OFF) option(RANGES_ENABLE_WERROR "Enables -Werror. Only effective if compiler is not clang-cl or MSVC. ON by default" ON) option(RANGES_PREFER_REAL_CONCEPTS "Use real concepts instead of emulation if the compiler supports it" ON) option(RANGES_DEEP_STL_INTEGRATION "Hijacks the primary std::iterator_traits template to emulate the C++20 std::ranges:: behavior." OFF) option(RANGE_V3_HEADER_CHECKS "Build the Range-v3 header checks and integrate with ctest" OFF) set(RANGES_INLINE_THRESHOLD -1 CACHE STRING "Force a specific inlining threshold.") # Enable verbose configure when passing -Wdev to CMake if (DEFINED CMAKE_SUPPRESS_DEVELOPER_WARNINGS AND NOT CMAKE_SUPPRESS_DEVELOPER_WARNINGS) set(RANGES_VERBOSE_BUILD ON) endif() if (RANGES_VERBOSE_BUILD) message(STATUS "[range-v3]: verbose build enabled.") endif() CMAKE_DEPENDENT_OPTION(RANGE_V3_INSTALL "Generate an install target for Range-v3" ON "${is_standalone}" OFF) CMAKE_DEPENDENT_OPTION(RANGE_V3_TESTS "Build the Range-v3 tests and integrate with ctest" ON "${is_standalone}" OFF) CMAKE_DEPENDENT_OPTION(RANGE_V3_EXAMPLES "Build the Range-v3 examples and integrate with ctest" ON "${is_standalone}" OFF) option(RANGE_V3_PERF "Build the Range-v3 performance benchmarks" OFF) CMAKE_DEPENDENT_OPTION(RANGE_V3_DOCS "Build the Range-v3 documentation" ON "${is_standalone}" OFF) mark_as_advanced(RANGE_V3_PERF)
0
repos/range-v3
repos/range-v3/cmake/gbenchmark.cmake
# Download and unpack googletest at configure time configure_file( cmake/GoogleBenchmark.cmake.in google-benchmark-download/CMakeLists.txt) execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . RESULT_VARIABLE result WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/google-benchmark-download) if(result) message(FATAL_ERROR "CMake step for google-benchmark failed: ${result}") endif() execute_process(COMMAND ${CMAKE_COMMAND} --build . RESULT_VARIABLE result WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/google-benchmark-download) if(result) message(FATAL_ERROR "Build step for google-benchmark failed: ${result}") endif() # Add google-benchmark directly to our build. This defines # the benchmark and benchmark_main targets. add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/google-benchmark-src ${CMAKE_CURRENT_BINARY_DIR}/google-benchmark-build EXCLUDE_FROM_ALL)
0
repos/range-v3
repos/range-v3/cmake/concepts_test_code.cpp
#if !defined(__cpp_concepts) || __cpp_concepts == 0 #error "Sorry, Charlie. No concepts" #else #if __cpp_concepts <= 201507L #define concept concept bool #endif template<class> concept True = true; template<class T> constexpr bool test(T) { return false; } template<class T> requires True<T> constexpr bool test(T) { return true; } int main() { static_assert(::test(42), ""); } #endif
0
repos/range-v3
repos/range-v3/cmake/GoogleBenchmark.cmake.in
# Copyright Eric Niebler 2019 # Distributed under the Boost Software License, Version 1.0. # (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) cmake_minimum_required(VERSION 2.8.2) project(google-benchmark-download NONE) include(ExternalProject) ExternalProject_Add(google-benchmark GIT_REPOSITORY https://github.com/google/benchmark.git GIT_TAG master SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/google-benchmark-src" BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/google-benchmark-build" CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" TEST_COMMAND "" )
0
repos/range-v3
repos/range-v3/cmake/coro_test_code.cpp
#if defined(__cpp_coroutines) && defined(__has_include) #if __has_include(<coroutine>) #include <coroutine> namespace std_coro = std; #elif __has_include(<experimental/coroutine>) #include <experimental/coroutine> namespace std_coro = std::experimental; #else #error Either the compiler or the library lacks support for coroutines #endif #else #error Either the compiler or the library lacks support for coroutines #endif struct present { struct promise_type { int result; present get_return_object() { return {*this}; } std_coro::suspend_never initial_suspend() { return {}; } std_coro::suspend_never final_suspend() noexcept { return {}; } void return_value(int i) { result = i; } void unhandled_exception() {} }; promise_type& promise; bool await_ready() const { return true; } void await_suspend(std_coro::coroutine_handle<>) const {} int await_resume() const { return promise.result; } }; present f(int n) { if (n < 2) co_return 1; else co_return n * co_await f(n - 1); } int main() { return f(5).promise.result != 120; }
0
repos/range-v3
repos/range-v3/cmake/ranges_diagnostics.cmake
# Copyright Louis Dionne 2015 # Copyright Gonzalo Brito Gadeschi 2015 # Distributed under the Boost Software License, Version 1.0. # (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) # # Setup compiler flags (more can be set on a per-target basis or in # subdirectories) # Enable all warnings: ranges_append_flag(RANGES_HAS_WEVERYTHING -Weverything) ranges_append_flag(RANGES_HAS_PEDANTIC -pedantic) ranges_append_flag(RANGES_HAS_PEDANTIC_ERRORS -pedantic-errors) # Selectively disable those warnings that are not worth it: ranges_append_flag(RANGES_HAS_WNO_CXX98_COMPAT -Wno-c++98-compat) ranges_append_flag(RANGES_HAS_WNO_CXX98_COMPAT_PEDANTIC -Wno-c++98-compat-pedantic) ranges_append_flag(RANGES_HAS_WNO_WEAK_VTABLES -Wno-weak-vtables) ranges_append_flag(RANGES_HAS_WNO_PADDED -Wno-padded) ranges_append_flag(RANGES_HAS_WNO_MISSING_VARIABLE_DECLARATIONS -Wno-missing-variable-declarations) ranges_append_flag(RANGES_HAS_WNO_DOCUMENTATION -Wno-documentation) ranges_append_flag(RANGES_HAS_WNO_DOCUMENTATION_UNKNOWN_COMMAND -Wno-documentation-unknown-command) ranges_append_flag(RANGES_HAS_WNO_OLD_STYLE_CAST -Wno-old-style-cast) if (RANGES_ENV_MACOSX) ranges_append_flag(RANGES_HAS_WNO_GLOBAL_CONSTRUCTORS -Wno-global-constructors) ranges_append_flag(RANGES_HAS_WNO_EXIT_TIME_DESTRUCTORS -Wno-exit-time-destructors) endif() if (RANGES_CXX_COMPILER_CLANG OR RANGES_CXX_COMPILER_CLANGCL) ranges_append_flag(RANGES_HAS_WNO_MISSING_PROTOTYPES -Wno-missing-prototypes) endif() if (RANGES_CXX_COMPILER_GCC) if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.0") ranges_append_flag(RANGES_HAS_WNO_STRICT_OVERFLOW -Wno-strict-overflow) if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.0") ranges_append_flag(RANGES_HAS_WNO_MISSING_FIELD_INITIALIZERS -Wno-missing-field-initializers) endif() elseif ((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "7.0") OR (CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL "7.0")) ranges_append_flag(RANGES_HAS_WNO_NOEXCEPT_TYPE -Wno-noexcept-type) endif() endif() if (RANGES_VERBOSE_BUILD) message(STATUS "[range-v3]: test C++ flags: ${CMAKE_CXX_FLAGS}") endif()
0
repos/range-v3
repos/range-v3/cmake/readme.md
# CMake files overview: - `ranges_options.cmake`: All options to configure the library. - `ranges_env.cmake`: Detects the environment: operating system, compiler, build-type, ... - `ranges_flags.cmake`: Sets up all compiler flags.
0
repos/range-v3
repos/range-v3/cmake/ranges_flags.cmake
# Copyright Louis Dionne 2015 # Copyright Gonzalo Brito Gadeschi 2015 # Distributed under the Boost Software License, Version 1.0. # (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) # # Setup compiler flags (more can be set on a per-target basis or in # subdirectories) # Compilation flags include(CheckCXXCompilerFlag) macro(ranges_append_flag testname flag) # As -Wno-* flags do not lead to build failure when there are no other # diagnostics, we check positive option to determine their applicability. # Of course, we set the original flag that is requested in the parameters. string(REGEX REPLACE "^-Wno-" "-W" alt ${flag}) check_cxx_compiler_flag(${alt} ${testname}) if (${testname}) add_compile_options(${flag}) endif() endmacro() function(cxx_standard_normalize cxx_standard return_value) if("x${cxx_standard}" STREQUAL "x1y") set( ${return_value} "14" PARENT_SCOPE ) elseif("x${cxx_standard}" STREQUAL "x1z") set( ${return_value} "17" PARENT_SCOPE ) elseif("x${cxx_standard}" STREQUAL "xlatest" OR "x${cxx_standard}" STREQUAL "x2a") set( ${return_value} "20" PARENT_SCOPE ) else() set( ${return_value} "${cxx_standard}" PARENT_SCOPE ) endif() endfunction() function(cxx_standard_denormalize cxx_standard return_value) if("x${cxx_standard}" STREQUAL "x17") if (RANGES_CXX_COMPILER_CLANGCL OR RANGES_CXX_COMPILER_MSVC) set( ${return_value} 17 PARENT_SCOPE ) else() set( ${return_value} 1z PARENT_SCOPE ) endif() elseif("x${cxx_standard}" STREQUAL "x20") if (RANGES_CXX_COMPILER_CLANGCL OR RANGES_CXX_COMPILER_MSVC) set( ${return_value} latest PARENT_SCOPE ) else() set( ${return_value} 2a PARENT_SCOPE ) endif() else() set( ${return_value} ${cxx_standard} PARENT_SCOPE ) endif() endfunction() if(CMAKE_CXX_STANDARD) if(NOT "x${RANGES_CXX_STD}" STREQUAL "xdefault") # Normalize RANGES_CXX_STD cxx_standard_normalize( ${RANGES_CXX_STD} ranges_cxx_std ) if(NOT "x${ranges_cxx_std}" STREQUAL "x${CMAKE_CXX_STANDARD}") message(FATAL_ERROR "[range-v3]: Cannot specify both CMAKE_CXX_STANDARD and RANGES_CXX_STD, or they must match.") endif() else() cxx_standard_denormalize(${CMAKE_CXX_STANDARD} RANGES_CXX_STD) endif() elseif("x${RANGES_CXX_STD}" STREQUAL "xdefault") if (RANGES_CXX_COMPILER_CLANGCL OR RANGES_CXX_COMPILER_MSVC) set(RANGES_CXX_STD 17) else() set(RANGES_CXX_STD 14) endif() endif() # All compilation flags # Language flag: version of the C++ standard to use message(STATUS "[range-v3]: C++ std=${RANGES_CXX_STD}") if (RANGES_CXX_COMPILER_CLANGCL OR RANGES_CXX_COMPILER_MSVC) ranges_append_flag(RANGES_HAS_CXXSTDCOLON "/std:c++${RANGES_CXX_STD}") set(RANGES_STD_FLAG "/std:c++${RANGES_CXX_STD}") if (RANGES_CXX_COMPILER_CLANGCL) # The MSVC STL before VS 2019v16.6 with Clang 10 requires -fms-compatibility in C++17 mode, and # doesn't support C++20 mode at all. Let's drop this flag until AppVeyor updates to VS2016v16.6. # ranges_append_flag(RANGES_HAS_FNO_MS_COMPATIBIILITY "-fno-ms-compatibility") ranges_append_flag(RANGES_HAS_FNO_DELAYED_TEMPLATE_PARSING "-fno-delayed-template-parsing") endif() # Enable "normal" warnings and make them errors: ranges_append_flag(RANGES_HAS_W3 /W3) ranges_append_flag(RANGES_HAS_WX /WX) else() ranges_append_flag(RANGES_HAS_CXXSTD "-std=c++${RANGES_CXX_STD}") set(RANGES_STD_FLAG "-std=c++${RANGES_CXX_STD}") # Enable "normal" warnings and make them errors: ranges_append_flag(RANGES_HAS_WALL -Wall) ranges_append_flag(RANGES_HAS_WEXTRA -Wextra) if (RANGES_ENABLE_WERROR) ranges_append_flag(RANGES_HAS_WERROR -Werror) endif() endif() if (RANGES_ENV_LINUX AND RANGES_CXX_COMPILER_CLANG) # On linux libc++ re-exports the system math headers. The ones from libstdc++ # use the GCC __extern_always_inline intrinsic which is not supported by clang # versions 3.6, 3.7, 3.8, 3.9, 4.0, and current trunk 5.0 (as of 2017.04.13). # # This works around it by replacing __extern_always_inline with inline using a # macro: ranges_append_flag(RANGES_HAS_D__EXTERN_ALWAYS_INLINE -D__extern_always_inline=inline) endif() # Deep integration support if (RANGES_DEEP_STL_INTEGRATION) if (RANGES_CXX_COMPILER_MSVC) add_compile_options(/I "${PROJECT_SOURCE_DIR}/include/std") add_compile_options(/I "${PROJECT_SOURCE_DIR}/include") else() add_compile_options(-isystem "${PROJECT_SOURCE_DIR}/include/std") add_compile_options(-I "${PROJECT_SOURCE_DIR}/include") endif() add_compile_options(-DRANGES_DEEP_STL_INTEGRATION=1) endif() # Template diagnostic flags ranges_append_flag(RANGES_HAS_FDIAGNOSTIC_SHOW_TEMPLATE_TREE -fdiagnostics-show-template-tree) ranges_append_flag(RANGES_HAS_FTEMPLATE_BACKTRACE_LIMIT "-ftemplate-backtrace-limit=0") ranges_append_flag(RANGES_HAS_FMACRO_BACKTRACE_LIMIT "-fmacro-backtrace-limit=1") # Clang modules support if (RANGES_MODULES) ranges_append_flag(RANGES_HAS_MODULES -fmodules) ranges_append_flag(RANGES_HAS_MODULE_MAP_FILE "-fmodule-map-file=${PROJECT_SOURCE_DIR}/include/module.modulemap") ranges_append_flag(RANGES_HAS_MODULE_CACHE_PATH "-fmodules-cache-path=${PROJECT_BINARY_DIR}/module.cache") if (RANGES_LIBCXX_MODULE) ranges_append_flag(RANGES_HAS_LIBCXX_MODULE_MAP_FILE "-fmodule-map-file=${RANGES_LIBCXX_MODULE}") endif() if (RANGES_ENV_MACOSX) ranges_append_flag(RANGES_HAS_NO_IMPLICIT_MODULE_MAPS -fno-implicit-module-maps) endif() if (RANGES_DEBUG_BUILD) ranges_append_flag(RANGES_HAS_GMODULES -gmodules) endif() endif() # Sanitizer support: detect incompatible sanitizer combinations if (RANGES_ASAN AND RANGES_MSAN) message(FATAL_ERROR "[range-v3 error]: AddressSanitizer and MemorySanitizer are both enabled at the same time!") endif() if (RANGES_MSAN AND RANGES_ENV_MACOSX) message(FATAL_ERROR "[range-v3 error]: MemorySanitizer is not supported on MacOSX!") endif() # AddressSanitizer support if (RANGES_ASAN) # This policy enables passing the linker flags to the linker when trying to # test the features, which is required to successfully link ASan binaries cmake_policy(SET CMP0056 NEW) set (ASAN_FLAGS "") if (RANGES_ENV_MACOSX) # LeakSanitizer not supported on MacOSX set (ASAN_FLAGS "-fsanitize=address,signed-integer-overflow,shift,integer-divide-by-zero,implicit-signed-integer-truncation,implicit-integer-sign-change,undefined,nullability") else() if (RANGES_CXX_COMPILER_CLANG AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.0") set (ASAN_FLAGS "-fsanitize=address") else() set (ASAN_FLAGS "-fsanitize=address,signed-integer-overflow,shift,integer-divide-by-zero,implicit-signed-integer-truncation,implicit-integer-sign-change,leak,nullability") endif() endif() ranges_append_flag(RANGES_HAS_ASAN "${ASAN_FLAGS}") if (RANGES_HAS_ASAN) #ASAN flags must be passed to the linker: set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${ASAN_FLAGS}") endif() ranges_append_flag(RANGES_HAS_SANITIZE_NO_RECOVER "-fno-sanitize-recover=all") ranges_append_flag(RANGES_HAS_NO_OMIT_FRAME_POINTER -fno-omit-frame-pointer) endif() # MemorySanitizer support if (RANGES_MSAN) # This policy enables passing the linker flags to the linker when trying to # compile the examples, which is required to successfully link MSan binaries cmake_policy(SET CMP0056 NEW) ranges_append_flag(RANGES_HAS_MSAN "-fsanitize=memory") ranges_append_flag(RANGES_HAS_MSAN_TRACK_ORIGINS -fsanitize-memory-track-origins) ranges_append_flag(RANGES_HAS_SANITIZE_RECOVER_ALL "-fno-sanitize-recover=all") ranges_append_flag(RANGES_HAS_NO_OMIT_FRAME_POINTER -fno-omit-frame-pointer) endif() # Build types: if (RANGES_DEBUG_BUILD AND RANGES_RELEASE_BUILD) message(FATAL_ERROR "[range-v3 error] Cannot simultaneously generate debug and release builds!") endif() if (RANGES_DEBUG_BUILD) ranges_append_flag(RANGES_HAS_NO_INLINE -fno-inline) ranges_append_flag(RANGES_HAS_STACK_PROTECTOR_ALL -fstack-protector-all) ranges_append_flag(RANGES_HAS_G3 -g3) # Clang can generate debug info tuned for LLDB or GDB if (RANGES_CXX_COMPILER_CLANG) if (RANGES_ENV_MACOSX) ranges_append_flag(RANGES_HAS_GLLDB -glldb) elseif(RANGES_ENV_LINUX OR RANGES_ENV_OPENBSD) ranges_append_flag(RANGES_HAS_GGDB -ggdb) endif() endif() endif() if (RANGES_RELEASE_BUILD) if (NOT RANGES_ASSERTIONS) ranges_append_flag(RANGES_HAS_DNDEBUG -DNDEBUG) endif() if (NOT RANGES_ASAN AND NOT RANGES_MSAN) # The quality of ASan and MSan error messages suffers if we disable the # frame pointer, so leave it enabled when compiling with either of them: ranges_append_flag(RANGES_HAS_OMIT_FRAME_POINTER -fomit-frame-pointer) endif() ranges_append_flag(RANGES_HAS_OFAST -Ofast) if (NOT RANGES_HAS_OFAST) ranges_append_flag(RANGES_HAS_O2 -O2) endif() ranges_append_flag(RANGES_HAS_STRICT_ALIASING -fstrict-aliasing) ranges_append_flag(RANGES_HAS_STRICT_VTABLE_POINTERS -fstrict-vtable-pointers) ranges_append_flag(RANGES_HAS_FAST_MATH -ffast-math) ranges_append_flag(RANGES_HAS_VECTORIZE -fvectorize) if (NOT RANGES_ENV_MACOSX) # Sized deallocation is not available in MacOSX: ranges_append_flag(RANGES_HAS_SIZED_DEALLOCATION -fsized-deallocation) endif() if (RANGES_LLVM_POLLY) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mllvm -polly -mllvm -polly-vectorizer=stripmine") endif() if (RANGES_CXX_COMPILER_CLANG AND (NOT (RANGES_INLINE_THRESHOLD EQUAL -1))) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mllvm -inline-threshold=${RANGES_INLINE_THRESHOLD}") endif() endif() if (RANGES_NATIVE) ranges_append_flag(RANGES_HAS_MARCH_NATIVE "-march=native") ranges_append_flag(RANGES_HAS_MTUNE_NATIVE "-mtune=native") endif() include(CheckCXXSourceCompiles) set(CMAKE_REQUIRED_FLAGS ${RANGES_STD_FLAG}) # Probe for library and compiler support for aligned new file(READ "${CMAKE_CURRENT_SOURCE_DIR}/cmake/aligned_new_probe.cpp" RANGE_V3_PROBE_CODE) check_cxx_source_compiles("${RANGE_V3_PROBE_CODE}" RANGE_V3_ALIGNED_NEW_PROBE) unset(RANGE_V3_PROBE_CODE) unset(CMAKE_REQUIRED_FLAGS) if (NOT RANGE_V3_ALIGNED_NEW_PROBE) add_compile_options("-DRANGES_CXX_ALIGNED_NEW=0") endif() # Probe for coroutine TS support file(READ "${CMAKE_CURRENT_SOURCE_DIR}/cmake/coro_test_code.cpp" RANGE_V3_PROBE_CODE) if(RANGES_CXX_COMPILER_MSVC) set(CMAKE_REQUIRED_FLAGS "/await") check_cxx_source_compiles("${RANGE_V3_PROBE_CODE}" RANGES_HAS_AWAIT) if(RANGES_HAS_AWAIT) set(RANGE_V3_COROUTINE_FLAGS "/await") endif() elseif(RANGES_CXX_COMPILER_CLANG) set(CMAKE_REQUIRED_FLAGS "-fcoroutines-ts ${RANGES_STD_FLAG}") check_cxx_source_compiles("${RANGE_V3_PROBE_CODE}" RANGES_HAS_FCOROUTINES_TS) if(RANGES_HAS_FCOROUTINES_TS) set(RANGE_V3_COROUTINE_FLAGS "-fcoroutines-ts") endif() endif() unset(CMAKE_REQUIRED_FLAGS) unset(RANGE_V3_PROBE_CODE) if (RANGE_V3_COROUTINE_FLAGS) add_compile_options(${RANGE_V3_COROUTINE_FLAGS}) endif() # Test for concepts support file(READ "${CMAKE_CURRENT_SOURCE_DIR}/cmake/concepts_test_code.cpp" RANGE_V3_PROBE_CODE) if(RANGES_CXX_COMPILER_GCC OR RANGES_CXX_COMPILER_CLANG) set(CMAKE_REQUIRED_FLAGS "-fconcepts ${RANGES_STD_FLAG}") check_cxx_source_compiles("${RANGE_V3_PROBE_CODE}" RANGE_V3_HAS_FCONCEPTS) if(RANGE_V3_HAS_FCONCEPTS) set(RANGE_V3_CONCEPTS_FLAGS "-fconcepts") endif() endif() unset(CMAKE_REQUIRED_FLAGS) unset(RANGE_V3_PROBE_CODE) if (RANGE_V3_CONCEPTS_FLAGS AND RANGES_PREFER_REAL_CONCEPTS) add_compile_options(${RANGE_V3_CONCEPTS_FLAGS}) endif() if (RANGES_VERBOSE_BUILD) get_directory_property(RANGES_COMPILE_OPTIONS COMPILE_OPTIONS) message(STATUS "[range-v3]: C++ flags: ${CMAKE_CXX_FLAGS}") message(STATUS "[range-v3]: C++ debug flags: ${CMAKE_CXX_FLAGS_DEBUG}") message(STATUS "[range-v3]: C++ Release Flags: ${CMAKE_CXX_FLAGS_RELEASE}") message(STATUS "[range-v3]: C++ Compile Flags: ${CMAKE_CXX_COMPILE_FLAGS}") message(STATUS "[range-v3]: Compile options: ${RANGES_COMPILE_OPTIONS}") message(STATUS "[range-v3]: C Flags: ${CMAKE_C_FLAGS}") message(STATUS "[range-v3]: C Compile Flags: ${CMAKE_C_COMPILE_FLAGS}") message(STATUS "[range-v3]: EXE Linker flags: ${CMAKE_EXE_LINKER_FLAGS}") message(STATUS "[range-v3]: C++ Linker flags: ${CMAKE_CXX_LINK_FLAGS}") message(STATUS "[range-v3]: MODULE Linker flags: ${CMAKE_MODULE_LINKER_FLAGS}") get_directory_property(CMakeCompDirDefs COMPILE_DEFINITIONS) message(STATUS "[range-v3]: Compile Definitions: ${CmakeCompDirDefs}") endif()
0
repos/range-v3
repos/range-v3/doc/layout.xml
<doxygenlayout version="1.0"> <!-- Generated by doxygen 1.9.4 --> <!-- Navigation index tabs for HTML output --> <navindex> <tab type="mainpage" visible="yes" title=""/> <tab type="pages" visible="yes" title="" intro=""/> <tab type="modules" visible="yes" title="" intro=""/> <tab type="namespaces" visible="yes" title=""> <tab type="namespacelist" visible="yes" title="" intro=""/> <tab type="namespacemembers" visible="yes" title="" intro=""/> </tab> <tab type="concepts" visible="yes" title=""> </tab> <tab type="interfaces" visible="yes" title=""> <tab type="interfacelist" visible="yes" title="" intro=""/> <tab type="interfaceindex" visible="$ALPHABETICAL_INDEX" title=""/> <tab type="interfacehierarchy" visible="yes" title="" intro=""/> </tab> <tab type="classes" visible="yes" title=""> <tab type="classlist" visible="yes" title="" intro=""/> <tab type="classindex" visible="$ALPHABETICAL_INDEX" title=""/> <tab type="hierarchy" visible="yes" title="" intro=""/> <tab type="classmembers" visible="yes" title="" intro=""/> </tab> <tab type="structs" visible="yes" title=""> <tab type="structlist" visible="yes" title="" intro=""/> <tab type="structindex" visible="$ALPHABETICAL_INDEX" title=""/> </tab> <tab type="exceptions" visible="yes" title=""> <tab type="exceptionlist" visible="yes" title="" intro=""/> <tab type="exceptionindex" visible="$ALPHABETICAL_INDEX" title=""/> <tab type="exceptionhierarchy" visible="yes" title="" intro=""/> </tab> <tab type="files" visible="yes" title=""> <tab type="filelist" visible="yes" title="" intro=""/> <tab type="globals" visible="yes" title="" intro=""/> </tab> <tab type="examples" visible="yes" title="" intro=""/> </navindex> <!-- Layout definition for a class page --> <class> <briefdescription visible="yes"/> <includes visible="$SHOW_HEADERFILE"/> <inheritancegraph visible="$CLASS_GRAPH"/> <collaborationgraph visible="$COLLABORATION_GRAPH"/> <memberdecl> <nestedclasses visible="yes" title=""/> <publictypes title=""/> <services title=""/> <interfaces title=""/> <publicslots title=""/> <signals title=""/> <publicmethods title=""/> <publicstaticmethods title=""/> <publicattributes title=""/> <publicstaticattributes title=""/> <protectedtypes title=""/> <protectedslots title=""/> <protectedmethods title=""/> <protectedstaticmethods title=""/> <protectedattributes title=""/> <protectedstaticattributes title=""/> <packagetypes title=""/> <packagemethods title=""/> <packagestaticmethods title=""/> <packageattributes title=""/> <packagestaticattributes title=""/> <properties title=""/> <events title=""/> <privatetypes title=""/> <privateslots title=""/> <privatemethods title=""/> <privatestaticmethods title=""/> <privateattributes title=""/> <privatestaticattributes title=""/> <friends title=""/> <related title="" subtitle=""/> <membergroups visible="yes"/> </memberdecl> <detaileddescription title=""/> <memberdef> <inlineclasses title=""/> <typedefs title=""/> <enums title=""/> <services title=""/> <interfaces title=""/> <constructors title=""/> <functions title=""/> <related title=""/> <variables title=""/> <properties title=""/> <events title=""/> </memberdef> <allmemberslink visible="yes"/> <usedfiles visible="$SHOW_USED_FILES"/> <authorsection visible="yes"/> </class> <!-- Layout definition for a namespace page --> <namespace> <briefdescription visible="yes"/> <memberdecl> <nestednamespaces visible="yes" title=""/> <constantgroups visible="yes" title=""/> <interfaces visible="yes" title=""/> <classes visible="yes" title=""/> <concepts visible="yes" title=""/> <structs visible="yes" title=""/> <exceptions visible="yes" title=""/> <typedefs title=""/> <sequences title=""/> <dictionaries title=""/> <enums title=""/> <functions title=""/> <variables title=""/> <membergroups visible="yes"/> </memberdecl> <detaileddescription title=""/> <memberdef> <inlineclasses title=""/> <typedefs title=""/> <sequences title=""/> <dictionaries title=""/> <enums title=""/> <functions title=""/> <variables title=""/> </memberdef> <authorsection visible="yes"/> </namespace> <!-- Layout definition for a concept page --> <concept> <briefdescription visible="yes"/> <includes visible="$SHOW_HEADERFILE"/> <definition visible="yes" title=""/> <detaileddescription title=""/> <authorsection visible="yes"/> </concept> <!-- Layout definition for a file page --> <file> <briefdescription visible="yes"/> <includes visible="$SHOW_INCLUDE_FILES"/> <includegraph visible="$INCLUDE_GRAPH"/> <includedbygraph visible="$INCLUDED_BY_GRAPH"/> <sourcelink visible="yes"/> <memberdecl> <interfaces visible="yes" title=""/> <classes visible="yes" title=""/> <structs visible="yes" title=""/> <exceptions visible="yes" title=""/> <namespaces visible="yes" title=""/> <concepts visible="yes" title=""/> <constantgroups visible="yes" title=""/> <defines title=""/> <typedefs title=""/> <sequences title=""/> <dictionaries title=""/> <enums title=""/> <functions title=""/> <variables title=""/> <membergroups visible="yes"/> </memberdecl> <detaileddescription title=""/> <memberdef> <inlineclasses title=""/> <defines title=""/> <typedefs title=""/> <sequences title=""/> <dictionaries title=""/> <enums title=""/> <functions title=""/> <variables title=""/> </memberdef> <authorsection/> </file> <!-- Layout definition for a group page --> <group> <briefdescription visible="yes"/> <groupgraph visible="$GROUP_GRAPHS"/> <memberdecl> <nestedgroups visible="yes" title=""/> <dirs visible="yes" title=""/> <files visible="yes" title=""/> <namespaces visible="yes" title=""/> <concepts visible="yes" title=""/> <classes visible="yes" title=""/> <defines title=""/> <typedefs title=""/> <sequences title=""/> <dictionaries title=""/> <enums title=""/> <enumvalues title=""/> <functions title=""/> <variables title=""/> <signals title=""/> <publicslots title=""/> <protectedslots title=""/> <privateslots title=""/> <events title=""/> <properties title=""/> <friends title=""/> <membergroups visible="yes"/> </memberdecl> <detaileddescription title=""/> <memberdef> <pagedocs/> <inlineclasses title=""/> <defines title=""/> <typedefs title=""/> <sequences title=""/> <dictionaries title=""/> <enums title=""/> <enumvalues title=""/> <functions title=""/> <variables title=""/> <signals title=""/> <publicslots title=""/> <protectedslots title=""/> <privateslots title=""/> <events title=""/> <properties title=""/> <friends title=""/> </memberdef> <authorsection visible="yes"/> </group> <!-- Layout definition for a directory page --> <directory> <briefdescription visible="yes"/> <directorygraph visible="yes"/> <memberdecl> <dirs visible="yes"/> <files visible="yes"/> </memberdecl> <detaileddescription title=""/> </directory> </doxygenlayout>
0
repos/range-v3
repos/range-v3/doc/preprocess.sh.in
#!/bin/bash @Range-v3_SOURCE_DIR@/doc/ignore_errors.sh @CMAKE_CXX_COMPILER@ -x c++ -std=c++2a -DRANGES_DOXYGEN_INVOKED=1 -DMETA_DOXYGEN_INVOKED=1 -DCPP_DOXYGEN_INVOKED=1 -I @Range-v3_SOURCE_DIR@/include -E -CC $1 | @Range-v3_SOURCE_DIR@/doc/unpreprocess.pl exit 0
0
repos/range-v3
repos/range-v3/doc/unpreprocess.pl
#!/usr/bin/perl use strict; my $file = ""; my $first = 1; my $emit = 0; while(<>) { if ($first) { $_ =~ m/^#\s*\d+\s+"(.*)"/; $file = $1; $first = 0; } elsif ($_ =~ m/^#\s*\d+\s+"(.*)"/) { $emit = ($1 eq $file); } elsif ($emit) { print $_; } }
0
repos/range-v3
repos/range-v3/doc/clean-gh-pages.cmake
FILE(GLOB gh_files "*.html" "*.js" "*.css" "*.png") IF( gh_files ) execute_process( COMMAND ${CMAKE_COMMAND} -E remove ${gh_files} ) ENDIF()
0
repos/range-v3
repos/range-v3/doc/index.md
User Manual {#mainpage} =========== \tableofcontents \section tutorial-preface Preface -------------------------------------------- Range library for C++14/17/20. This code is the basis of [the range support in C++20](http://eel.is/c++draft/#ranges). **Development Status:** This code is fairly stable, well-tested, and suitable for casual use, although currently lacking documentation. No promise is made about support or long-term stability. This code *will* evolve without regard to backwards compatibility. A notable exception is anything found within the `ranges::cpp20` namespace. Those components will change rarely or (preferably) never at all. \subsection tutorial-installation Installation -------------------------------------------- This library is header-only. You can get the source code from the [range-v3 repository](https://github.com/ericniebler/range-v3) on github. To compile with Range-v3, just `#include` the individual headers you want. This distribution actually contains three separate header-only libraries: * <strong><tt>include/concepts/...</tt></strong> contains the Concepts Portability Preprocessor, or CPP, which is a set of macros for defining and using concept checks, regardless of whether your compiler happens to support the C++20 concepts language feature or not. * <strong><tt>include/meta/...</tt></strong> contains the Meta Library, which is a set of meta-programming utilities for processing types and lists of types at compile time. * <strong><tt>include/range/...</tt></strong> contains the Range-v3 library, as described below. The Range-v3 library is physically structured in directories by feature group: * <strong><tt>include/range/v3/actions/...</tt></strong> contains _actions_, or composable components that operate eagerly on containers and return the mutated container for further actions. * <strong><tt>include/range/v3/algorithms/...</tt></strong> contains all the STL _algorithms_ with overloads that accept ranges, in addition to the familiar overloads that take iterators. * <strong><tt>include/range/v3/functional/...</tt></strong> contains many generally useful components that would be familiar to functional programmers. * <strong><tt>include/range/v3/iterator/...</tt></strong> contains the definitions of many useful iterators and iterator-related concepts and utilities. * <strong><tt>include/range/v3/numeric/...</tt></strong> contains numeric algorithms corresponding to those found in the standard `<numeric>` header. * <strong><tt>include/range/v3/range/...</tt></strong> contains range-related utilities, such as `begin`, `end`, and `size`, range traits and concepts, and conversions to containers. * <strong><tt>include/range/v3/utility/...</tt></strong> contains a miscellaneous assortment of reusable code. * <strong><tt>include/range/v3/view/...</tt></strong> contains _views_, or composable components that operate lazily on ranges and that themselves return ranges that can be operated upon with additional view adaptors. \subsection tutorial-license License -------------------------------------------- Most of the source code in this project are mine, and those are under the Boost Software License. Parts are taken from Alex Stepanov's Elements of Programming, Howard Hinnant's libc++, and from the SGI STL. Please see the attached LICENSE file and the CREDITS file for the licensing and acknowledgements. \subsection tutorial-compilers Supported Compilers -------------------------------------------------------------------------------- The code is known to work on the following compilers: - clang 5.0 - GCC 6.5 - Clang/LLVM 6 (or later) on Windows - MSVC VS2019, with `/permissive-` and either `/std:c++latest`, `/std:c++20`, or `/std:c++17` \section tutorial-quick-start Quick Start -------------------------------------------------------------------------------- Range-v3 is a generic library that augments the existing standard library with facilities for working with *ranges*. A range can be loosely thought of a pair of iterators, although they need not be implemented that way. Bundling begin/end iterators into a single object brings several benefits: convenience, composability, and correctness. **Convenience** It's more convenient to pass a single range object to an algorithm than separate begin/end iterators. Compare: ~~~~~~~{.cpp} std::vector<int> v{/*...*/}; std::sort( v.begin(), v.end() ); ~~~~~~~ with ~~~~~~~{.cpp} std::vector<int> v{/*...*/}; ranges::sort( v ); ~~~~~~~ Range-v3 contains full implementations of all the standard algorithms with range-based overloads for convenience. **Composability** Having a single range object permits *pipelines* of operations. In a pipeline, a range is lazily adapted or eagerly mutated in some way, with the result immediately available for further adaptation or mutation. Lazy adaption is handled by *views*, and eager mutation is handled by *actions*. For instance, the below uses _views_ to filter a container using a predicate and transform the resulting range with a function. Note that the underlying data is `const` and is not mutated by the views. ~~~~~~~{.cpp} std::vector<int> const vi{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; using namespace ranges; auto rng = vi | views::remove_if([](int i){ return i % 2 == 1; }) | views::transform([](int i){ return std::to_string(i); }); // rng == {"2","4","6","8","10"}; ~~~~~~~ In the code above, `rng` simply stores a reference to the underlying data and the filter and transformation functions. No work is done until `rng` is iterated. In contrast, _actions_ do their work eagerly, but they also compose. Consider the code below, which reads some data into a vector, sorts it, and makes it unique. ~~~~~~~{.cpp} extern std::vector<int> read_data(); using namespace ranges; std::vector<int> vi = read_data() | actions::sort | actions::unique; ~~~~~~~ Unlike views, with actions each step in the pipeline (`actions::sort` and `actions::unique`) accepts a container _by value_, mutates it in place, and returns it. **Correctness** Whether you are using views or actions, you are operating on data in a pure functional, declarative style. You rarely need to trouble yourself with iterators, although they are there under the covers should you need them. By operating declaratively and functionally instead of imperatively, we reduce the need for overt state manipulation and branches and loops. This brings down the number of states your program can be in, which brings down your bug counts. In short, if you can find a way to express your solution as a composition of functional transformations on your data, you can make your code _correct by construction_. \subsection tutorial-views Views -------------------------------------------------------------------------------- As described above, the big advantage of ranges over iterators is their composability. They permit a functional style of programming where data is manipulated by passing it through a series of combinators. In addition, the combinators can be *lazy*, only doing work when the answer is requested, and *purely functional*, without mutating the original data. This makes it easier to reason about your code. A _view_ is a lightweight wrapper that presents a view of an underlying sequence of elements in some custom way without mutating or copying it. Views are cheap to create and copy and have non-owning reference semantics. Below are some examples that use views: Filter a container using a predicate and transform it. ~~~~~~~{.cpp} std::vector<int> const vi{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; using namespace ranges; auto rng = vi | views::remove_if([](int i){return i % 2 == 1;}) | views::transform([](int i){return std::to_string(i);}); // rng == {"2","4","6","8","10"}; ~~~~~~~ Generate an infinite list of integers starting at 1, square them, take the first 10, and sum them: ~~~~~~~{.cpp} using namespace ranges; int sum = accumulate(views::ints(1) | views::transform([](int i){return i*i;}) | views::take(10), 0); ~~~~~~~ Generate a sequence on the fly with a range comprehension and initialize a vector with it: ~~~~~~~{.cpp} using namespace ranges; auto vi = views::for_each(views::ints(1, 10), [](int i) { return yield_from(views::repeat_n(i, i)); }) | to<std::vector>(); // vi == {1,2,2,3,3,3,4,4,4,4,5,5,5,5,5,...} ~~~~~~~ ### View const-ness Logically, a view is a factory for iterators, but in practice a view is often implemented as a state machine, with the state stored within the view object itself (to keep iterators small) and mutated as the view is iterated. Because the view contains mutable state, many views lack a `const`-qualified `begin()`/`end()`. When `const` versions of `begin()`/`end()` are provided, they are truly `const`; that is, thread-safe. Since views present the same interface as containers, the temptation is to think they behave like containers with regard to `const`-ness. This is not the case. Their behavior with regards to `const`-ness is similar to iterators and pointers. The `const`-ness of a view is not related to the `const`-ness of the underlying data. A non-`const` view may refer to elements that are themselves `const`, and _vice versa_. This is analogous to pointers; an `int* const` is a `const` pointer to a mutable `int`, and a `int const*` is a non-`const` pointer to a `const` `int`. Use non-`const` views whenever possible. If you need thread-safety, work with view copies in threads; don't share. ### View validity Any operation on the underlying range that invalidates its iterators or sentinels will also invalidate any view that refers to any part of that range. Additionally, some views (_e.g._, `views::filter`), are invalidated when the underlying elements of the range are mutated. It is best to recreate a view after any operation that may have mutated the underlying range. ### List of range views Below is a list of the lazy range combinators, or views, that Range-v3 provides, and a blurb about how each is intended to be used. <DL> <DT>\link ranges::views::addressof_fn `views::addressof`\endlink</DT> <DD>Given a source range of lvalue references, return a new view that is the result of taking `std::addressof` of each.</DD> <DT>\link ranges::views::adjacent_filter_fn `views::adjacent_filter`\endlink</DT> <DD>For each pair of adjacent elements in a source range, evaluate the specified binary predicate. If the predicate evaluates to false, the second element of the pair is removed from the result range; otherwise, it is included. The first element in the source range is always included. (For instance, `adjacent_filter` with `std::not_equal_to` filters out all the non-unique elements.)</DD> <DT>\link ranges::views::adjacent_remove_if_fn `views::adjacent_remove_if`\endlink</DT> <DD>For each pair of adjacent elements in a source range, evaluate the specified binary predicate. If the predicate evaluates to true, the first element of the pair is removed from the result range; otherwise, it is included. The last element in the source range is always included.</DD> <DT>\link ranges::views::all_fn `views::all`\endlink</DT> <DD>Return a range containing all the elements in the source. Useful for converting containers to ranges.</DD> <DT>\link ranges::any_view `any_view<T>(rng)`\endlink</DT> <DD>Type-erased range of elements with value type `T`; can store _any_ range with this value type.</DD> <DT>\link ranges::views::c_str_fn `views::c_str`\endlink</DT> <DD>View a `\0`-terminated C string (e.g. from a `const char*`) as a range.</DD> <DT>\link ranges::views::cache1_fn `views::cache1`\endlink</DT> <DD>Caches the most recent element within the view so that dereferencing the view's iterator multiple times doesn't incur any recomputation. This can be useful in adaptor pipelines that include combinations of `view::filter` and `view::transform`, for instance. `views::cache1` is always single-pass.</DD> <DT>\link ranges::views::cartesian_product_fn `views::cartesian_product`\endlink</DT> <DD>Enumerates the n-ary cartesian product of `n` ranges, i.e., generates all `n`-tuples `(e1, e2, ... , en)` where `e1` is an element of the first range, `e2` is an element of the second range, etc.</DD> <DT>\link ranges::views::chunk_fn `views::chunk`\endlink</DT> <DD>Given a source range and an integer *N*, produce a range of contiguous ranges where each inner range has *N* contiguous elements. The final range may have fewer than *N* elements.</DD> <DT>\link ranges::views::common_fn `views::common`\endlink</DT> <DD>Convert the source range to a *common* range, where the type of the `end` is the same as the `begin`. Useful for calling algorithms in the `std::` namespace.</DD> <DT>\link ranges::views::concat_fn `views::concat`\endlink</DT> <DD>Given *N* source ranges, produce a result range that is the concatenation of all of them.</DD> <DT>\link ranges::views::const_fn `views::const_`\endlink</DT> <DD>Present a `const` view of a source range.</DD> <DT>\link ranges::views::counted_fn `views::counted`\endlink</DT> <DD>Given an iterator `it` and a count `n`, create a range that starts at `it` and includes the next `n` elements.</DD> <DT>\link ranges::views::cycle_fn `views::cycle`\endlink</DT> <DD>Returns an infinite range that endlessly repeats the source range.</DD> <DT>\link ranges::views::delimit_fn `views::delimit`\endlink</DT> <DD>Given a source range and a value, return a new range that ends either at the end of the source or at the first occurrence of the value, whichever comes first. Alternatively, `views::delimit` can be called with an iterator and a value, in which case it returns a range that starts at the specified position and ends at the first occurrence of the value.</DD> <DT>\link ranges::views::drop_fn `views::drop`\endlink</DT> <DD>Given a source range and an integral count, return a range consisting of all but the first *count* elements from the source range, or an empty range if it has fewer elements.</DD> <DT>\link ranges::views::drop_last_fn `views::drop_last`\endlink</DT> <DD>Given a source range and an integral count, return a range consisting of all but the last *count* elements from the source range, or an empty range if it has fewer elements.</DD> <DT>\link ranges::views::drop_exactly_fn `views::drop_exactly`\endlink</DT> <DD>Given a source range and an integral count, return a range consisting of all but the first *count* elements from the source range. The source range must have at least that many elements.</DD> <DT>\link ranges::views::drop_while_fn `views::drop_while`\endlink</DT> <DD>Remove elements from the front of a range that satisfy a unary predicate.</DD> <DT>\link ranges::views::empty() `views::empty`\endlink</DT> <DD>Create an empty range with a given value type.</DD> <DT>\link ranges::views::enumerate() `views::enumerate`\endlink</DT> <DD>Pair each element of a range with its index.</DD> <DT>\link ranges::views::filter_fn `views::filter`\endlink</DT> <DD>Given a source range and a unary predicate, filter the elements that satisfy the predicate. (For users of Boost.Range, this is like the `filter` adaptor.)</DD> <DT>\link ranges::views::for_each_fn `views::for_each`\endlink</DT> <DD>Lazily applies an unary function to each element in the source range that returns another range (possibly empty), flattening the result.</DD> <DT>\link ranges::views::generate_fn `views::generate`\endlink</DT> <DD>Given a nullary function, return an infinite range whose elements are generated with the function.</DD> <DT>\link ranges::views::generate_n_fn `views::generate_n`\endlink</DT> <DD>Given a nullary function and a count, return a range that generates the requested number of elements by calling the function.</DD> <DT>\link ranges::views::chunk_by_fn `views::chunk_by`\endlink</DT> <DD>Given a source range and a binary predicate, return a range of ranges where each range contains contiguous elements from the source range such that the following condition holds: for each element in the range apart from the first, when that element and the previous element are passed to the binary predicate, the result is true. In essence, `views::chunk_by` groups contiguous elements together with a binary predicate.</DD> <DT>\link ranges::views::indirect_fn `views::indirect`\endlink</DT> <DD>Given a source range of readable values (e.g. pointers or iterators), return a new view that is the result of dereferencing each.</DD> <DT>\link ranges::views::intersperse_fn `views::intersperse`\endlink</DT> <DD>Given a source range and a value, return a new range where the value is inserted between contiguous elements from the source.</DD> <DT>\link ranges::views::ints_fn `views::ints`\endlink</DT> <DD>Generate a range of monotonically increasing `int`s. When used without arguments, it generates the quasi-infinite range [0,1,2,3...]. It can also be called with a lower bound, or with a lower and upper bound (exclusive). An inclusive version is provided by `closed_ints`.</DD> <DT>\link ranges::views::iota_fn `views::iota`\endlink</DT> <DD>A generalization of `views::ints` that generates a sequence of monotonically increasing values of any incrementable type. When specified with a single argument, the result is an infinite range beginning at the specified value. With two arguments, the values are assumed to denote a half-open range.</DD> <DT>\link ranges::views::join_fn `views::join`\endlink</DT> <DD>Given a range of ranges, join them into a flattened sequence of elements. Optionally, you can specify a value or a range to be inserted between each source range.</DD> <DT>\link ranges::views::keys_fn `views::keys`\endlink</DT> <DD>Given a range of `pair`s (like a `std::map`), return a new range consisting of just the first element of the `pair`.</DD> <DT>\link ranges::views::linear_distribute_fn `views::linear_distribute`\endlink</DT> <DD>Distributes `n` values linearly in the closed interval `[from, to]` (the end points are always included). If `from == to`, returns `n`-times `to`, and if `n == 1` it returns `to`.</DD> <DT>\link ranges::views::move_fn `views::move`\endlink</DT> <DD>Given a source range, return a new range where each element has been cast to an rvalue reference.</DD> <DT>\link ranges::views::partial_sum_fn `views::partial_sum`\endlink</DT> <DD>Given a range and a binary function, return a new range where the *N*<SUP>th</SUP> element is the result of applying the function to the *N*<SUP>th</SUP> element from the source range and the (N-1)th element from the result range.</DD> <DT>\link ranges::views::remove_fn `views::remove`\endlink</DT> <DD>Given a source range and a value, filter out those elements that do not equal value.</DD> <DT>\link ranges::views::remove_if_fn `views::remove_if`\endlink</DT> <DD>Given a source range and a unary predicate, filter out those elements that do not satisfy the predicate. (For users of Boost.Range, this is like the `filter` adaptor with the predicate negated.)</DD> <DT>\link ranges::views::repeat_fn `views::repeat`\endlink</DT> <DD>Given a value, create a range that is that value repeated infinitely.</DD> <DT>\link ranges::views::repeat_n_fn `views::repeat_n`\endlink</DT> <DD>Given a value and a count, create a range that is that value repeated *count* number of times.</DD> <DT>\link ranges::views::replace_fn `views::replace`\endlink</DT> <DD>Given a source range, a source value and a target value, create a new range where all elements equal to the source value are replaced with the target value.</DD> <DT>\link ranges::views::replace_if_fn `views::replace_if`\endlink</DT> <DD>Given a source range, a unary predicate and a target value, create a new range where all elements that satisfy the predicate are replaced with the target value.</DD> <DT>\link ranges::views::reverse_fn `views::reverse`\endlink</DT> <DD>Create a new range that traverses the source range in reverse order.</DD> <DT>\link ranges::views::sample_fn `views::sample`\endlink</DT> <DD>Returns a random sample of a range of length `size(range)`.</DD> <DT>\link ranges::views::single_fn `views::single`\endlink</DT> <DD>Given a value, create a range with exactly one element.</DD> <DT>\link ranges::views::slice_fn `views::slice`\endlink</DT> <DD>Give a source range a lower bound (inclusive) and an upper bound (exclusive), create a new range that begins and ends at the specified offsets. Both the begin and the end can be integers relative to the front, or relative to the end with "`end-2`" syntax.</DD> <DT>\link ranges::views::sliding_fn `views::sliding`\endlink</DT> <DD>Given a range and a count `n`, place a window over the first `n` elements of the underlying range. Return the contents of that window as the first element of the adapted range, then slide the window forward one element at a time until hitting the end of the underlying range.</DD> <DT>\link ranges::views::split_fn `views::split`\endlink</DT> <DD>Given a source range and a delimiter specifier, split the source range into a range of ranges using the delimiter specifier to find the boundaries. The delimiter specifier can be an element or a range of elements. The elements matching the delimiter are excluded from the resulting range of ranges.</DD> <DT>\link ranges::views::split_when_fn `views::split_when`\endlink</DT> <DD>Given a source range and a delimiter specifier, split the source range into a range of ranges using the delimiter specifier to find the boundaries. The delimiter specifier can be a predicate or a function. The predicate should take a single argument of the range's reference type and return `true` if and only if the element is part of a delimiter. The function should accept an iterator and sentinel indicating the current position and end of the source range and return `std::make_pair(true, iterator_past_the_delimiter)` if the current position is a boundary; otherwise `std::make_pair(false, ignored_iterator_value)`. The elements matching the delimiter are excluded from the resulting range of ranges.</DD> <DT>\link ranges::views::stride_fn `views::stride`\endlink</DT> <DD>Given a source range and an integral stride value, return a range consisting of every *N*<SUP>th</SUP> element, starting with the first.</DD> <DT>\link ranges::views::tail_fn `views::tail`\endlink</DT> <DD>Given a source range, return a new range without the first element. The range must have at least one element.</DD> <DT>\link ranges::views::take_fn `views::take`\endlink</DT> <DD>Given a source range and an integral count, return a range consisting of the first *count* elements from the source range, or the complete range if it has fewer elements. (The result of `views::take` is not a `sized_range`.)</DD> <DT>\link ranges::views::take_exactly_fn `views::take_exactly`\endlink</DT> <DD>Given a source range and an integral count, return a range consisting of the first *count* elements from the source range. The source range must have at least that many elements. (The result of `views::take_exactly` is a `sized_range`.)</DD> <DT>\link ranges::views::take_last_fn `views::take_last`\endlink</DT> <DD>Given a source range and an integral count, return a range consisting of the last *count* elements from the source range. The source range must be a `sized_range`. If the source range does not have at least *count* elements, the full range is returned.</DD> <DT>\link ranges::views::take_while_fn `views::take_while`\endlink</DT> <DD>Given a source range and a unary predicate, return a new range consisting of the elements from the front that satisfy the predicate.</DD> <DT>\link ranges::views::tokenize_fn `views::tokenize`\endlink</DT> <DD>Given a source range and optionally a submatch specifier and a `std::regex_constants::match_flag_type`, return a `std::regex_token_iterator` to step through the regex submatches of the source range. The submatch specifier may be either a plain `int`, a `std::vector<int>`, or a `std::initializer_list<int>`.</DD> <DT>\link ranges::views::transform_fn `views::transform`\endlink</DT> <DD>Given a source range and a unary function, return a new range where each result element is the result of applying the unary function to a source element.</DD> <DT>\link ranges::views::trim_fn `views::trim`\endlink</DT> <DD>Given a source bidirectional range and a unary predicate, return a new range without the front and back elements that satisfy the predicate.</DD> <DT>\link ranges::views::unbounded_fn `views::unbounded`\endlink</DT> <DD>Given an iterator, return an infinite range that begins at that position.</DD> <DT>\link ranges::views::unique_fn `views::unique`\endlink</DT> <DD>Given a range, return a new range where all consecutive elements that compare equal save the first have been filtered out.</DD> <DT>\link ranges::views::values_fn `views::values`\endlink</DT> <DD>Given a range of `pair`s (like a `std::map`), return a new range consisting of just the second element of the `pair`.</DD> <DT>\link ranges::views::zip_fn `views::zip`\endlink</DT> <DD>Given *N* ranges, return a new range where *M*<SUP>th</SUP> element is the result of calling `make_tuple` on the *M*<SUP>th</SUP> elements of all *N* ranges.</DD> <DT>\link ranges::views::zip_with_fn `views::zip_with`\endlink</DT> <DD>Given *N* ranges and a *N*-ary function, return a new range where *M*<SUP>th</SUP> element is the result of calling the function on the *M*<SUP>th</SUP> elements of all *N* ranges.</DD> </DL> \subsection tutorial-actions Actions -------------------------------------------------------------- When you want to mutate a container in-place, or forward it through a chain of mutating operations, you can use actions. The following examples should make it clear. Read data into a vector, sort it, and make it unique. ~~~~~~~{.cpp} extern std::vector<int> read_data(); using namespace ranges; std::vector<int> vi = read_data() | actions::sort | actions::unique; ~~~~~~~ Do the same to a `vector` that already contains some data: ~~~~~~~{.cpp} vi = std::move(vi) | actions::sort | actions::unique; ~~~~~~~ Mutate the container in-place: ~~~~~~~{.cpp} vi |= actions::sort | actions::unique; ~~~~~~~ Same as above, but with function-call syntax instead of pipe syntax: ~~~~~~~{.cpp} actions::unique(actions::sort(vi)); ~~~~~~~ ### List of range actions Below is a list of the eager range combinators, or actions, that Range-v3 provides, and a blurb about how each is intended to be used. <DL> <DT>\link ranges::actions::drop_fn `actions::drop`\endlink</DT> <DD>Removes the first `N` elements of the source range.</DD> <DT>\link ranges::actions::drop_while_fn `actions::drop_while`\endlink</DT> <DD>Removes the first elements of the source range that satisfy the unary predicate.</DD> <DT>`actions::erase`</DT> <DD>Removes all elements in the sub-range of the source (range version) or all elements after position.</DD> <DT>`actions::insert`</DT> <DD>Inserts all elements of the range into the source at position.</DD> <DT>\link ranges::actions::join_fn `actions::join`\endlink</DT> <DD>Flattens a range of ranges.</DD> <DT> `actions::push_back`</DT> <DD>Appends elements to the tail of the source.</DD> <DT>`actions::push_front`</DT> <DD>Appends elements before the head of the source.</DD> <DT>\link ranges::actions::remove_if_fn `actions::remove_if`\endlink</DT> <DD>Removes all elements from the source that satisfy the predicate.</DD> <DT>\link ranges::actions::remove_fn `actions::remove`\endlink</DT> <DD>Removes all elements from the source that are equal to value.</DD> <DT>\link ranges::actions::reverse_fn `actions::reverse`\endlink</DT> <DD>Reverses all the elements in the container.</DD> <DT>\link ranges::actions::shuffle_fn `actions::shuffle`\endlink</DT> <DD>Shuffles the source range.</DD> <DT>\link ranges::actions::slice_fn `actions::slice`\endlink</DT> <DD>Removes all elements from the source that are not part of the sub-range.</DD> <DT>\link ranges::actions::sort_fn `actions::sort`\endlink</DT> <DD>Sorts the source range (unstable).</DD> <DT>\link ranges::actions::split_fn `actions::split`\endlink</DT> <DD>Split a range into a sequence of subranges using a delimiter (a value, a sequence of values, a predicate, or a binary function returning a `pair<bool, N>`).</DD> <DT>\link ranges::actions::stable_sort_fn `actions::stable_sort`\endlink</DT> <DD>Sorts the source range (stable).</DD> <DT>\link ranges::actions::stride_fn `actions::stride`\endlink</DT> <DD>Removes all elements whose position does not match the stride.</DD> <DT>\link ranges::actions::take_fn `actions::take`\endlink</DT> <DD>Keeps the first `N`-th elements of the range, removes the rest.</DD> <DT>\link ranges::actions::take_while_fn `actions::take_while`\endlink</DT> <DD>Keeps the first elements that satisfy the predicate, removes the rest.</DD> <DT>\link ranges::actions::transform_fn `actions::transform`\endlink</DT> <DD>Replaces elements of the source with the result of the unary function.</DD> <DT>\link ranges::actions::unique_fn `actions::unique`\endlink</DT> <DD>Removes adjacent elements of the source that compare equal. If the source is sorted, removes all duplicate elements.</DD> <DT>\link ranges::actions::unstable_remove_if_fn `actions::unstable_remove_if`\endlink</DT> <DD>Much faster (each element remove has constant time complexity), unordered version of `remove_if`. Requires bidirectional container.</DD> </DL> \subsection tutorial-utilities Utilities ---------------------------------------------- Below we cover some utilities that range-v3 provides for creating your own view adaptors and iterators. #### Create Custom Views with view_facade Range-v3 provides a utility for easily creating your own range types, called \link ranges::view_facade `ranges::view_facade`\endlink. The code below uses `view_facade` to create a range that traverses a null-terminated string: ~~~~~~~{.cpp} #include <range/v3/view/facade.hpp> // A range that iterates over all the characters in a // null-terminated string. class c_string_range : public ranges::view_facade<c_string_range> { friend ranges::range_access; char const * sz_ = ""; char const & read() const { return *sz_; } bool equal(ranges::default_sentinel_t) const { return *sz_ == '\0'; } void next() { ++sz_; } public: c_string_range() = default; explicit c_string_range(char const *sz) : sz_(sz) { assert(sz != nullptr); } }; ~~~~~~~ The `view_facade` class generates an iterator and begin/end member functions from the minimal interface provided by `c_string_range`. This is an example of a very simple range for which it is not necessary to separate the range itself from the thing that iterates the range. Future examples will show examples of more sophisticated ranges. With `c_string_range`, you can now use algorithms to operate on null-terminated strings, as below: ~~~~~~~{.cpp} #include <iostream> #include <range/v3/algorithm/for_each.hpp> int main() { c_string_range r("hello world"); // Iterate over all the characters and print them out ranges::for_each(r, [](char ch){ std::cout << ch << ' '; }); // prints: h e l l o w o r l d } ~~~~~~~ #### Create Custom Views with view_adaptor Often, a new range type is most easily expressed by adapting an existing range type. That's the case for many of the range views provided by the Range-v3 library; for example, the `views::remove_if` and `views::transform` views. These are rich types with many moving parts, but thanks to a helper class called \link ranges::view_adaptor `ranges::view_adaptor`\endlink, they aren't hard to write. Below in roughly 2 dozen lines of code is the `transform` view, which takes one range and transforms all the elements with a unary function. ~~~~~~~{.cpp} #include <range/v3/view/adaptor.hpp> #include <range/v3/utility/semiregular_box.hpp> // A class that adapts an existing range with a function template<class Rng, class Fun> class transform_view : public ranges::view_adaptor<transform_view<Rng, Fun>, Rng> { friend ranges::range_access; ranges::semiregular_box_t<Fun> fun_; // Make Fun model semiregular if it doesn't class adaptor : public ranges::adaptor_base { ranges::semiregular_box_t<Fun> fun_; public: adaptor() = default; adaptor(ranges::semiregular_box_t<Fun> const &fun) : fun_(fun) {} // Here is where we apply Fun to the elements: auto read(ranges::iterator_t<Rng> it) const -> decltype(fun_(*it)) { return fun_(*it); } }; adaptor begin_adaptor() const { return {fun_}; } adaptor end_adaptor() const { return {fun_}; } public: transform_view() = default; transform_view(Rng && rng, Fun fun) : transform_view::view_adaptor{std::forward<Rng>(rng)} , fun_(std::move(fun)) {} }; template<class Rng, class Fun> transform_view<Rng, Fun> transform(Rng && rng, Fun fun) { return {std::forward<Rng>(rng), std::move(fun)}; } ~~~~~~~ Range transformation is achieved by defining a nested `adaptor` class that handles the transformation, and then defining `begin_adaptor` and `end_adaptor` members that return adaptors for the begin iterator and the end sentinel, respectively. The `adaptor` class has a `read` member that performs the transformation. It is passed an iterator to the current element. Other members are available for customization: `equal`, `next`, `prev`, `advance`, and `distance_to`; but the transform adaptor accepts the defaults defined in \link ranges::adaptor_base `ranges::adaptor_base`\endlink. With `transform_view`, we can print out the first 20 squares: ~~~~~~~{.cpp} int main() { auto squares = ::transform(views::ints(1), [](int i){return i*i;}); for(int i : squares | views::take(20)) std::cout << i << ' '; std::cout << '\n'; // prints 1 4 9 16 25 36 49 64 81 100 121 144 169 196 225 256 289 324 361 400 } ~~~~~~~ The `transform_view` defined above is an input range when it is wrapping an input range, a forward range when it's wrapping a forward range, etc. That happens because of smart defaults defined in the `adaptor_base` class that frees you from having to deal with a host of niggly detail when implementing iterators. *(Note: the above `transform_view` always stores a copy of the function in the sentinel. That is only necessary if the underlying range's sentinel type models bidirectional_iterator. That's a finer point that you shouldn't worry about right now.)* ##### view_adaptor in details Each `view_adaptor` contains `base()` member in view and iterator. `base()` - allow to access "adapted" range/iterator: ~~~~~~~{.cpp} std::vector<int> vec; auto list = vec | views::transfom([](int i){ return i+1; }); assert( vec.begin() == list.begin().base() ); assert( vec.begin() == list.base().begin() ); ~~~~~~~ Like `basic_iterator`'s `cursor`, `view_adaptor`'s `adaptor` can contain mixin class too, to inject things into the public interface of the iterator: ~~~~~~~{.cpp} class adaptor : public ranges::adaptor_base { template<class BaseMixin> struct mixin : BaseMixin { // everything inside this class will be accessible from iterator using BaseMixin::BaseMixin; auto& base_value() const { return *this->base(); } int get_i() const { return this->get().i; } }; int i = 100; }; ~~~~~~~ From within mixin you can call: * `get()` - to access adaptor internals * `base()` - to access adaptable iterator Iterator/sentinel adaptor may "override" the following members: ~~~~~~~{.cpp} class adaptor : public ranges::adaptor_base { // !For begin_adaptor only! template<typename Rng> constexpr auto begin(Rng &rng) { return ranges::begin(rng.base()); } // !For end_adaptor only! template<typename Rng> constexpr auto end(Rng &rng) { return ranges::end(rng.base()); } template<typename I> bool equal(I const &this_iter, I const &that_iter) const { return this_iter == that_iter; } // or template<typename I> bool equal(I const &this_iter, I const &that_iter, adaptor const &that_adapt) const { return *this.some_value == that_adapt.some_value && this_iter == that_iter; } // !For end_adaptor only! // Same as equal, but compare iterator with sentinel. // Not used, if iterator same as sentinel, and both have the same adaptor. template<typename I, typename S> constexpr bool empty(I const &it, S const &end) const { return it == end; } // or template<typename I, typename S, typename SA> constexpr bool empty(I const &it, S const &end, SA const &end_adapt) const { return *this.some_value == end_adapt.some_value && it == end; } template<typename I> reference_t<I> read(I const &it) { return *it; } template<typename I> void next(I &it) { ++it; } // !For bidirectional iterator only! template<typename I> void prev(I &it) { --it; } // !For random access iterator only! template<typename I> void advance(I &it, difference_type_t<I> n) { it += n; } // !For "sized" iterators only! template<typename I> difference_type_t<I> distance_to(I const &this_iter, I const &that_iter) { return that_iter - this_iter; } // or template<typename I> difference_type_t<I> distance_to (I const &this_iter, I const &that_iter, adaptor const &that_adapt) { return that_iter - this_iter; } } ~~~~~~~ As you can see, some "overrides" have effect only for `begin_adaptor` or `end_adaptor`. In order to use full potential of adaptor, you need to have separate adaptors for begin and end: ~~~~~~~{.cpp} struct adaptor : adaptor_base { int n = 0; void next(iterator_t<Rng>& it) { ++n; ++it; } }; struct sentinel_adaptor : adaptor_base { int stop_at; bool empty(const iterator_t<Rng>&, const adaptor& ia, const sentinel_t<Rng>& s) const { return ia.n == stop_at; } }; adaptor begin_adaptor() const { return {}; } sentinel_adaptor end_adaptor() const { return {100}; } ~~~~~~~ Sometimes, you can use the same adaptor for both `begin_adaptor` and `end_adaptor`: ~~~~~~~{.cpp} struct adaptor : adaptor_base { int n = 0; void next(iterator_t<Rng>& it) { ++n; ++it; } // pay attention, we use equal, not empty. empty() will never trigger. template<typename I> bool equal(I const &this_iter, I const &that_iter, adaptor const &that_adapt) const { return *this.n == that_adapt.n; } }; adaptor begin_adaptor() const { return {}; } adaptor end_adaptor() const { return {100}; } ~~~~~~~ Note that all the data you store in the adaptor will become part of the iterator. If you will not "override" `begin_adaptor()` or/and `end_adaptor()` in your view_adaptor, default ones will be used. #### Create Custom Iterators with basic_iterator Here is an example of Range-v3 compatible random access proxy iterator. The iterator returns a key/value pair, like the `zip` view. ~~~~~~~{.cpp} #include <range/v3/iterator/basic_iterator.hpp> #include <range/v3/utility/common_tuple.hpp> using KeyIter = typename std::vector<Key>::iterator; using ValueIter = typename std::vector<Value>::iterator; struct cursor { // basic_iterator derives from "mixin", if present, so it can be used // to inject things into the public interface of the iterator struct mixin; // This is for dereference operator. using value_type = std::pair<Key, Value>; ranges::common_pair<Key&, Value&> read() const { return { *key_iterator, *value_iterator }; } bool equal(const cursor& other) const { return key_iterator == other.key_iterator; } void next() { ++key_iterator; ++value_iterator; } // prev optional. Required for Bidirectional iterator void prev() { --key_iterator; --value_iterator; } // advance and distance_to are optional. Required for random access iterator void advance(std::ptrdiff_t n) { key_iterator += n; value_iterator += n; } std::ptrdiff_t distance_to(const cursor& other) const { return other.key_iterator - this->key_iterator; } cursor() = default; cursor(KeyIter key_iterator, ValueIter value_iterator) : key_iterator(key_iterator) , value_iterator(value_iterator) {} KeyIter key_iterator; ValueIter value_iterator; }; struct cursor::mixin : ranges::basic_mixin<cursor> { using ranges::basic_mixin<cursor>::basic_mixin; // It is necessary to expose constructor in this way mixin(KeyIter key_iterator, ValueIter value_iterator) : mixin{ cursor(key_iterator, value_iterator) } {} KeyIter key_iterator() { return this->get().key_iterator; } ValueIter value_iterator() { return this->get().value_iterator; } }; using iterator = ranges::basic_iterator<cursor>; void test() { std::vector<Key> keys = {1}; std::vector<Value> values = {10}; iterator iter(keys.begin(), values.begin()); ranges::common_pair<Key&, Value&> pair = *iter; Key& key = pair.first; Value& value = pair.second; assert(&key == &keys[0]); assert(&value == &values[0]); auto key_iter = iter.key_iterator(); assert(key_iter == keys.begin()); } ~~~~~~~ `read()` returns references. But the default for `value_type`, which is `decay_t<decltype(read())>`, is `common_pair<Key&, Value&>`. That is not correct in our case. It should be `pair<Key, Value>`, so we explicitly specify `value_type`. `ranges::common_pair` has conversions: > `ranges::common_pair<Key&, Value&>` &harr; `ranges::common_pair<Key, Value>`. All `ranges::common_pair`s converts to their `std::pair` equivalents, also. For more information, see [http://wg21.link/P0186#basic-iterators-iterators.basic](http://wg21.link/P0186#basic-iterators-iterators.basic) \subsection tutorial-concepts Concept Checking -------------------------------------------------------------------------------- The Range-v3 library makes heavy use of concepts to constrain functions, control overloading, and check type constraints at compile-time. It achieves this with the help of a Concepts emulation layer that works on any standard-conforming C++14 compiler. The library provides many useful concepts, both for the core language and for iterators and ranges. You can use the concepts framework to constrain your own code. For instance, if you would like to write a function that takes an iterator/sentinel pair, you can write it like this: ~~~~~~~{.cpp} CPP_template(class Iter, class Sent, class Comp = /*...some_default..*/) (requires sentinel_for<Sent, Iter>) void my_algorithm(Iter first, Sent last, Comp comp = Comp{}) { // ... } ~~~~~~~ You can then add an overload that take a Range: ~~~~~~~{.cpp} CPP_template(class Rng, class Comp = /*...some_default..*/) (requires range<Rng>) void my_algorithm(Rng && rng, Comp comp = Comp{}) { return my_algorithm(ranges::begin(rng), ranges::end(rng)); } ~~~~~~~ With the type constraints expressed with the `CPP_template` macro, these two overloads are guaranteed to not be ambiguous. When compiling with C++20 concepts support, this uses real concept checks. On legacy compilers, it falls back to using `std::enable_if`. \subsection tutorial-future Range-v3 and the Future -------------------------------------------------------------------------------- Range-v3 formed the basis for the [Technical Specification on Ranges](https://www.iso.org/standard/70910.html), which has since been merged into the working draft and shipped with C++20 in the `std::ranges` namespace. More range adaptors are slated for inclusion in C++23 and beyond. The actions, as well as various utilities, have not yet been reviewed by the Committee, although the basic direction has already passed an initial review.
0
repos/range-v3
repos/range-v3/doc/Doxyfile.in
# Doxyfile 1.9.4 # This file describes the settings to be used by the documentation system # doxygen (www.doxygen.org) for a project. # # All text after a double hash (##) is considered a comment and is placed in # front of the TAG it is preceding. # # All text after a single hash (#) is considered a comment and will be ignored. # The format is: # TAG = value [value, ...] # For lists, items can also be appended using: # TAG += value [value, ...] # Values that contain spaces should be placed between quotes (\" \"). # # Note: # # Use doxygen to compare the used configuration file with the template # configuration file: # doxygen -x [configFile] # Use doxygen to compare the used configuration file with the template # configuration file without replacing the environment variables: # doxygen -x_noenv [configFile] #--------------------------------------------------------------------------- # Project related configuration options #--------------------------------------------------------------------------- # This tag specifies the encoding used for all characters in the configuration # file that follow. The default is UTF-8 which is also the encoding used for all # text before the first occurrence of this tag. Doxygen uses libiconv (or the # iconv built into libc) for the transcoding. See # https://www.gnu.org/software/libiconv/ for the list of possible encodings. # The default value is: UTF-8. DOXYFILE_ENCODING = UTF-8 # The PROJECT_NAME tag is a single word (or a sequence of words surrounded by # double-quotes, unless you are using Doxywizard) that should identify the # project for which the documentation is generated. This name is used in the # title of most generated pages and in a few other places. # The default value is: My Project. PROJECT_NAME = Range-v3 # The PROJECT_NUMBER tag can be used to enter a project or revision number. This # could be handy for archiving the generated documentation or if some version # control system is used. PROJECT_NUMBER = # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a # quick idea about the purpose of the project. Keep the description short. PROJECT_BRIEF = "Range algorithms, views, and actions for the Standard Library" # With the PROJECT_LOGO tag one can specify a logo or an icon that is included # in the documentation. The maximum height of the logo should not exceed 55 # pixels and the maximum width should not exceed 200 pixels. Doxygen will copy # the logo to the output directory. PROJECT_LOGO = # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path # into which the generated documentation will be written. If a relative path is # entered, it will be relative to the location where doxygen was started. If # left blank the current directory will be used. OUTPUT_DIRECTORY = # If the CREATE_SUBDIRS tag is set to YES then doxygen will create up to 4096 # sub-directories (in 2 levels) under the output directory of each output format # and will distribute the generated files over these directories. Enabling this # option can be useful when feeding doxygen a huge amount of source files, where # putting all generated files in the same directory would otherwise causes # performance problems for the file system. Adapt CREATE_SUBDIRS_LEVEL to # control the number of sub-directories. # The default value is: NO. CREATE_SUBDIRS = NO # Controls the number of sub-directories that will be created when # CREATE_SUBDIRS tag is set to YES. Level 0 represents 16 directories, and every # level increment doubles the number of directories, resulting in 4096 # directories at level 8 which is the default and also the maximum value. The # sub-directories are organized in 2 levels, the first level always has a fixed # numer of 16 directories. # Minimum value: 0, maximum value: 8, default value: 8. # This tag requires that the tag CREATE_SUBDIRS is set to YES. CREATE_SUBDIRS_LEVEL = 8 # If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII # characters to appear in the names of generated files. If set to NO, non-ASCII # characters will be escaped, for example _xE3_x81_x84 will be used for Unicode # U+3044. # The default value is: NO. ALLOW_UNICODE_NAMES = NO # The OUTPUT_LANGUAGE tag is used to specify the language in which all # documentation generated by doxygen is written. Doxygen will use this # information to generate all constant output in the proper language. # Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Bulgarian, # Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, Dutch, English # (United States), Esperanto, Farsi (Persian), Finnish, French, German, Greek, # Hindi, Hungarian, Indonesian, Italian, Japanese, Japanese-en (Japanese with # English messages), Korean, Korean-en (Korean with English messages), Latvian, # Lithuanian, Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, # Romanian, Russian, Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, # Swedish, Turkish, Ukrainian and Vietnamese. # The default value is: English. OUTPUT_LANGUAGE = English # If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member # descriptions after the members that are listed in the file and class # documentation (similar to Javadoc). Set to NO to disable this. # The default value is: YES. BRIEF_MEMBER_DESC = YES # If the REPEAT_BRIEF tag is set to YES, doxygen will prepend the brief # description of a member or function before the detailed description # # Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the # brief descriptions will be completely suppressed. # The default value is: YES. REPEAT_BRIEF = YES # This tag implements a quasi-intelligent brief description abbreviator that is # used to form the text in various listings. Each string in this list, if found # as the leading text of the brief description, will be stripped from the text # and the result, after processing the whole list, is used as the annotated # text. Otherwise, the brief description is used as-is. If left blank, the # following values are used ($name is automatically replaced with the name of # the entity):The $name class, The $name widget, The $name file, is, provides, # specifies, contains, represents, a, an and the. ABBREVIATE_BRIEF = "The $name class" \ "The $name widget" \ "The $name file" \ is \ provides \ specifies \ contains \ represents \ a \ an \ the # If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then # doxygen will generate a detailed section even if there is only a brief # description. # The default value is: NO. ALWAYS_DETAILED_SEC = NO # If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all # inherited members of a class in the documentation of that class as if those # members were ordinary class members. Constructors, destructors and assignment # operators of the base classes will not be shown. # The default value is: NO. INLINE_INHERITED_MEMB = NO # If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path # before files name in the file list and in the header files. If set to NO the # shortest path that makes the file name unique will be used # The default value is: YES. FULL_PATH_NAMES = YES # The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path. # Stripping is only done if one of the specified strings matches the left-hand # part of the path. The tag can be used to show relative paths in the file list. # If left blank the directory from which doxygen is run is used as the path to # strip. # # Note that you can specify absolute paths here, but also relative paths, which # will be relative from the directory where doxygen is started. # This tag requires that the tag FULL_PATH_NAMES is set to YES. STRIP_FROM_PATH = @Range-v3_SOURCE_DIR@/include \ @Range-v3_SOURCE_DIR@/doc # The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the # path mentioned in the documentation of a class, which tells the reader which # header file to include in order to use a class. If left blank only the name of # the header file containing the class definition is used. Otherwise one should # specify the list of include paths that are normally passed to the compiler # using the -I flag. STRIP_FROM_INC_PATH = @Range-v3_SOURCE_DIR@/include # If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but # less readable) file names. This can be useful is your file systems doesn't # support long names like on DOS, Mac, or CD-ROM. # The default value is: NO. SHORT_NAMES = NO # If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the # first line (until the first dot) of a Javadoc-style comment as the brief # description. If set to NO, the Javadoc-style will behave just like regular Qt- # style comments (thus requiring an explicit @brief command for a brief # description.) # The default value is: NO. JAVADOC_AUTOBRIEF = YES # If the JAVADOC_BANNER tag is set to YES then doxygen will interpret a line # such as # /*************** # as being the beginning of a Javadoc-style comment "banner". If set to NO, the # Javadoc-style will behave just like regular comments and it will not be # interpreted by doxygen. # The default value is: NO. JAVADOC_BANNER = NO # If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first # line (until the first dot) of a Qt-style comment as the brief description. If # set to NO, the Qt-style will behave just like regular Qt-style comments (thus # requiring an explicit \brief command for a brief description.) # The default value is: NO. QT_AUTOBRIEF = YES # The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a # multi-line C++ special comment block (i.e. a block of //! or /// comments) as # a brief description. This used to be the default behavior. The new default is # to treat a multi-line C++ comment block as a detailed description. Set this # tag to YES if you prefer the old behavior instead. # # Note that setting this tag to YES also means that rational rose comments are # not recognized any more. # The default value is: NO. MULTILINE_CPP_IS_BRIEF = YES # By default Python docstrings are displayed as preformatted text and doxygen's # special commands cannot be used. By setting PYTHON_DOCSTRING to NO the # doxygen's special commands can be used and the contents of the docstring # documentation blocks is shown as doxygen documentation. # The default value is: YES. PYTHON_DOCSTRING = YES # If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the # documentation from any documented member that it re-implements. # The default value is: YES. INHERIT_DOCS = NO # If the SEPARATE_MEMBER_PAGES tag is set to YES then doxygen will produce a new # page for each member. If set to NO, the documentation of a member will be part # of the file/class/namespace that contains it. # The default value is: NO. SEPARATE_MEMBER_PAGES = NO # The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen # uses this value to replace tabs by spaces in code fragments. # Minimum value: 1, maximum value: 16, default value: 4. TAB_SIZE = 4 # This tag can be used to specify a number of aliases that act as commands in # the documentation. An alias has the form: # name=value # For example adding # "sideeffect=@par Side Effects:^^" # will allow you to put the command \sideeffect (or @sideeffect) in the # documentation, which will result in a user-defined paragraph with heading # "Side Effects:". Note that you cannot put \n's in the value part of an alias # to insert newlines (in the resulting output). You can put ^^ in the value part # of an alias to insert a newline as if a physical newline was in the original # file. When you need a literal { or } or , in the value part of an alias you # have to escape them by means of a backslash (\), this can lead to conflicts # with the commands \{ and \} for these it is advised to use the version @{ and # @} or use a double escape (\\{ and \\}) ALIASES = # Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources # only. Doxygen will then generate output that is more tailored for C. For # instance, some of the names that are used will be different. The list of all # members will be omitted, etc. # The default value is: NO. OPTIMIZE_OUTPUT_FOR_C = NO # Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or # Python sources only. Doxygen will then generate output that is more tailored # for that language. For instance, namespaces will be presented as packages, # qualified scopes will look different, etc. # The default value is: NO. OPTIMIZE_OUTPUT_JAVA = NO # Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran # sources. Doxygen will then generate output that is tailored for Fortran. # The default value is: NO. OPTIMIZE_FOR_FORTRAN = NO # Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL # sources. Doxygen will then generate output that is tailored for VHDL. # The default value is: NO. OPTIMIZE_OUTPUT_VHDL = NO # Set the OPTIMIZE_OUTPUT_SLICE tag to YES if your project consists of Slice # sources only. Doxygen will then generate output that is more tailored for that # language. For instance, namespaces will be presented as modules, types will be # separated into more groups, etc. # The default value is: NO. OPTIMIZE_OUTPUT_SLICE = NO # Doxygen selects the parser to use depending on the extension of the files it # parses. With this tag you can assign which parser to use for a given # extension. Doxygen has a built-in mapping, but you can override or extend it # using this tag. The format is ext=language, where ext is a file extension, and # language is one of the parsers supported by doxygen: IDL, Java, JavaScript, # Csharp (C#), C, C++, Lex, D, PHP, md (Markdown), Objective-C, Python, Slice, # VHDL, Fortran (fixed format Fortran: FortranFixed, free formatted Fortran: # FortranFree, unknown formatted Fortran: Fortran. In the later case the parser # tries to guess whether the code is fixed or free formatted code, this is the # default for Fortran type files). For instance to make doxygen treat .inc files # as Fortran files (default is PHP), and .f files as C (default is Fortran), # use: inc=Fortran f=C. # # Note: For files without extension you can use no_extension as a placeholder. # # Note that for custom extensions you also need to set FILE_PATTERNS otherwise # the files are not read by doxygen. When specifying no_extension you should add # * to the FILE_PATTERNS. # # Note see also the list of default file extension mappings. EXTENSION_MAPPING = # If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments # according to the Markdown format, which allows for more readable # documentation. See https://daringfireball.net/projects/markdown/ for details. # The output of markdown processing is further processed by doxygen, so you can # mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in # case of backward compatibilities issues. # The default value is: YES. MARKDOWN_SUPPORT = YES # When the TOC_INCLUDE_HEADINGS tag is set to a non-zero value, all headings up # to that level are automatically included in the table of contents, even if # they do not have an id attribute. # Note: This feature currently applies only to Markdown headings. # Minimum value: 0, maximum value: 99, default value: 5. # This tag requires that the tag MARKDOWN_SUPPORT is set to YES. TOC_INCLUDE_HEADINGS = 5 # When enabled doxygen tries to link words that correspond to documented # classes, or namespaces to their corresponding documentation. Such a link can # be prevented in individual cases by putting a % sign in front of the word or # globally by setting AUTOLINK_SUPPORT to NO. # The default value is: YES. AUTOLINK_SUPPORT = YES # If you use STL classes (i.e. std::string, std::vector, etc.) but do not want # to include (a tag file for) the STL sources as input, then you should set this # tag to YES in order to let doxygen match functions declarations and # definitions whose arguments contain STL classes (e.g. func(std::string); # versus func(std::string) {}). This also make the inheritance and collaboration # diagrams that involve STL classes more complete and accurate. # The default value is: NO. BUILTIN_STL_SUPPORT = YES # If you use Microsoft's C++/CLI language, you should set this option to YES to # enable parsing support. # The default value is: NO. CPP_CLI_SUPPORT = NO # Set the SIP_SUPPORT tag to YES if your project consists of sip (see: # https://www.riverbankcomputing.com/software/sip/intro) sources only. Doxygen # will parse them like normal C++ but will assume all classes use public instead # of private inheritance when no explicit protection keyword is present. # The default value is: NO. SIP_SUPPORT = NO # For Microsoft's IDL there are propget and propput attributes to indicate # getter and setter methods for a property. Setting this option to YES will make # doxygen to replace the get and set methods by a property in the documentation. # This will only work if the methods are indeed getting or setting a simple # type. If this is not the case, or you want to show the methods anyway, you # should set this option to NO. # The default value is: YES. IDL_PROPERTY_SUPPORT = YES # If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC # tag is set to YES then doxygen will reuse the documentation of the first # member in the group (if any) for the other members of the group. By default # all members of a group must be documented explicitly. # The default value is: NO. DISTRIBUTE_GROUP_DOC = NO # If one adds a struct or class to a group and this option is enabled, then also # any nested class or struct is added to the same group. By default this option # is disabled and one has to add nested compounds explicitly via \ingroup. # The default value is: NO. GROUP_NESTED_COMPOUNDS = NO # Set the SUBGROUPING tag to YES to allow class member groups of the same type # (for instance a group of public functions) to be put as a subgroup of that # type (e.g. under the Public Functions section). Set it to NO to prevent # subgrouping. Alternatively, this can be done per class using the # \nosubgrouping command. # The default value is: YES. SUBGROUPING = NO # When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions # are shown inside the group in which they are included (e.g. using \ingroup) # instead of on a separate page (for HTML and Man pages) or section (for LaTeX # and RTF). # # Note that this feature does not work in combination with # SEPARATE_MEMBER_PAGES. # The default value is: NO. INLINE_GROUPED_CLASSES = NO # When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions # with only public data fields or simple typedef fields will be shown inline in # the documentation of the scope in which they are defined (i.e. file, # namespace, or group documentation), provided this scope is documented. If set # to NO, structs, classes, and unions are shown on a separate page (for HTML and # Man pages) or section (for LaTeX and RTF). # The default value is: NO. INLINE_SIMPLE_STRUCTS = NO # When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or # enum is documented as struct, union, or enum with the name of the typedef. So # typedef struct TypeS {} TypeT, will appear in the documentation as a struct # with name TypeT. When disabled the typedef will appear as a member of a file, # namespace, or class. And the struct will be named TypeS. This can typically be # useful for C code in case the coding convention dictates that all compound # types are typedef'ed and only the typedef is referenced, never the tag name. # The default value is: NO. TYPEDEF_HIDES_STRUCT = NO # The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This # cache is used to resolve symbols given their name and scope. Since this can be # an expensive process and often the same symbol appears multiple times in the # code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small # doxygen will become slower. If the cache is too large, memory is wasted. The # cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range # is 0..9, the default is 0, corresponding to a cache size of 2^16=65536 # symbols. At the end of a run doxygen will report the cache usage and suggest # the optimal cache size from a speed point of view. # Minimum value: 0, maximum value: 9, default value: 0. LOOKUP_CACHE_SIZE = 0 # The NUM_PROC_THREADS specifies the number of threads doxygen is allowed to use # during processing. When set to 0 doxygen will based this on the number of # cores available in the system. You can set it explicitly to a value larger # than 0 to get more control over the balance between CPU load and processing # speed. At this moment only the input processing can be done using multiple # threads. Since this is still an experimental feature the default is set to 1, # which effectively disables parallel processing. Please report any issues you # encounter. Generating dot graphs in parallel is controlled by the # DOT_NUM_THREADS setting. # Minimum value: 0, maximum value: 32, default value: 1. NUM_PROC_THREADS = 1 #--------------------------------------------------------------------------- # Build related configuration options #--------------------------------------------------------------------------- # If the EXTRACT_ALL tag is set to YES, doxygen will assume all entities in # documentation are documented, even if no documentation was available. Private # class members and static file members will be hidden unless the # EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES. # Note: This will also disable the warnings about undocumented members that are # normally produced when WARNINGS is set to YES. # The default value is: NO. EXTRACT_ALL = NO # If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will # be included in the documentation. # The default value is: NO. EXTRACT_PRIVATE = NO # If the EXTRACT_PRIV_VIRTUAL tag is set to YES, documented private virtual # methods of a class will be included in the documentation. # The default value is: NO. EXTRACT_PRIV_VIRTUAL = NO # If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal # scope will be included in the documentation. # The default value is: NO. EXTRACT_PACKAGE = NO # If the EXTRACT_STATIC tag is set to YES, all static members of a file will be # included in the documentation. # The default value is: NO. EXTRACT_STATIC = NO # If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined # locally in source files will be included in the documentation. If set to NO, # only classes defined in header files are included. Does not have any effect # for Java sources. # The default value is: YES. EXTRACT_LOCAL_CLASSES = YES # This flag is only useful for Objective-C code. If set to YES, local methods, # which are defined in the implementation section but not in the interface are # included in the documentation. If set to NO, only methods in the interface are # included. # The default value is: NO. EXTRACT_LOCAL_METHODS = NO # If this flag is set to YES, the members of anonymous namespaces will be # extracted and appear in the documentation as a namespace called # 'anonymous_namespace{file}', where file will be replaced with the base name of # the file that contains the anonymous namespace. By default anonymous namespace # are hidden. # The default value is: NO. EXTRACT_ANON_NSPACES = NO # If this flag is set to YES, the name of an unnamed parameter in a declaration # will be determined by the corresponding definition. By default unnamed # parameters remain unnamed in the output. # The default value is: YES. RESOLVE_UNNAMED_PARAMS = YES # If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all # undocumented members inside documented classes or files. If set to NO these # members will be included in the various overviews, but no documentation # section is generated. This option has no effect if EXTRACT_ALL is enabled. # The default value is: NO. HIDE_UNDOC_MEMBERS = NO # If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all # undocumented classes that are normally visible in the class hierarchy. If set # to NO, these classes will be included in the various overviews. This option # has no effect if EXTRACT_ALL is enabled. # The default value is: NO. HIDE_UNDOC_CLASSES = NO # If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend # declarations. If set to NO, these declarations will be included in the # documentation. # The default value is: NO. HIDE_FRIEND_COMPOUNDS = NO # If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any # documentation blocks found inside the body of a function. If set to NO, these # blocks will be appended to the function's detailed documentation block. # The default value is: NO. HIDE_IN_BODY_DOCS = NO # The INTERNAL_DOCS tag determines if documentation that is typed after a # \internal command is included. If the tag is set to NO then the documentation # will be excluded. Set it to YES to include the internal documentation. # The default value is: NO. INTERNAL_DOCS = NO # With the correct setting of option CASE_SENSE_NAMES doxygen will better be # able to match the capabilities of the underlying filesystem. In case the # filesystem is case sensitive (i.e. it supports files in the same directory # whose names only differ in casing), the option must be set to YES to properly # deal with such files in case they appear in the input. For filesystems that # are not case sensitive the option should be set to NO to properly deal with # output files written for symbols that only differ in casing, such as for two # classes, one named CLASS and the other named Class, and to also support # references to files without having to specify the exact matching casing. On # Windows (including Cygwin) and MacOS, users should typically set this option # to NO, whereas on Linux or other Unix flavors it should typically be set to # YES. # The default value is: system dependent. CASE_SENSE_NAMES = YES # If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with # their full class and namespace scopes in the documentation. If set to YES, the # scope will be hidden. # The default value is: NO. HIDE_SCOPE_NAMES = NO # If the HIDE_COMPOUND_REFERENCE tag is set to NO (default) then doxygen will # append additional text to a page's title, such as Class Reference. If set to # YES the compound reference will be hidden. # The default value is: NO. HIDE_COMPOUND_REFERENCE= NO # If the SHOW_HEADERFILE tag is set to YES then the documentation for a class # will show which file needs to be included to use the class. # The default value is: YES. SHOW_HEADERFILE = YES # If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of # the files that are included by a file in the documentation of that file. # The default value is: YES. SHOW_INCLUDE_FILES = NO # If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each # grouped member an include statement to the documentation, telling the reader # which file to include in order to use the member. # The default value is: NO. SHOW_GROUPED_MEMB_INC = YES # If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include # files with double quotes in the documentation rather than with sharp brackets. # The default value is: NO. FORCE_LOCAL_INCLUDES = NO # If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the # documentation for inline members. # The default value is: YES. INLINE_INFO = NO # If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the # (detailed) documentation of file and class members alphabetically by member # name. If set to NO, the members will appear in declaration order. # The default value is: YES. SORT_MEMBER_DOCS = YES # If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief # descriptions of file, namespace and class members alphabetically by member # name. If set to NO, the members will appear in declaration order. Note that # this will also influence the order of the classes in the class list. # The default value is: NO. SORT_BRIEF_DOCS = YES # If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the # (brief and detailed) documentation of class members so that constructors and # destructors are listed first. If set to NO the constructors will appear in the # respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS. # Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief # member documentation. # Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting # detailed member documentation. # The default value is: NO. SORT_MEMBERS_CTORS_1ST = NO # If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy # of group names into alphabetical order. If set to NO the group names will # appear in their defined order. # The default value is: NO. SORT_GROUP_NAMES = NO # If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by # fully-qualified names, including namespaces. If set to NO, the class list will # be sorted only by class name, not including the namespace part. # Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. # Note: This option applies only to the class list, not to the alphabetical # list. # The default value is: NO. SORT_BY_SCOPE_NAME = YES # If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper # type resolution of all parameters of a function it will reject a match between # the prototype and the implementation of a member function even if there is # only one candidate or it is obvious which candidate to choose by doing a # simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still # accept a match between prototype and implementation in such cases. # The default value is: NO. STRICT_PROTO_MATCHING = NO # The GENERATE_TODOLIST tag can be used to enable (YES) or disable (NO) the todo # list. This list is created by putting \todo commands in the documentation. # The default value is: YES. GENERATE_TODOLIST = YES # The GENERATE_TESTLIST tag can be used to enable (YES) or disable (NO) the test # list. This list is created by putting \test commands in the documentation. # The default value is: YES. GENERATE_TESTLIST = YES # The GENERATE_BUGLIST tag can be used to enable (YES) or disable (NO) the bug # list. This list is created by putting \bug commands in the documentation. # The default value is: YES. GENERATE_BUGLIST = YES # The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or disable (NO) # the deprecated list. This list is created by putting \deprecated commands in # the documentation. # The default value is: YES. GENERATE_DEPRECATEDLIST= YES # The ENABLED_SECTIONS tag can be used to enable conditional documentation # sections, marked by \if <section_label> ... \endif and \cond <section_label> # ... \endcond blocks. ENABLED_SECTIONS = # The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the # initial value of a variable or macro / define can have for it to appear in the # documentation. If the initializer consists of more lines than specified here # it will be hidden. Use a value of 0 to hide initializers completely. The # appearance of the value of individual variables and macros / defines can be # controlled using \showinitializer or \hideinitializer command in the # documentation regardless of this setting. # Minimum value: 0, maximum value: 10000, default value: 30. MAX_INITIALIZER_LINES = 30 # Set the SHOW_USED_FILES tag to NO to disable the list of files generated at # the bottom of the documentation of classes and structs. If set to YES, the # list will mention the files that were used to generate the documentation. # The default value is: YES. SHOW_USED_FILES = NO # Set the SHOW_FILES tag to NO to disable the generation of the Files page. This # will remove the Files entry from the Quick Index and from the Folder Tree View # (if specified). # The default value is: YES. SHOW_FILES = YES # Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces # page. This will remove the Namespaces entry from the Quick Index and from the # Folder Tree View (if specified). # The default value is: YES. SHOW_NAMESPACES = YES # The FILE_VERSION_FILTER tag can be used to specify a program or script that # doxygen should invoke to get the current version for each file (typically from # the version control system). Doxygen will invoke the program by executing (via # popen()) the command command input-file, where command is the value of the # FILE_VERSION_FILTER tag, and input-file is the name of an input file provided # by doxygen. Whatever the program writes to standard output is used as the file # version. For an example see the documentation. FILE_VERSION_FILTER = # The LAYOUT_FILE tag can be used to specify a layout file which will be parsed # by doxygen. The layout file controls the global structure of the generated # output files in an output format independent way. To create the layout file # that represents doxygen's defaults, run doxygen with the -l option. You can # optionally specify a file name after the option, if omitted DoxygenLayout.xml # will be used as the name of the layout file. See also section "Changing the # layout of pages" for information. # # Note that if you run doxygen from a directory containing a file called # DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE # tag is left empty. LAYOUT_FILE = @Range-v3_SOURCE_DIR@/doc/layout.xml # The CITE_BIB_FILES tag can be used to specify one or more bib files containing # the reference definitions. This must be a list of .bib files. The .bib # extension is automatically appended if omitted. This requires the bibtex tool # to be installed. See also https://en.wikipedia.org/wiki/BibTeX for more info. # For LaTeX the style of the bibliography can be controlled using # LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the # search path. See also \cite for info how to create references. CITE_BIB_FILES = #--------------------------------------------------------------------------- # Configuration options related to warning and progress messages #--------------------------------------------------------------------------- # The QUIET tag can be used to turn on/off the messages that are generated to # standard output by doxygen. If QUIET is set to YES this implies that the # messages are off. # The default value is: NO. QUIET = NO # The WARNINGS tag can be used to turn on/off the warning messages that are # generated to standard error (stderr) by doxygen. If WARNINGS is set to YES # this implies that the warnings are on. # # Tip: Turn warnings on while writing the documentation. # The default value is: YES. WARNINGS = YES # If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate # warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag # will automatically be disabled. # The default value is: YES. WARN_IF_UNDOCUMENTED = NO # If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for # potential errors in the documentation, such as documenting some parameters in # a documented function twice, or documenting parameters that don't exist or # using markup commands wrongly. # The default value is: YES. WARN_IF_DOC_ERROR = YES # If WARN_IF_INCOMPLETE_DOC is set to YES, doxygen will warn about incomplete # function parameter documentation. If set to NO, doxygen will accept that some # parameters have no documentation without warning. # The default value is: YES. WARN_IF_INCOMPLETE_DOC = YES # This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that # are documented, but have no documentation for their parameters or return # value. If set to NO, doxygen will only warn about wrong parameter # documentation, but not about the absence of documentation. If EXTRACT_ALL is # set to YES then this flag will automatically be disabled. See also # WARN_IF_INCOMPLETE_DOC # The default value is: NO. WARN_NO_PARAMDOC = NO # If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when # a warning is encountered. If the WARN_AS_ERROR tag is set to FAIL_ON_WARNINGS # then doxygen will continue running as if WARN_AS_ERROR tag is set to NO, but # at the end of the doxygen process doxygen will return with a non-zero status. # Possible values are: NO, YES and FAIL_ON_WARNINGS. # The default value is: NO. WARN_AS_ERROR = NO # The WARN_FORMAT tag determines the format of the warning messages that doxygen # can produce. The string should contain the $file, $line, and $text tags, which # will be replaced by the file and line number from which the warning originated # and the warning text. Optionally the format may contain $version, which will # be replaced by the version of the file (if it could be obtained via # FILE_VERSION_FILTER) # See also: WARN_LINE_FORMAT # The default value is: $file:$line: $text. WARN_FORMAT = "$file:$line: $text" # In the $text part of the WARN_FORMAT command it is possible that a reference # to a more specific place is given. To make it easier to jump to this place # (outside of doxygen) the user can define a custom "cut" / "paste" string. # Example: # WARN_LINE_FORMAT = "'vi $file +$line'" # See also: WARN_FORMAT # The default value is: at line $line of file $file. WARN_LINE_FORMAT = "at line $line of file $file" # The WARN_LOGFILE tag can be used to specify a file to which warning and error # messages should be written. If left blank the output is written to standard # error (stderr). In case the file specified cannot be opened for writing the # warning and error messages are written to standard error. When as file - is # specified the warning and error messages are written to standard output # (stdout). WARN_LOGFILE = #--------------------------------------------------------------------------- # Configuration options related to the input files #--------------------------------------------------------------------------- # The INPUT tag is used to specify the files and/or directories that contain # documented source files. You may enter file names like myfile.cpp or # directories like /usr/src/myproject. Separate the files or directories with # spaces. See also FILE_PATTERNS and EXTENSION_MAPPING # Note: If this tag is empty the current directory is searched. INPUT = @Range-v3_SOURCE_DIR@/include \ @Range-v3_SOURCE_DIR@/doc/index.md \ @Range-v3_SOURCE_DIR@/doc/examples.md \ @Range-v3_SOURCE_DIR@/doc/release_notes.md # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses # libiconv (or the iconv built into libc) for the transcoding. See the libiconv # documentation (see: # https://www.gnu.org/software/libiconv/) for the list of possible encodings. # The default value is: UTF-8. INPUT_ENCODING = UTF-8 # If the value of the INPUT tag contains directories, you can use the # FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and # *.h) to filter out the source-files in the directories. # # Note that for custom extensions or not directly supported extensions you also # need to set EXTENSION_MAPPING for the extension otherwise the files are not # read by doxygen. # # Note the list of default checked file patterns might differ from the list of # default file extension mappings. # # If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp, # *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, # *.hh, *.hxx, *.hpp, *.h++, *.l, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, # *.inc, *.m, *.markdown, *.md, *.mm, *.dox (to be provided as doxygen C # comment), *.py, *.pyw, *.f90, *.f95, *.f03, *.f08, *.f18, *.f, *.for, *.vhd, # *.vhdl, *.ucf, *.qsf and *.ice. FILE_PATTERNS = *.hpp \ *.md # The RECURSIVE tag can be used to specify whether or not subdirectories should # be searched for input files as well. # The default value is: NO. RECURSIVE = YES # The EXCLUDE tag can be used to specify files and/or directories that should be # excluded from the INPUT source files. This way you can easily exclude a # subdirectory from a directory tree whose root is specified with the INPUT tag. # # Note that relative paths are relative to the directory from which doxygen is # run. EXCLUDE = @Range-v3_SOURCE_DIR@/include/range/v3/detail \ @Range-v3_SOURCE_DIR@/include/range/v3/algorithm/aux_ \ @Range-v3_SOURCE_DIR@/include/range/v3/algorithm/tagspec.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/at.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/back.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/begin_end.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/data.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/distance.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/empty.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/front.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/getlines.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/index.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/istream_range.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/iterator_range.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/range_access.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/range_concepts.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/range_traits.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/size.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/span.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/to_container.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/to_container.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/utility/associated_types.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/utility/basic_iterator.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/utility/common_iterator.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/utility/concepts.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/utility/counted_iterator.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/utility/dangling.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/utility/functional.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/utility/infinity.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/utility/invoke.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/utility/iterator_concepts.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/utility/iterator_traits.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/utility/iterator.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/utility/nullptr_v.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/utility/semiregular.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/utility/tagged_pair.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/utility/tagged_tuple.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/utility/unreachable.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/utility/view_adaptor.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/view_adaptor.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/view_facade.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/view_interface.hpp \ @Range-v3_SOURCE_DIR@/include/range/v3/view/bounded.hpp # The EXCLUDE_SYMLINKS tag can be used to select whether or not files or # directories that are symbolic links (a Unix file system feature) are excluded # from the input. # The default value is: NO. EXCLUDE_SYMLINKS = NO # If the value of the INPUT tag contains directories, you can use the # EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude # certain files from those directories. # # Note that the wildcards are matched against the file with absolute path, so to # exclude all test directories for example use the pattern */test/* EXCLUDE_PATTERNS = # The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names # (namespaces, classes, functions, etc.) that should be excluded from the # output. The symbol name can be a fully qualified name, a word, or if the # wildcard * is used, a substring. Examples: ANamespace, AClass, # ANamespace::AClass, ANamespace::*Test # # Note that the wildcards are matched against the file with absolute path, so to # exclude all test directories use the pattern */test/* EXCLUDE_SYMBOLS = # The EXAMPLE_PATH tag can be used to specify one or more files or directories # that contain example code fragments that are included (see the \include # command). EXAMPLE_PATH = @Range-v3_SOURCE_DIR@/example \ @Range-v3_SOURCE_DIR@/test # If the value of the EXAMPLE_PATH tag contains directories, you can use the # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and # *.h) to filter out the source-files in the directories. If left blank all # files are included. EXAMPLE_PATTERNS = * # If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be # searched for input files to be used with the \include or \dontinclude commands # irrespective of the value of the RECURSIVE tag. # The default value is: NO. EXAMPLE_RECURSIVE = YES # The IMAGE_PATH tag can be used to specify one or more files or directories # that contain images that are to be included in the documentation (see the # \image command). IMAGE_PATH = @Range-v3_BINARY_DIR@/image # The INPUT_FILTER tag can be used to specify a program that doxygen should # invoke to filter for each input file. Doxygen will invoke the filter program # by executing (via popen()) the command: # # <filter> <input-file> # # where <filter> is the value of the INPUT_FILTER tag, and <input-file> is the # name of an input file. Doxygen will then use the output that the filter # program writes to standard output. If FILTER_PATTERNS is specified, this tag # will be ignored. # # Note that the filter must not add or remove lines; it is applied before the # code is scanned, but not when the output code is generated. If lines are added # or removed, the anchors will not be placed correctly. # # Note that for custom extensions or not directly supported extensions you also # need to set EXTENSION_MAPPING for the extension otherwise the files are not # properly processed by doxygen. INPUT_FILTER = # The FILTER_PATTERNS tag can be used to specify filters on a per file pattern # basis. Doxygen will compare the file name with each pattern and apply the # filter if there is a match. The filters are a list of the form: pattern=filter # (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how # filters are used. If the FILTER_PATTERNS tag is empty or if none of the # patterns match the file name, INPUT_FILTER is applied. # # Note that for custom extensions or not directly supported extensions you also # need to set EXTENSION_MAPPING for the extension otherwise the files are not # properly processed by doxygen. FILTER_PATTERNS = # If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using # INPUT_FILTER) will also be used to filter the input files that are used for # producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES). # The default value is: NO. FILTER_SOURCE_FILES = NO # The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file # pattern. A pattern will override the setting for FILTER_PATTERN (if any) and # it is also possible to disable source filtering for a specific pattern using # *.ext= (so without naming a filter). # This tag requires that the tag FILTER_SOURCE_FILES is set to YES. FILTER_SOURCE_PATTERNS = # If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that # is part of the input, its contents will be placed on the main page # (index.html). This can be useful if you have a project on for instance GitHub # and want to reuse the introduction page also for the doxygen output. USE_MDFILE_AS_MAINPAGE = #--------------------------------------------------------------------------- # Configuration options related to source browsing #--------------------------------------------------------------------------- # If the SOURCE_BROWSER tag is set to YES then a list of source files will be # generated. Documented entities will be cross-referenced with these sources. # # Note: To get rid of all source code in the generated output, make sure that # also VERBATIM_HEADERS is set to NO. # The default value is: NO. SOURCE_BROWSER = NO # Setting the INLINE_SOURCES tag to YES will include the body of functions, # classes and enums directly into the documentation. # The default value is: NO. INLINE_SOURCES = NO # Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any # special comment blocks from generated source code fragments. Normal C, C++ and # Fortran comments will always remain visible. # The default value is: YES. STRIP_CODE_COMMENTS = YES # If the REFERENCED_BY_RELATION tag is set to YES then for each documented # entity all documented functions referencing it will be listed. # The default value is: NO. REFERENCED_BY_RELATION = YES # If the REFERENCES_RELATION tag is set to YES then for each documented function # all documented entities called/used by that function will be listed. # The default value is: NO. REFERENCES_RELATION = YES # If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set # to YES then the hyperlinks from functions in REFERENCES_RELATION and # REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will # link to the documentation. # The default value is: YES. REFERENCES_LINK_SOURCE = YES # If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the # source code will show a tooltip with additional information such as prototype, # brief description and links to the definition and documentation. Since this # will make the HTML file larger and loading of large files a bit slower, you # can opt to disable this feature. # The default value is: YES. # This tag requires that the tag SOURCE_BROWSER is set to YES. SOURCE_TOOLTIPS = YES # If the USE_HTAGS tag is set to YES then the references to source code will # point to the HTML generated by the htags(1) tool instead of doxygen built-in # source browser. The htags tool is part of GNU's global source tagging system # (see https://www.gnu.org/software/global/global.html). You will need version # 4.8.6 or higher. # # To use it do the following: # - Install the latest version of global # - Enable SOURCE_BROWSER and USE_HTAGS in the configuration file # - Make sure the INPUT points to the root of the source tree # - Run doxygen as normal # # Doxygen will invoke htags (and that will in turn invoke gtags), so these # tools must be available from the command line (i.e. in the search path). # # The result: instead of the source browser generated by doxygen, the links to # source code will now point to the output of htags. # The default value is: NO. # This tag requires that the tag SOURCE_BROWSER is set to YES. USE_HTAGS = NO # If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a # verbatim copy of the header file for each class for which an include is # specified. Set to NO to disable this. # See also: Section \class. # The default value is: YES. VERBATIM_HEADERS = NO # If the CLANG_ASSISTED_PARSING tag is set to YES then doxygen will use the # clang parser (see: # http://clang.llvm.org/) for more accurate parsing at the cost of reduced # performance. This can be particularly helpful with template rich C++ code for # which doxygen's built-in parser lacks the necessary type information. # Note: The availability of this option depends on whether or not doxygen was # generated with the -Duse_libclang=ON option for CMake. # The default value is: NO. CLANG_ASSISTED_PARSING = NO # If the CLANG_ASSISTED_PARSING tag is set to YES and the CLANG_ADD_INC_PATHS # tag is set to YES then doxygen will add the directory of each input to the # include path. # The default value is: YES. # This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES. CLANG_ADD_INC_PATHS = YES # If clang assisted parsing is enabled you can provide the compiler with command # line options that you would normally use when invoking the compiler. Note that # the include paths will already be set by doxygen for the files and directories # specified with INPUT and INCLUDE_PATH. # This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES. CLANG_OPTIONS = # If clang assisted parsing is enabled you can provide the clang parser with the # path to the directory containing a file called compile_commands.json. This # file is the compilation database (see: # http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html) containing the # options used when the source files were built. This is equivalent to # specifying the -p option to a clang tool, such as clang-check. These options # will then be passed to the parser. Any options specified with CLANG_OPTIONS # will be added as well. # Note: The availability of this option depends on whether or not doxygen was # generated with the -Duse_libclang=ON option for CMake. CLANG_DATABASE_PATH = #--------------------------------------------------------------------------- # Configuration options related to the alphabetical class index #--------------------------------------------------------------------------- # If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all # compounds will be generated. Enable this if the project contains a lot of # classes, structs, unions or interfaces. # The default value is: YES. ALPHABETICAL_INDEX = NO # In case all classes in a project start with a common prefix, all classes will # be put under the same header in the alphabetical index. The IGNORE_PREFIX tag # can be used to specify a prefix (or a list of prefixes) that should be ignored # while generating the index headers. # This tag requires that the tag ALPHABETICAL_INDEX is set to YES. IGNORE_PREFIX = #--------------------------------------------------------------------------- # Configuration options related to the HTML output #--------------------------------------------------------------------------- # If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output # The default value is: YES. GENERATE_HTML = YES # The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a # relative path is entered the value of OUTPUT_DIRECTORY will be put in front of # it. # The default directory is: html. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_OUTPUT = html # The HTML_FILE_EXTENSION tag can be used to specify the file extension for each # generated HTML page (for example: .htm, .php, .asp). # The default value is: .html. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_FILE_EXTENSION = .html # The HTML_HEADER tag can be used to specify a user-defined HTML header file for # each generated HTML page. If the tag is left blank doxygen will generate a # standard header. # # To get valid HTML the header file that includes any scripts and style sheets # that doxygen needs, which is dependent on the configuration options used (e.g. # the setting GENERATE_TREEVIEW). It is highly recommended to start with a # default header using # doxygen -w html new_header.html new_footer.html new_stylesheet.css # YourConfigFile # and then modify the file new_header.html. See also section "Doxygen usage" # for information on how to generate the default header that doxygen normally # uses. # Note: The header is subject to change so you typically have to regenerate the # default header when upgrading to a newer version of doxygen. For a description # of the possible markers and block names see the documentation. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_HEADER = # The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each # generated HTML page. If the tag is left blank doxygen will generate a standard # footer. See HTML_HEADER for more information on how to generate a default # footer and what special commands can be used inside the footer. See also # section "Doxygen usage" for information on how to generate the default footer # that doxygen normally uses. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_FOOTER = # The HTML_STYLESHEET tag can be used to specify a user-defined cascading style # sheet that is used by each HTML page. It can be used to fine-tune the look of # the HTML output. If left blank doxygen will generate a default style sheet. # See also section "Doxygen usage" for information on how to generate the style # sheet that doxygen normally uses. # Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as # it is more robust and this tag (HTML_STYLESHEET) will in the future become # obsolete. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_STYLESHEET = # The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined # cascading style sheets that are included after the standard style sheets # created by doxygen. Using this option one can overrule certain style aspects. # This is preferred over using HTML_STYLESHEET since it does not replace the # standard style sheet and is therefore more robust against future updates. # Doxygen will copy the style sheet files to the output directory. # Note: The order of the extra style sheet files is of importance (e.g. the last # style sheet in the list overrules the setting of the previous ones in the # list). For an example see the documentation. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_EXTRA_STYLESHEET = # The HTML_EXTRA_FILES tag can be used to specify one or more extra images or # other source files which should be copied to the HTML output directory. Note # that these files will be copied to the base HTML output directory. Use the # $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these # files. In the HTML_STYLESHEET file, use the file name only. Also note that the # files will be copied as-is; there are no commands or markers available. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_EXTRA_FILES = # The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen # will adjust the colors in the style sheet and background images according to # this color. Hue is specified as an angle on a color-wheel, see # https://en.wikipedia.org/wiki/Hue for more information. For instance the value # 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300 # purple, and 360 is red again. # Minimum value: 0, maximum value: 359, default value: 220. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_COLORSTYLE_HUE = 75 # The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors # in the HTML output. For a value of 0 the output will use gray-scales only. A # value of 255 will produce the most vivid colors. # Minimum value: 0, maximum value: 255, default value: 100. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_COLORSTYLE_SAT = 100 # The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the # luminance component of the colors in the HTML output. Values below 100 # gradually make the output lighter, whereas values above 100 make the output # darker. The value divided by 100 is the actual gamma applied, so 80 represents # a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not # change the gamma. # Minimum value: 40, maximum value: 240, default value: 80. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_COLORSTYLE_GAMMA = 80 # If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML # page will contain the date and time when the page was generated. Setting this # to YES can help to show when doxygen was last run and thus if the # documentation is up to date. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_TIMESTAMP = NO # If the HTML_DYNAMIC_MENUS tag is set to YES then the generated HTML # documentation will contain a main index with vertical navigation menus that # are dynamically created via JavaScript. If disabled, the navigation index will # consists of multiple levels of tabs that are statically embedded in every HTML # page. Disable this option to support browsers that do not have JavaScript, # like the Qt help browser. # The default value is: YES. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_DYNAMIC_MENUS = YES # If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML # documentation will contain sections that can be hidden and shown after the # page has loaded. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_DYNAMIC_SECTIONS = YES # With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries # shown in the various tree structured indices initially; the user can expand # and collapse entries dynamically later on. Doxygen will expand the tree to # such a level that at most the specified number of entries are visible (unless # a fully collapsed tree already exceeds this amount). So setting the number of # entries 1 will produce a full collapsed tree by default. 0 is a special value # representing an infinite number of entries and will result in a full expanded # tree by default. # Minimum value: 0, maximum value: 9999, default value: 100. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_INDEX_NUM_ENTRIES = 0 # If the GENERATE_DOCSET tag is set to YES, additional index files will be # generated that can be used as input for Apple's Xcode 3 integrated development # environment (see: # https://developer.apple.com/xcode/), introduced with OSX 10.5 (Leopard). To # create a documentation set, doxygen will generate a Makefile in the HTML # output directory. Running make will produce the docset in that directory and # running make install will install the docset in # ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at # startup. See https://developer.apple.com/library/archive/featuredarticles/Doxy # genXcode/_index.html for more information. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_DOCSET = NO # This tag determines the name of the docset feed. A documentation feed provides # an umbrella under which multiple documentation sets from a single provider # (such as a company or product suite) can be grouped. # The default value is: Doxygen generated docs. # This tag requires that the tag GENERATE_DOCSET is set to YES. DOCSET_FEEDNAME = "Doxygen generated docs" # This tag determines the URL of the docset feed. A documentation feed provides # an umbrella under which multiple documentation sets from a single provider # (such as a company or product suite) can be grouped. # This tag requires that the tag GENERATE_DOCSET is set to YES. DOCSET_FEEDURL = # This tag specifies a string that should uniquely identify the documentation # set bundle. This should be a reverse domain-name style string, e.g. # com.mycompany.MyDocSet. Doxygen will append .docset to the name. # The default value is: org.doxygen.Project. # This tag requires that the tag GENERATE_DOCSET is set to YES. DOCSET_BUNDLE_ID = org.doxygen.Project # The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify # the documentation publisher. This should be a reverse domain-name style # string, e.g. com.mycompany.MyDocSet.documentation. # The default value is: org.doxygen.Publisher. # This tag requires that the tag GENERATE_DOCSET is set to YES. DOCSET_PUBLISHER_ID = org.doxygen.Publisher # The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher. # The default value is: Publisher. # This tag requires that the tag GENERATE_DOCSET is set to YES. DOCSET_PUBLISHER_NAME = Publisher # If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three # additional HTML index files: index.hhp, index.hhc, and index.hhk. The # index.hhp is a project file that can be read by Microsoft's HTML Help Workshop # on Windows. In the beginning of 2021 Microsoft took the original page, with # a.o. the download links, offline the HTML help workshop was already many years # in maintenance mode). You can download the HTML help workshop from the web # archives at Installation executable (see: # http://web.archive.org/web/20160201063255/http://download.microsoft.com/downlo # ad/0/A/9/0A939EF6-E31C-430F-A3DF-DFAE7960D564/htmlhelp.exe). # # The HTML Help Workshop contains a compiler that can convert all HTML output # generated by doxygen into a single compiled HTML file (.chm). Compiled HTML # files are now used as the Windows 98 help format, and will replace the old # Windows help format (.hlp) on all Windows platforms in the future. Compressed # HTML files also contain an index, a table of contents, and you can search for # words in the documentation. The HTML workshop also contains a viewer for # compressed HTML files. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_HTMLHELP = NO # The CHM_FILE tag can be used to specify the file name of the resulting .chm # file. You can add a path in front of the file if the result should not be # written to the html output directory. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. CHM_FILE = # The HHC_LOCATION tag can be used to specify the location (absolute path # including file name) of the HTML help compiler (hhc.exe). If non-empty, # doxygen will try to run the HTML help compiler on the generated index.hhp. # The file has to be specified with full path. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. HHC_LOCATION = # The GENERATE_CHI flag controls if a separate .chi index file is generated # (YES) or that it should be included in the main .chm file (NO). # The default value is: NO. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. GENERATE_CHI = NO # The CHM_INDEX_ENCODING is used to encode HtmlHelp index (hhk), content (hhc) # and project file content. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. CHM_INDEX_ENCODING = # The BINARY_TOC flag controls whether a binary table of contents is generated # (YES) or a normal table of contents (NO) in the .chm file. Furthermore it # enables the Previous and Next buttons. # The default value is: NO. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. BINARY_TOC = NO # The TOC_EXPAND flag can be set to YES to add extra items for group members to # the table of contents of the HTML help documentation and to the tree view. # The default value is: NO. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. TOC_EXPAND = NO # If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and # QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that # can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help # (.qch) of the generated HTML documentation. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_QHP = NO # If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify # the file name of the resulting .qch file. The path specified is relative to # the HTML output folder. # This tag requires that the tag GENERATE_QHP is set to YES. QCH_FILE = # The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help # Project output. For more information please see Qt Help Project / Namespace # (see: # https://doc.qt.io/archives/qt-4.8/qthelpproject.html#namespace). # The default value is: org.doxygen.Project. # This tag requires that the tag GENERATE_QHP is set to YES. QHP_NAMESPACE = org.doxygen.Project # The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt # Help Project output. For more information please see Qt Help Project / Virtual # Folders (see: # https://doc.qt.io/archives/qt-4.8/qthelpproject.html#virtual-folders). # The default value is: doc. # This tag requires that the tag GENERATE_QHP is set to YES. QHP_VIRTUAL_FOLDER = doc # If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom # filter to add. For more information please see Qt Help Project / Custom # Filters (see: # https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-filters). # This tag requires that the tag GENERATE_QHP is set to YES. QHP_CUST_FILTER_NAME = # The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the # custom filter to add. For more information please see Qt Help Project / Custom # Filters (see: # https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-filters). # This tag requires that the tag GENERATE_QHP is set to YES. QHP_CUST_FILTER_ATTRS = # The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this # project's filter section matches. Qt Help Project / Filter Attributes (see: # https://doc.qt.io/archives/qt-4.8/qthelpproject.html#filter-attributes). # This tag requires that the tag GENERATE_QHP is set to YES. QHP_SECT_FILTER_ATTRS = # The QHG_LOCATION tag can be used to specify the location (absolute path # including file name) of Qt's qhelpgenerator. If non-empty doxygen will try to # run qhelpgenerator on the generated .qhp file. # This tag requires that the tag GENERATE_QHP is set to YES. QHG_LOCATION = # If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be # generated, together with the HTML files, they form an Eclipse help plugin. To # install this plugin and make it available under the help contents menu in # Eclipse, the contents of the directory containing the HTML and XML files needs # to be copied into the plugins directory of eclipse. The name of the directory # within the plugins directory should be the same as the ECLIPSE_DOC_ID value. # After copying Eclipse needs to be restarted before the help appears. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_ECLIPSEHELP = NO # A unique identifier for the Eclipse help plugin. When installing the plugin # the directory name containing the HTML and XML files should also have this # name. Each documentation set should have its own identifier. # The default value is: org.doxygen.Project. # This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES. ECLIPSE_DOC_ID = org.doxygen.Project # If you want full control over the layout of the generated HTML pages it might # be necessary to disable the index and replace it with your own. The # DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top # of each HTML page. A value of NO enables the index and the value YES disables # it. Since the tabs in the index contain the same information as the navigation # tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. DISABLE_INDEX = YES # The GENERATE_TREEVIEW tag is used to specify whether a tree-like index # structure should be generated to display hierarchical information. If the tag # value is set to YES, a side panel will be generated containing a tree-like # index structure (just like the one that is generated for HTML Help). For this # to work a browser that supports JavaScript, DHTML, CSS and frames is required # (i.e. any modern browser). Windows users are probably better off using the # HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can # further fine tune the look of the index (see "Fine-tuning the output"). As an # example, the default style sheet generated by doxygen has an example that # shows how to put an image at the root of the tree instead of the PROJECT_NAME. # Since the tree basically has the same information as the tab index, you could # consider setting DISABLE_INDEX to YES when enabling this option. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_TREEVIEW = YES # When both GENERATE_TREEVIEW and DISABLE_INDEX are set to YES, then the # FULL_SIDEBAR option determines if the side bar is limited to only the treeview # area (value NO) or if it should extend to the full height of the window (value # YES). Setting this to YES gives a layout similar to # https://docs.readthedocs.io with more room for contents, but less room for the # project logo, title, and description. If either GENERATE_TREEVIEW or # DISABLE_INDEX is set to NO, this option has no effect. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. FULL_SIDEBAR = NO # The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that # doxygen will group on one line in the generated HTML documentation. # # Note that a value of 0 will completely suppress the enum values from appearing # in the overview section. # Minimum value: 0, maximum value: 20, default value: 4. # This tag requires that the tag GENERATE_HTML is set to YES. ENUM_VALUES_PER_LINE = 4 # If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used # to set the initial width (in pixels) of the frame in which the tree is shown. # Minimum value: 0, maximum value: 1500, default value: 250. # This tag requires that the tag GENERATE_HTML is set to YES. TREEVIEW_WIDTH = 270 # If the EXT_LINKS_IN_WINDOW option is set to YES, doxygen will open links to # external symbols imported via tag files in a separate window. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. EXT_LINKS_IN_WINDOW = NO # If the OBFUSCATE_EMAILS tag is set to YES, doxygen will obfuscate email # addresses. # The default value is: YES. # This tag requires that the tag GENERATE_HTML is set to YES. OBFUSCATE_EMAILS = YES # If the HTML_FORMULA_FORMAT option is set to svg, doxygen will use the pdf2svg # tool (see https://github.com/dawbarton/pdf2svg) or inkscape (see # https://inkscape.org) to generate formulas as SVG images instead of PNGs for # the HTML output. These images will generally look nicer at scaled resolutions. # Possible values are: png (the default) and svg (looks nicer but requires the # pdf2svg or inkscape tool). # The default value is: png. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_FORMULA_FORMAT = png # Use this tag to change the font size of LaTeX formulas included as images in # the HTML documentation. When you change the font size after a successful # doxygen run you need to manually remove any form_*.png images from the HTML # output directory to force them to be regenerated. # Minimum value: 8, maximum value: 50, default value: 10. # This tag requires that the tag GENERATE_HTML is set to YES. FORMULA_FONTSIZE = 10 # Use the FORMULA_TRANSPARENT tag to determine whether or not the images # generated for formulas are transparent PNGs. Transparent PNGs are not # supported properly for IE 6.0, but are supported on all modern browsers. # # Note that when changing this option you need to delete any form_*.png files in # the HTML output directory before the changes have effect. # The default value is: YES. # This tag requires that the tag GENERATE_HTML is set to YES. FORMULA_TRANSPARENT = YES # The FORMULA_MACROFILE can contain LaTeX \newcommand and \renewcommand commands # to create new LaTeX commands to be used in formulas as building blocks. See # the section "Including formulas" for details. FORMULA_MACROFILE = # Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see # https://www.mathjax.org) which uses client side JavaScript for the rendering # instead of using pre-rendered bitmaps. Use this if you do not have LaTeX # installed or if you want to formulas look prettier in the HTML output. When # enabled you may also need to install MathJax separately and configure the path # to it using the MATHJAX_RELPATH option. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. USE_MATHJAX = NO # With MATHJAX_VERSION it is possible to specify the MathJax version to be used. # Note that the different versions of MathJax have different requirements with # regards to the different settings, so it is possible that also other MathJax # settings have to be changed when switching between the different MathJax # versions. # Possible values are: MathJax_2 and MathJax_3. # The default value is: MathJax_2. # This tag requires that the tag USE_MATHJAX is set to YES. MATHJAX_VERSION = MathJax_2 # When MathJax is enabled you can set the default output format to be used for # the MathJax output. For more details about the output format see MathJax # version 2 (see: # http://docs.mathjax.org/en/v2.7-latest/output.html) and MathJax version 3 # (see: # http://docs.mathjax.org/en/latest/web/components/output.html). # Possible values are: HTML-CSS (which is slower, but has the best # compatibility. This is the name for Mathjax version 2, for MathJax version 3 # this will be translated into chtml), NativeMML (i.e. MathML. Only supported # for NathJax 2. For MathJax version 3 chtml will be used instead.), chtml (This # is the name for Mathjax version 3, for MathJax version 2 this will be # translated into HTML-CSS) and SVG. # The default value is: HTML-CSS. # This tag requires that the tag USE_MATHJAX is set to YES. MATHJAX_FORMAT = HTML-CSS # When MathJax is enabled you need to specify the location relative to the HTML # output directory using the MATHJAX_RELPATH option. The destination directory # should contain the MathJax.js script. For instance, if the mathjax directory # is located at the same level as the HTML output directory, then # MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax # Content Delivery Network so you can quickly see the result without installing # MathJax. However, it is strongly recommended to install a local copy of # MathJax from https://www.mathjax.org before deployment. The default value is: # - in case of MathJax version 2: https://cdn.jsdelivr.net/npm/mathjax@2 # - in case of MathJax version 3: https://cdn.jsdelivr.net/npm/mathjax@3 # This tag requires that the tag USE_MATHJAX is set to YES. MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest # The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax # extension names that should be enabled during MathJax rendering. For example # for MathJax version 2 (see https://docs.mathjax.org/en/v2.7-latest/tex.html # #tex-and-latex-extensions): # MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols # For example for MathJax version 3 (see # http://docs.mathjax.org/en/latest/input/tex/extensions/index.html): # MATHJAX_EXTENSIONS = ams # This tag requires that the tag USE_MATHJAX is set to YES. MATHJAX_EXTENSIONS = # The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces # of code that will be used on startup of the MathJax code. See the MathJax site # (see: # http://docs.mathjax.org/en/v2.7-latest/output.html) for more details. For an # example see the documentation. # This tag requires that the tag USE_MATHJAX is set to YES. MATHJAX_CODEFILE = # When the SEARCHENGINE tag is enabled doxygen will generate a search box for # the HTML output. The underlying search engine uses javascript and DHTML and # should work on any modern browser. Note that when using HTML help # (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET) # there is already a search function so this one should typically be disabled. # For large projects the javascript based search engine can be slow, then # enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to # search using the keyboard; to jump to the search box use <access key> + S # (what the <access key> is depends on the OS and browser, but it is typically # <CTRL>, <ALT>/<option>, or both). Inside the search box use the <cursor down # key> to jump into the search results window, the results can be navigated # using the <cursor keys>. Press <Enter> to select an item or <escape> to cancel # the search. The filter options can be selected when the cursor is inside the # search box by pressing <Shift>+<cursor down>. Also here use the <cursor keys> # to select a filter and <Enter> or <escape> to activate or cancel the filter # option. # The default value is: YES. # This tag requires that the tag GENERATE_HTML is set to YES. SEARCHENGINE = YES # When the SERVER_BASED_SEARCH tag is enabled the search engine will be # implemented using a web server instead of a web client using JavaScript. There # are two flavors of web server based searching depending on the EXTERNAL_SEARCH # setting. When disabled, doxygen will generate a PHP script for searching and # an index file used by the script. When EXTERNAL_SEARCH is enabled the indexing # and searching needs to be provided by external tools. See the section # "External Indexing and Searching" for details. # The default value is: NO. # This tag requires that the tag SEARCHENGINE is set to YES. SERVER_BASED_SEARCH = NO # When EXTERNAL_SEARCH tag is enabled doxygen will no longer generate the PHP # script for searching. Instead the search results are written to an XML file # which needs to be processed by an external indexer. Doxygen will invoke an # external search engine pointed to by the SEARCHENGINE_URL option to obtain the # search results. # # Doxygen ships with an example indexer (doxyindexer) and search engine # (doxysearch.cgi) which are based on the open source search engine library # Xapian (see: # https://xapian.org/). # # See the section "External Indexing and Searching" for details. # The default value is: NO. # This tag requires that the tag SEARCHENGINE is set to YES. EXTERNAL_SEARCH = NO # The SEARCHENGINE_URL should point to a search engine hosted by a web server # which will return the search results when EXTERNAL_SEARCH is enabled. # # Doxygen ships with an example indexer (doxyindexer) and search engine # (doxysearch.cgi) which are based on the open source search engine library # Xapian (see: # https://xapian.org/). See the section "External Indexing and Searching" for # details. # This tag requires that the tag SEARCHENGINE is set to YES. SEARCHENGINE_URL = # When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the unindexed # search data is written to a file for indexing by an external tool. With the # SEARCHDATA_FILE tag the name of this file can be specified. # The default file is: searchdata.xml. # This tag requires that the tag SEARCHENGINE is set to YES. SEARCHDATA_FILE = searchdata.xml # When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the # EXTERNAL_SEARCH_ID tag can be used as an identifier for the project. This is # useful in combination with EXTRA_SEARCH_MAPPINGS to search through multiple # projects and redirect the results back to the right project. # This tag requires that the tag SEARCHENGINE is set to YES. EXTERNAL_SEARCH_ID = # The EXTRA_SEARCH_MAPPINGS tag can be used to enable searching through doxygen # projects other than the one defined by this configuration file, but that are # all added to the same external search index. Each project needs to have a # unique id set via EXTERNAL_SEARCH_ID. The search mapping then maps the id of # to a relative location where the documentation can be found. The format is: # EXTRA_SEARCH_MAPPINGS = tagname1=loc1 tagname2=loc2 ... # This tag requires that the tag SEARCHENGINE is set to YES. EXTRA_SEARCH_MAPPINGS = #--------------------------------------------------------------------------- # Configuration options related to the LaTeX output #--------------------------------------------------------------------------- # If the GENERATE_LATEX tag is set to YES, doxygen will generate LaTeX output. # The default value is: YES. GENERATE_LATEX = NO # The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. If a # relative path is entered the value of OUTPUT_DIRECTORY will be put in front of # it. # The default directory is: latex. # This tag requires that the tag GENERATE_LATEX is set to YES. LATEX_OUTPUT = latex # The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be # invoked. # # Note that when not enabling USE_PDFLATEX the default is latex when enabling # USE_PDFLATEX the default is pdflatex and when in the later case latex is # chosen this is overwritten by pdflatex. For specific output languages the # default can have been set differently, this depends on the implementation of # the output language. # This tag requires that the tag GENERATE_LATEX is set to YES. LATEX_CMD_NAME = # The MAKEINDEX_CMD_NAME tag can be used to specify the command name to generate # index for LaTeX. # Note: This tag is used in the Makefile / make.bat. # See also: LATEX_MAKEINDEX_CMD for the part in the generated output file # (.tex). # The default file is: makeindex. # This tag requires that the tag GENERATE_LATEX is set to YES. MAKEINDEX_CMD_NAME = makeindex # The LATEX_MAKEINDEX_CMD tag can be used to specify the command name to # generate index for LaTeX. In case there is no backslash (\) as first character # it will be automatically added in the LaTeX code. # Note: This tag is used in the generated output file (.tex). # See also: MAKEINDEX_CMD_NAME for the part in the Makefile / make.bat. # The default value is: makeindex. # This tag requires that the tag GENERATE_LATEX is set to YES. LATEX_MAKEINDEX_CMD = makeindex # If the COMPACT_LATEX tag is set to YES, doxygen generates more compact LaTeX # documents. This may be useful for small projects and may help to save some # trees in general. # The default value is: NO. # This tag requires that the tag GENERATE_LATEX is set to YES. COMPACT_LATEX = NO # The PAPER_TYPE tag can be used to set the paper type that is used by the # printer. # Possible values are: a4 (210 x 297 mm), letter (8.5 x 11 inches), legal (8.5 x # 14 inches) and executive (7.25 x 10.5 inches). # The default value is: a4. # This tag requires that the tag GENERATE_LATEX is set to YES. PAPER_TYPE = a4 # The EXTRA_PACKAGES tag can be used to specify one or more LaTeX package names # that should be included in the LaTeX output. The package can be specified just # by its name or with the correct syntax as to be used with the LaTeX # \usepackage command. To get the times font for instance you can specify : # EXTRA_PACKAGES=times or EXTRA_PACKAGES={times} # To use the option intlimits with the amsmath package you can specify: # EXTRA_PACKAGES=[intlimits]{amsmath} # If left blank no extra packages will be included. # This tag requires that the tag GENERATE_LATEX is set to YES. EXTRA_PACKAGES = # The LATEX_HEADER tag can be used to specify a user-defined LaTeX header for # the generated LaTeX document. The header should contain everything until the # first chapter. If it is left blank doxygen will generate a standard header. It # is highly recommended to start with a default header using # doxygen -w latex new_header.tex new_footer.tex new_stylesheet.sty # and then modify the file new_header.tex. See also section "Doxygen usage" for # information on how to generate the default header that doxygen normally uses. # # Note: Only use a user-defined header if you know what you are doing! # Note: The header is subject to change so you typically have to regenerate the # default header when upgrading to a newer version of doxygen. The following # commands have a special meaning inside the header (and footer): For a # description of the possible markers and block names see the documentation. # This tag requires that the tag GENERATE_LATEX is set to YES. LATEX_HEADER = # The LATEX_FOOTER tag can be used to specify a user-defined LaTeX footer for # the generated LaTeX document. The footer should contain everything after the # last chapter. If it is left blank doxygen will generate a standard footer. See # LATEX_HEADER for more information on how to generate a default footer and what # special commands can be used inside the footer. See also section "Doxygen # usage" for information on how to generate the default footer that doxygen # normally uses. Note: Only use a user-defined footer if you know what you are # doing! # This tag requires that the tag GENERATE_LATEX is set to YES. LATEX_FOOTER = # The LATEX_EXTRA_STYLESHEET tag can be used to specify additional user-defined # LaTeX style sheets that are included after the standard style sheets created # by doxygen. Using this option one can overrule certain style aspects. Doxygen # will copy the style sheet files to the output directory. # Note: The order of the extra style sheet files is of importance (e.g. the last # style sheet in the list overrules the setting of the previous ones in the # list). # This tag requires that the tag GENERATE_LATEX is set to YES. LATEX_EXTRA_STYLESHEET = # The LATEX_EXTRA_FILES tag can be used to specify one or more extra images or # other source files which should be copied to the LATEX_OUTPUT output # directory. Note that the files will be copied as-is; there are no commands or # markers available. # This tag requires that the tag GENERATE_LATEX is set to YES. LATEX_EXTRA_FILES = # If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated is # prepared for conversion to PDF (using ps2pdf or pdflatex). The PDF file will # contain links (just like the HTML output) instead of page references. This # makes the output suitable for online browsing using a PDF viewer. # The default value is: YES. # This tag requires that the tag GENERATE_LATEX is set to YES. PDF_HYPERLINKS = YES # If the USE_PDFLATEX tag is set to YES, doxygen will use the engine as # specified with LATEX_CMD_NAME to generate the PDF file directly from the LaTeX # files. Set this option to YES, to get a higher quality PDF documentation. # # See also section LATEX_CMD_NAME for selecting the engine. # The default value is: YES. # This tag requires that the tag GENERATE_LATEX is set to YES. USE_PDFLATEX = YES # If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \batchmode # command to the generated LaTeX files. This will instruct LaTeX to keep running # if errors occur, instead of asking the user for help. # The default value is: NO. # This tag requires that the tag GENERATE_LATEX is set to YES. LATEX_BATCHMODE = NO # If the LATEX_HIDE_INDICES tag is set to YES then doxygen will not include the # index chapters (such as File Index, Compound Index, etc.) in the output. # The default value is: NO. # This tag requires that the tag GENERATE_LATEX is set to YES. LATEX_HIDE_INDICES = NO # The LATEX_BIB_STYLE tag can be used to specify the style to use for the # bibliography, e.g. plainnat, or ieeetr. See # https://en.wikipedia.org/wiki/BibTeX and \cite for more info. # The default value is: plain. # This tag requires that the tag GENERATE_LATEX is set to YES. LATEX_BIB_STYLE = plain # If the LATEX_TIMESTAMP tag is set to YES then the footer of each generated # page will contain the date and time when the page was generated. Setting this # to NO can help when comparing the output of multiple runs. # The default value is: NO. # This tag requires that the tag GENERATE_LATEX is set to YES. LATEX_TIMESTAMP = NO # The LATEX_EMOJI_DIRECTORY tag is used to specify the (relative or absolute) # path from which the emoji images will be read. If a relative path is entered, # it will be relative to the LATEX_OUTPUT directory. If left blank the # LATEX_OUTPUT directory will be used. # This tag requires that the tag GENERATE_LATEX is set to YES. LATEX_EMOJI_DIRECTORY = #--------------------------------------------------------------------------- # Configuration options related to the RTF output #--------------------------------------------------------------------------- # If the GENERATE_RTF tag is set to YES, doxygen will generate RTF output. The # RTF output is optimized for Word 97 and may not look too pretty with other RTF # readers/editors. # The default value is: NO. GENERATE_RTF = NO # The RTF_OUTPUT tag is used to specify where the RTF docs will be put. If a # relative path is entered the value of OUTPUT_DIRECTORY will be put in front of # it. # The default directory is: rtf. # This tag requires that the tag GENERATE_RTF is set to YES. RTF_OUTPUT = rtf # If the COMPACT_RTF tag is set to YES, doxygen generates more compact RTF # documents. This may be useful for small projects and may help to save some # trees in general. # The default value is: NO. # This tag requires that the tag GENERATE_RTF is set to YES. COMPACT_RTF = NO # If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated will # contain hyperlink fields. The RTF file will contain links (just like the HTML # output) instead of page references. This makes the output suitable for online # browsing using Word or some other Word compatible readers that support those # fields. # # Note: WordPad (write) and others do not support links. # The default value is: NO. # This tag requires that the tag GENERATE_RTF is set to YES. RTF_HYPERLINKS = NO # Load stylesheet definitions from file. Syntax is similar to doxygen's # configuration file, i.e. a series of assignments. You only have to provide # replacements, missing definitions are set to their default value. # # See also section "Doxygen usage" for information on how to generate the # default style sheet that doxygen normally uses. # This tag requires that the tag GENERATE_RTF is set to YES. RTF_STYLESHEET_FILE = # Set optional variables used in the generation of an RTF document. Syntax is # similar to doxygen's configuration file. A template extensions file can be # generated using doxygen -e rtf extensionFile. # This tag requires that the tag GENERATE_RTF is set to YES. RTF_EXTENSIONS_FILE = #--------------------------------------------------------------------------- # Configuration options related to the man page output #--------------------------------------------------------------------------- # If the GENERATE_MAN tag is set to YES, doxygen will generate man pages for # classes and files. # The default value is: NO. GENERATE_MAN = NO # The MAN_OUTPUT tag is used to specify where the man pages will be put. If a # relative path is entered the value of OUTPUT_DIRECTORY will be put in front of # it. A directory man3 will be created inside the directory specified by # MAN_OUTPUT. # The default directory is: man. # This tag requires that the tag GENERATE_MAN is set to YES. MAN_OUTPUT = man # The MAN_EXTENSION tag determines the extension that is added to the generated # man pages. In case the manual section does not start with a number, the number # 3 is prepended. The dot (.) at the beginning of the MAN_EXTENSION tag is # optional. # The default value is: .3. # This tag requires that the tag GENERATE_MAN is set to YES. MAN_EXTENSION = .3 # The MAN_SUBDIR tag determines the name of the directory created within # MAN_OUTPUT in which the man pages are placed. If defaults to man followed by # MAN_EXTENSION with the initial . removed. # This tag requires that the tag GENERATE_MAN is set to YES. MAN_SUBDIR = # If the MAN_LINKS tag is set to YES and doxygen generates man output, then it # will generate one additional man file for each entity documented in the real # man page(s). These additional files only source the real man page, but without # them the man command would be unable to find the correct page. # The default value is: NO. # This tag requires that the tag GENERATE_MAN is set to YES. MAN_LINKS = NO #--------------------------------------------------------------------------- # Configuration options related to the XML output #--------------------------------------------------------------------------- # If the GENERATE_XML tag is set to YES, doxygen will generate an XML file that # captures the structure of the code including all documentation. # The default value is: NO. GENERATE_XML = NO # The XML_OUTPUT tag is used to specify where the XML pages will be put. If a # relative path is entered the value of OUTPUT_DIRECTORY will be put in front of # it. # The default directory is: xml. # This tag requires that the tag GENERATE_XML is set to YES. XML_OUTPUT = xml # If the XML_PROGRAMLISTING tag is set to YES, doxygen will dump the program # listings (including syntax highlighting and cross-referencing information) to # the XML output. Note that enabling this will significantly increase the size # of the XML output. # The default value is: YES. # This tag requires that the tag GENERATE_XML is set to YES. XML_PROGRAMLISTING = YES # If the XML_NS_MEMB_FILE_SCOPE tag is set to YES, doxygen will include # namespace members in file scope as well, matching the HTML output. # The default value is: NO. # This tag requires that the tag GENERATE_XML is set to YES. XML_NS_MEMB_FILE_SCOPE = NO #--------------------------------------------------------------------------- # Configuration options related to the DOCBOOK output #--------------------------------------------------------------------------- # If the GENERATE_DOCBOOK tag is set to YES, doxygen will generate Docbook files # that can be used to generate PDF. # The default value is: NO. GENERATE_DOCBOOK = NO # The DOCBOOK_OUTPUT tag is used to specify where the Docbook pages will be put. # If a relative path is entered the value of OUTPUT_DIRECTORY will be put in # front of it. # The default directory is: docbook. # This tag requires that the tag GENERATE_DOCBOOK is set to YES. DOCBOOK_OUTPUT = docbook #--------------------------------------------------------------------------- # Configuration options for the AutoGen Definitions output #--------------------------------------------------------------------------- # If the GENERATE_AUTOGEN_DEF tag is set to YES, doxygen will generate an # AutoGen Definitions (see http://autogen.sourceforge.net/) file that captures # the structure of the code including all documentation. Note that this feature # is still experimental and incomplete at the moment. # The default value is: NO. GENERATE_AUTOGEN_DEF = NO #--------------------------------------------------------------------------- # Configuration options related to the Perl module output #--------------------------------------------------------------------------- # If the GENERATE_PERLMOD tag is set to YES, doxygen will generate a Perl module # file that captures the structure of the code including all documentation. # # Note that this feature is still experimental and incomplete at the moment. # The default value is: NO. GENERATE_PERLMOD = NO # If the PERLMOD_LATEX tag is set to YES, doxygen will generate the necessary # Makefile rules, Perl scripts and LaTeX code to be able to generate PDF and DVI # output from the Perl module output. # The default value is: NO. # This tag requires that the tag GENERATE_PERLMOD is set to YES. PERLMOD_LATEX = NO # If the PERLMOD_PRETTY tag is set to YES, the Perl module output will be nicely # formatted so it can be parsed by a human reader. This is useful if you want to # understand what is going on. On the other hand, if this tag is set to NO, the # size of the Perl module output will be much smaller and Perl will parse it # just the same. # The default value is: YES. # This tag requires that the tag GENERATE_PERLMOD is set to YES. PERLMOD_PRETTY = YES # The names of the make variables in the generated doxyrules.make file are # prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. This is useful # so different doxyrules.make files included by the same Makefile don't # overwrite each other's variables. # This tag requires that the tag GENERATE_PERLMOD is set to YES. PERLMOD_MAKEVAR_PREFIX = #--------------------------------------------------------------------------- # Configuration options related to the preprocessor #--------------------------------------------------------------------------- # If the ENABLE_PREPROCESSING tag is set to YES, doxygen will evaluate all # C-preprocessor directives found in the sources and include files. # The default value is: YES. ENABLE_PREPROCESSING = YES # If the MACRO_EXPANSION tag is set to YES, doxygen will expand all macro names # in the source code. If set to NO, only conditional compilation will be # performed. Macro expansion can be done in a controlled way by setting # EXPAND_ONLY_PREDEF to YES. # The default value is: NO. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. MACRO_EXPANSION = YES # If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then # the macro expansion is limited to the macros specified with the PREDEFINED and # EXPAND_AS_DEFINED tags. # The default value is: NO. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. EXPAND_ONLY_PREDEF = NO # If the SEARCH_INCLUDES tag is set to YES, the include files in the # INCLUDE_PATH will be searched if a #include is found. # The default value is: YES. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. SEARCH_INCLUDES = YES # The INCLUDE_PATH tag can be used to specify one or more directories that # contain include files that are not input files but should be processed by the # preprocessor. Note that the INCLUDE_PATH is not recursive, so the setting of # RECURSIVE has no effect here. # This tag requires that the tag SEARCH_INCLUDES is set to YES. INCLUDE_PATH = @Range-v3_SOURCE_DIR@/include # You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard # patterns (like *.h and *.hpp) to filter out the header-files in the # directories. If left blank, the patterns specified with FILE_PATTERNS will be # used. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. INCLUDE_FILE_PATTERNS = # The PREDEFINED tag can be used to specify one or more macro names that are # defined before the preprocessor is started (similar to the -D option of e.g. # gcc). The argument of the tag is a list of macros of the form: name or # name=definition (no spaces). If the definition and the "=" are omitted, "=1" # is assumed. To prevent a macro definition from being undefined via #undef or # recursively expanded use the := operator instead of the = operator. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. PREDEFINED = RANGES_DOXYGEN_INVOKED=1 \ META_DOXYGEN_INVOKED=1 \ CPP_DOXYGEN_INVOKED=1 \ "RANGES_INLINE_VARIABLE(T,N)=inline constexpr T N{};" # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this # tag can be used to specify a list of macro names that should be expanded. The # macro definition that is found in the sources will be used. Use the PREDEFINED # tag if you want to use a different macro definition that overrules the # definition found in the source code. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. EXPAND_AS_DEFINED = # If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will # remove all references to function-like macros that are alone on a line, have # an all uppercase name, and do not end with a semicolon. Such function macros # are typically used for boiler-plate code, and will confuse the parser if not # removed. # The default value is: YES. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. SKIP_FUNCTION_MACROS = NO #--------------------------------------------------------------------------- # Configuration options related to external references #--------------------------------------------------------------------------- # The TAGFILES tag can be used to specify one or more tag files. For each tag # file the location of the external documentation should be added. The format of # a tag file without this location is as follows: # TAGFILES = file1 file2 ... # Adding location for the tag files is done as follows: # TAGFILES = file1=loc1 "file2 = loc2" ... # where loc1 and loc2 can be relative or absolute paths or URLs. See the # section "Linking to external documentation" for more information about the use # of tag files. # Note: Each tag file must have a unique name (where the name does NOT include # the path). If a tag file is not located in the directory in which doxygen is # run, you must also specify the path to the tagfile here. TAGFILES = # When a file name is specified after GENERATE_TAGFILE, doxygen will create a # tag file that is based on the input files it reads. See section "Linking to # external documentation" for more information about the usage of tag files. GENERATE_TAGFILE = # If the ALLEXTERNALS tag is set to YES, all external class will be listed in # the class index. If set to NO, only the inherited external classes will be # listed. # The default value is: NO. ALLEXTERNALS = NO # If the EXTERNAL_GROUPS tag is set to YES, all external groups will be listed # in the modules index. If set to NO, only the current project's groups will be # listed. # The default value is: YES. EXTERNAL_GROUPS = YES # If the EXTERNAL_PAGES tag is set to YES, all external pages will be listed in # the related pages index. If set to NO, only the current project's pages will # be listed. # The default value is: YES. EXTERNAL_PAGES = YES #--------------------------------------------------------------------------- # Configuration options related to the dot tool #--------------------------------------------------------------------------- # You can include diagrams made with dia in doxygen documentation. Doxygen will # then run dia to produce the diagram and insert it in the documentation. The # DIA_PATH tag allows you to specify the directory where the dia binary resides. # If left empty dia is assumed to be found in the default search path. DIA_PATH = # If set to YES the inheritance and collaboration graphs will hide inheritance # and usage relations if the target is undocumented or is not a class. # The default value is: YES. HIDE_UNDOC_RELATIONS = NO # If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is # available from the path. This tool is part of Graphviz (see: # http://www.graphviz.org/), a graph visualization toolkit from AT&T and Lucent # Bell Labs. The other options in this section have no effect if this option is # set to NO # The default value is: NO. HAVE_DOT = NO # The DOT_NUM_THREADS specifies the number of dot invocations doxygen is allowed # to run in parallel. When set to 0 doxygen will base this on the number of # processors available in the system. You can set it explicitly to a value # larger than 0 to get control over the balance between CPU load and processing # speed. # Minimum value: 0, maximum value: 32, default value: 0. # This tag requires that the tag HAVE_DOT is set to YES. DOT_NUM_THREADS = 0 # When you want a differently looking font in the dot files that doxygen # generates you can specify the font name using DOT_FONTNAME. You need to make # sure dot is able to find the font, which can be done by putting it in a # standard location or by setting the DOTFONTPATH environment variable or by # setting DOT_FONTPATH to the directory containing the font. # The default value is: Helvetica. # This tag requires that the tag HAVE_DOT is set to YES. DOT_FONTNAME = Helvetica # The DOT_FONTSIZE tag can be used to set the size (in points) of the font of # dot graphs. # Minimum value: 4, maximum value: 24, default value: 10. # This tag requires that the tag HAVE_DOT is set to YES. DOT_FONTSIZE = 10 # By default doxygen will tell dot to use the default font as specified with # DOT_FONTNAME. If you specify a different font using DOT_FONTNAME you can set # the path where dot can find it using this tag. # This tag requires that the tag HAVE_DOT is set to YES. DOT_FONTPATH = # If the CLASS_GRAPH tag is set to YES (or GRAPH) then doxygen will generate a # graph for each documented class showing the direct and indirect inheritance # relations. In case HAVE_DOT is set as well dot will be used to draw the graph, # otherwise the built-in generator will be used. If the CLASS_GRAPH tag is set # to TEXT the direct and indirect inheritance relations will be shown as texts / # links. # Possible values are: NO, YES, TEXT and GRAPH. # The default value is: YES. CLASS_GRAPH = YES # If the COLLABORATION_GRAPH tag is set to YES then doxygen will generate a # graph for each documented class showing the direct and indirect implementation # dependencies (inheritance, containment, and class references variables) of the # class with other documented classes. # The default value is: YES. # This tag requires that the tag HAVE_DOT is set to YES. COLLABORATION_GRAPH = YES # If the GROUP_GRAPHS tag is set to YES then doxygen will generate a graph for # groups, showing the direct groups dependencies. See also the chapter Grouping # in the manual. # The default value is: YES. # This tag requires that the tag HAVE_DOT is set to YES. GROUP_GRAPHS = YES # If the UML_LOOK tag is set to YES, doxygen will generate inheritance and # collaboration diagrams in a style similar to the OMG's Unified Modeling # Language. # The default value is: NO. # This tag requires that the tag HAVE_DOT is set to YES. UML_LOOK = NO # If the UML_LOOK tag is enabled, the fields and methods are shown inside the # class node. If there are many fields or methods and many nodes the graph may # become too big to be useful. The UML_LIMIT_NUM_FIELDS threshold limits the # number of items for each type to make the size more manageable. Set this to 0 # for no limit. Note that the threshold may be exceeded by 50% before the limit # is enforced. So when you set the threshold to 10, up to 15 fields may appear, # but if the number exceeds 15, the total amount of fields shown is limited to # 10. # Minimum value: 0, maximum value: 100, default value: 10. # This tag requires that the tag UML_LOOK is set to YES. UML_LIMIT_NUM_FIELDS = 10 # If the DOT_UML_DETAILS tag is set to NO, doxygen will show attributes and # methods without types and arguments in the UML graphs. If the DOT_UML_DETAILS # tag is set to YES, doxygen will add type and arguments for attributes and # methods in the UML graphs. If the DOT_UML_DETAILS tag is set to NONE, doxygen # will not generate fields with class member information in the UML graphs. The # class diagrams will look similar to the default class diagrams but using UML # notation for the relationships. # Possible values are: NO, YES and NONE. # The default value is: NO. # This tag requires that the tag UML_LOOK is set to YES. DOT_UML_DETAILS = NO # The DOT_WRAP_THRESHOLD tag can be used to set the maximum number of characters # to display on a single line. If the actual line length exceeds this threshold # significantly it will wrapped across multiple lines. Some heuristics are apply # to avoid ugly line breaks. # Minimum value: 0, maximum value: 1000, default value: 17. # This tag requires that the tag HAVE_DOT is set to YES. DOT_WRAP_THRESHOLD = 17 # If the TEMPLATE_RELATIONS tag is set to YES then the inheritance and # collaboration graphs will show the relations between templates and their # instances. # The default value is: NO. # This tag requires that the tag HAVE_DOT is set to YES. TEMPLATE_RELATIONS = NO # If the INCLUDE_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are set to # YES then doxygen will generate a graph for each documented file showing the # direct and indirect include dependencies of the file with other documented # files. # The default value is: YES. # This tag requires that the tag HAVE_DOT is set to YES. INCLUDE_GRAPH = YES # If the INCLUDED_BY_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are # set to YES then doxygen will generate a graph for each documented file showing # the direct and indirect include dependencies of the file with other documented # files. # The default value is: YES. # This tag requires that the tag HAVE_DOT is set to YES. INCLUDED_BY_GRAPH = YES # If the CALL_GRAPH tag is set to YES then doxygen will generate a call # dependency graph for every global function or class method. # # Note that enabling this option will significantly increase the time of a run. # So in most cases it will be better to enable call graphs for selected # functions only using the \callgraph command. Disabling a call graph can be # accomplished by means of the command \hidecallgraph. # The default value is: NO. # This tag requires that the tag HAVE_DOT is set to YES. CALL_GRAPH = NO # If the CALLER_GRAPH tag is set to YES then doxygen will generate a caller # dependency graph for every global function or class method. # # Note that enabling this option will significantly increase the time of a run. # So in most cases it will be better to enable caller graphs for selected # functions only using the \callergraph command. Disabling a caller graph can be # accomplished by means of the command \hidecallergraph. # The default value is: NO. # This tag requires that the tag HAVE_DOT is set to YES. CALLER_GRAPH = NO # If the GRAPHICAL_HIERARCHY tag is set to YES then doxygen will graphical # hierarchy of all classes instead of a textual one. # The default value is: YES. # This tag requires that the tag HAVE_DOT is set to YES. GRAPHICAL_HIERARCHY = YES # If the DIRECTORY_GRAPH tag is set to YES then doxygen will show the # dependencies a directory has on other directories in a graphical way. The # dependency relations are determined by the #include relations between the # files in the directories. # The default value is: YES. # This tag requires that the tag HAVE_DOT is set to YES. DIRECTORY_GRAPH = YES # The DIR_GRAPH_MAX_DEPTH tag can be used to limit the maximum number of levels # of child directories generated in directory dependency graphs by dot. # Minimum value: 1, maximum value: 25, default value: 1. # This tag requires that the tag DIRECTORY_GRAPH is set to YES. DIR_GRAPH_MAX_DEPTH = 1 # The DOT_IMAGE_FORMAT tag can be used to set the image format of the images # generated by dot. For an explanation of the image formats see the section # output formats in the documentation of the dot tool (Graphviz (see: # http://www.graphviz.org/)). # Note: If you choose svg you need to set HTML_FILE_EXTENSION to xhtml in order # to make the SVG files visible in IE 9+ (other browsers do not have this # requirement). # Possible values are: png, jpg, gif, svg, png:gd, png:gd:gd, png:cairo, # png:cairo:gd, png:cairo:cairo, png:cairo:gdiplus, png:gdiplus and # png:gdiplus:gdiplus. # The default value is: png. # This tag requires that the tag HAVE_DOT is set to YES. DOT_IMAGE_FORMAT = png # If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to # enable generation of interactive SVG images that allow zooming and panning. # # Note that this requires a modern browser other than Internet Explorer. Tested # and working are Firefox, Chrome, Safari, and Opera. # Note: For IE 9+ you need to set HTML_FILE_EXTENSION to xhtml in order to make # the SVG files visible. Older versions of IE do not have SVG support. # The default value is: NO. # This tag requires that the tag HAVE_DOT is set to YES. INTERACTIVE_SVG = NO # The DOT_PATH tag can be used to specify the path where the dot tool can be # found. If left blank, it is assumed the dot tool can be found in the path. # This tag requires that the tag HAVE_DOT is set to YES. DOT_PATH = # The DOTFILE_DIRS tag can be used to specify one or more directories that # contain dot files that are included in the documentation (see the \dotfile # command). # This tag requires that the tag HAVE_DOT is set to YES. DOTFILE_DIRS = # The MSCFILE_DIRS tag can be used to specify one or more directories that # contain msc files that are included in the documentation (see the \mscfile # command). MSCFILE_DIRS = # The DIAFILE_DIRS tag can be used to specify one or more directories that # contain dia files that are included in the documentation (see the \diafile # command). DIAFILE_DIRS = # When using plantuml, the PLANTUML_JAR_PATH tag should be used to specify the # path where java can find the plantuml.jar file or to the filename of jar file # to be used. If left blank, it is assumed PlantUML is not used or called during # a preprocessing step. Doxygen will generate a warning when it encounters a # \startuml command in this case and will not generate output for the diagram. PLANTUML_JAR_PATH = # When using plantuml, the PLANTUML_CFG_FILE tag can be used to specify a # configuration file for plantuml. PLANTUML_CFG_FILE = # When using plantuml, the specified paths are searched for files specified by # the !include statement in a plantuml block. PLANTUML_INCLUDE_PATH = # The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of nodes # that will be shown in the graph. If the number of nodes in a graph becomes # larger than this value, doxygen will truncate the graph, which is visualized # by representing a node as a red box. Note that doxygen if the number of direct # children of the root node in a graph is already larger than # DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note that # the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH. # Minimum value: 0, maximum value: 10000, default value: 50. # This tag requires that the tag HAVE_DOT is set to YES. DOT_GRAPH_MAX_NODES = 50 # The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the graphs # generated by dot. A depth value of 3 means that only nodes reachable from the # root by following a path via at most 3 edges will be shown. Nodes that lay # further from the root node will be omitted. Note that setting this option to 1 # or 2 may greatly reduce the computation time needed for large code bases. Also # note that the size of a graph can be further restricted by # DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction. # Minimum value: 0, maximum value: 1000, default value: 0. # This tag requires that the tag HAVE_DOT is set to YES. MAX_DOT_GRAPH_DEPTH = 0 # Set the DOT_TRANSPARENT tag to YES to generate images with a transparent # background. This is disabled by default, because dot on Windows does not seem # to support this out of the box. # # Warning: Depending on the platform used, enabling this option may lead to # badly anti-aliased labels on the edges of a graph (i.e. they become hard to # read). # The default value is: NO. # This tag requires that the tag HAVE_DOT is set to YES. DOT_TRANSPARENT = NO # Set the DOT_MULTI_TARGETS tag to YES to allow dot to generate multiple output # files in one run (i.e. multiple -o and -T options on the command line). This # makes dot run faster, but since only newer versions of dot (>1.8.10) support # this, this feature is disabled by default. # The default value is: NO. # This tag requires that the tag HAVE_DOT is set to YES. DOT_MULTI_TARGETS = NO # If the GENERATE_LEGEND tag is set to YES doxygen will generate a legend page # explaining the meaning of the various boxes and arrows in the dot generated # graphs. # Note: This tag requires that UML_LOOK isn't set, i.e. the doxygen internal # graphical representation for inheritance and collaboration diagrams is used. # The default value is: YES. # This tag requires that the tag HAVE_DOT is set to YES. GENERATE_LEGEND = YES # If the DOT_CLEANUP tag is set to YES, doxygen will remove the intermediate # files that are used to generate the various graphs. # # Note: This setting is not only used for dot files but also for msc temporary # files. # The default value is: YES. DOT_CLEANUP = YES
0
repos/range-v3
repos/range-v3/doc/CMakeLists.txt
#============================================================================= # Setup the documentation #============================================================================= if (NOT DOXYGEN_FOUND) message(STATUS "Doxygen not found; the 'range-v3-doc' and 'range-v3-gh-pages.{clean,copy,update}' targets " "will be unavailable.") return() endif() set(CMAKE_FOLDER "doc") configure_file(Doxyfile.in Doxyfile @ONLY) configure_file(preprocess.sh.in preprocess.sh @ONLY) add_custom_target(range.v3.doc.check COMMAND ${DOXYGEN_EXECUTABLE} Doxyfile COMMENT "Running Doxygen to validate the documentation" VERBATIM ) set_target_properties(range.v3.doc.check PROPERTIES FOLDER ${CMAKE_FOLDER} ) # if (NOT TARGET benchmarks) # message(STATUS # "The 'benchmarks' target is not available; the 'doc' and " # "'gh-pages.{clean,copy,update}' targets will be unavailable. " # "The 'doc.check' target can still be used to generate the " # "documentation to check for errors/warnings.") # return() # endif() add_custom_target(range-v3-doc COMMAND ${DOXYGEN_EXECUTABLE} Doxyfile COMMENT "Generating API documentation with Doxygen" # DEPENDS range-v3-benchmarks VERBATIM ) set_target_properties(range-v3-doc PROPERTIES FOLDER ${CMAKE_FOLDER} ) if (NOT GIT_FOUND) message(STATUS "Git was not found; the 'range-v3-gh-pages.{clean,copy,update}' targets " "will be unavailable.") return() endif() add_custom_target(range-v3-gh-pages.clean COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_LIST_DIR}/clean-gh-pages.cmake COMMAND ${CMAKE_COMMAND} -E remove_directory search WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/gh-pages COMMENT "Cleaning up doc/gh-pages" VERBATIM ) set_target_properties(range-v3-gh-pages.clean PROPERTIES FOLDER ${CMAKE_FOLDER} ) add_custom_target(range-v3-gh-pages.copy COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_BINARY_DIR}/html ${CMAKE_CURRENT_LIST_DIR}/gh-pages WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/gh-pages COMMENT "Copying the documentation from ${CMAKE_CURRENT_BINARY_DIR}/html to doc/gh-pages" DEPENDS range-v3-doc range-v3-gh-pages.clean VERBATIM ) set_target_properties(range-v3-gh-pages.copy PROPERTIES FOLDER ${CMAKE_FOLDER} ) execute_process( COMMAND ${GIT_EXECUTABLE} -C ${CMAKE_SOURCE_DIR} rev-parse --short HEAD OUTPUT_VARIABLE RANGE_V3_GIT_SHORT_SHA OUTPUT_STRIP_TRAILING_WHITESPACE ) add_custom_target(range-v3-gh-pages.update COMMAND ${GIT_EXECUTABLE} add --all . COMMAND ${GIT_EXECUTABLE} commit -m "Update to ${RANGE_V3_GIT_SHORT_SHA}" WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/gh-pages COMMENT "Updating the gh-pages branch with freshly built documentation" DEPENDS range-v3-gh-pages.copy VERBATIM ) set_target_properties(range-v3-gh-pages.update PROPERTIES FOLDER ${CMAKE_FOLDER} )
0
repos/range-v3
repos/range-v3/doc/examples.md
Examples ======== \section example-algorithms Examples: Algorithms \subsection example-hello Hello, Ranges! \snippet hello.cpp hello \subsection example-any-all-none any_of, all_of, none_of \snippet any_all_none_of.cpp any_all_none_of \subsection example-count count \snippet count.cpp count \subsection example-count_if count_if \snippet count_if.cpp count_if \subsection example-find find, find_if, find_if_not on sequence containers \snippet find.cpp find \subsection example-for_each-seq for_each on sequence containers \snippet for_each_sequence.cpp for_each_sequence \subsection example-for_each-assoc for_each on associative containers \snippet for_each_assoc.cpp for_each_assoc \subsection example-is_sorted is_sorted \snippet is_sorted.cpp is_sorted \section example-views Examples: Views \subsection example-filter-transform Filter and transform \snippet filter_transform.cpp filter_transform \subsection example-accumulate-ints Generate ints and accumulate \snippet accumulate_ints.cpp accumulate_ints \subsection example-comprehension-conversion Convert a range comprehension to a vector \snippet comprehension_conversion.cpp comprehension_conversion \section example-actions Examples: Actions \subsection example-sort-unique Remove non-unique elements from a container \snippet sort_unique.cpp sort_unique \section example-gestalt Examples: Putting it all together \subsection example-calendar Calendar \snippet calendar.cpp calendar
0
repos/range-v3
repos/range-v3/doc/release_notes.md
Release Notes {#release_notes} ============= \section v0-12-0 Version 0.12.0 "Dude, Where's My Bored Ape?" _Released:_ June 19, 2022 > **IMPORTANT:** This release deprecates `views::group_by` which was > an endless source of confusion. `group_by` is replaced with > `views::chunk_by` (which, beware, has _subtly_ different semantics, > see below.) Changes: * **NEW:** `views::chunk_by` which, like the old `views::group_by` it replaces, splits a range into a range-of-ranges, where adjacent elements satisfy a binary predicate ([\#1648](https://github.com/ericniebler/range-v3/pull/1648)). [_Note:_ Whereas `views::group_by` evaluated the predicate between the current element and the _first_ element in the chunk, `views::chunk_by` evaluates the predicate between _adjacent_ elements. -- _end note_] * **NEW:** `constexpr` all the algorithms that are `constexpr` in C++20's `std::ranges` ([\#1683](https://github.com/ericniebler/range-v3/pull/1683)). * **NEW:** Fold algorithms from [P2322](http://wg21.link/P2322) ([\#1628](https://github.com/ericniebler/range-v3/pull/1628)), ([\#1668](https://github.com/ericniebler/range-v3/pull/1668)). * **NEW:** `ranges::unformatted_ostream_iterator` ([\#1586](https://github.com/ericniebler/range-v3/pull/1586)). * **NEW:** Support for the `build2` build system ([\#1562](https://github.com/ericniebler/range-v3/pull/1562)). * Implement [P2328](http://wg21.link/P2328): relax the constraint on `ranges::join_view` to support joining ranges of prvalue non-`view` ranges ([\#1655](https://github.com/ericniebler/range-v3/pull/1655)). * Improved algorithm for `ranges::linear_distribute` ([\#1679](https://github.com/ericniebler/range-v3/pull/1679)). * Renamed `safe_subrange_t` to `borrowed_subrange_t` ([\#1542](https://github.com/ericniebler/range-v3/pull/1542)). * Extend `ranges::to` to support conversion to container-of-containers ([\#1553](https://github.com/ericniebler/range-v3/pull/1553)). * `views::enumerate` can be a `borrowed_view` ([\#1571](https://github.com/ericniebler/range-v3/pull/1571)). * `ranges::upper_bound` works in the presence of overloaded `operator&` ([\#1632](https://github.com/ericniebler/range-v3/pull/1632)). * Input iterators are no longer required to be default-constructible ([\#1652](https://github.com/ericniebler/range-v3/pull/1652)). Bugs fixed: * `ranges::to<std::map>(v)` does not work ([\#1700](https://github.com/ericniebler/range-v3/pull/1700)) * `ranges::reverse_iterator` has the wrong `value_type` when reversing a proxy range ([\#1670](https://github.com/ericniebler/range-v3/pull/1670)). * A post-increment of a `ranges::counted_iterator` wrapping an input iterator with a `void`-returning post-increment operator isn't incrementing the count ([\#1664](https://github.com/ericniebler/range-v3/pull/1664)). * Bad assert in `views::drop_last` ([\#1599](https://github.com/ericniebler/range-v3/pull/1599)). * Read of uninitialized `bool` in `views::cache1` ([\#1610](https://github.com/ericniebler/range-v3/pull/1610)). * `ranges::unstable_remove_if` calls predicate on same element twice ([\#1629](https://github.com/ericniebler/range-v3/pull/1629)). * `ranges::on(f,g)(x...)` should be `f(g(x)...)` instead of `f(g(x...))` ([\#1661](https://github.com/ericniebler/range-v3/pull/1661)). * Broken qualification of cmake targets ([\#1557](https://github.com/ericniebler/range-v3/pull/1557)). * Various portability and documentation fixes. **Credits:** I would like to thank the following people who contributed to this release (in no particular order): Barry Revzin, @dvirtz, Gonzalo Brito, Johel Ernesto Guerrero Peña, Joël Lamotte, Doug Roeper, Facundo Tuesca, Vitaly Zaitsev, @23rd, @furkanusta, Jonathan Haigh, @SmorkalovG, @marehr, Matt Beardsley, Chris Glover, Louis Dionne, Jin Shang (@js8544), Hui Xie, @huixie90, Robert Maynard, Silver Zachara, @sergegers, Théo DELRIEU, @LesnyRumcajs, Yehezkel Bernat, Maciej Patro, Klemens Nanni, Thomas Madlener, and Jason Merrill. &#127881; Special thanks to Barry Revzin for stepping up to be part-time co-maintainer of range-v3. &#127881; \section v0-11-0 Version 0.11.0 "Thanks, ISO" _Released:_ August 6, 2020 > **IMPORTANT:** This release removes the heuristic that tries to guess whether a range type is a "view" (lightweight, non-owning range), in accordance with the C++20. **This is a potentially source-breaking change.** Code that previously used an rvalue range as the start of a pipeline could stop compiling if the range library is not explicitly told that that range type is a view. To override the new default, please specialize the `ranges::enable_view<R>` Boolean variable template. > **IMPORTANT:** This release removes the implicit conversion from views to containers. To construct a container from an arbitrary range, you must now explicitly use `ranges::to`. For example, the following code no longer works: > > ```c++ > std::vector<int> is = ranges::views::ints(0, 10); // ERROR: no conversion > ``` > > Instead, please write this as: > > ```c++ > auto is = ranges::views::ints(0, 10) | ranges::to<std::vector>; // OK > ``` > > `ranges::to` lives in header `<range/v3/range/conversion.hpp>` > **IMPORTANT:** This release drops support for llvm-3.9. Changes: * **NEW:** A new concepts portability layer that short-circuits atomic constraints in `requires` clauses for better compile times when emulating concepts. * **NEW:** Restored support for MSVC in `/std:c++17` mode, and for MSVC's default preprocessor. * Remove the implicit conversion from views to containers. * Rename the following entities to be consistent with C++20's `std::ranges` support: * `safe_range<R>` -> `borrowed_range<R>` * `enable_safe_range<R>` -> `enable_borrowed_range<R>` * `safe_iterator_t<R>` -> `borrowed_iterator_t<R>` * `safe_subrange_t<R>` -> `borrowed_subrange_t<R>` * `readable_traits<I>` -> `indirectly_readable_traits<I>` * `readable<I>` -> `indirectly_readable<I>` * `writable<I>` -> `indirectly_writable<I>` * Added the following to the `ranges::cpp20` namespace: * Algorithm `for_each_n` * Algorithm `sample` * Class `view_base` * Alias `views::all_t` * Type `__int128` is recognized as "integer-like". * Adds concepts `three_way_comparable[_with]` when `<=>` is supported. * Adds concepts `partially_ordered[_with]`. * Better conformance with C++20's use of the _`boolean-testable`_ concept. * Support C++20 coroutines. * Honor CMake's `CMAKE_CXX_STANDARD` variable. * A fix for the cardinality of `views::zip[_with]` ([\#1486](https://github.com/ericniebler/range-v3/pull/1486)). * Add `view_interface::data()` member function. * Add necessary specializations for `std::basic_common_reference` and `std::common_type`. * Numerous workarounds for MSVC. * Various CMake fixes and improvements. * `drop_while_view` is not a `sized_range`. * Added support for Wind River Systems. * Bug fixes to `views::group_by` ([\#1393](https://github.com/ericniebler/range-v3/pull/1393)). * `common_[reference|type]` of `common_[tuple|pair]` now yields a `common_[tuple|pair]` instead of a `std::[tuple|pair]` ([\#1422](https://github.com/ericniebler/range-v3/pull/1422)). * Avoid UB when currying an lvalue in some views and actions ([\#1320](https://github.com/ericniebler/range-v3/pull/1320)). **Credits:** I would like to thank the following people who contributed to this release (in no particular order): Christopher Di Bella, @marehr, Casey Carter, Dvir Yitzchaki, Justin Riddell, Johel Ernesto Guerrero Peña, Barry Revzin, Kamlesh Kumar, and Vincas Dargis. \section v0-10-0 Version 0.10.0 "To Err is Human" _Released:_ Dec 6, 2019. **IMPORTANT:** Before upgrading, please note that several older compiler versions and build configurations are no longer supported! In particular, MSVC now needs `/std:c++latest`. **ALSO:** When taking a dependency on the `range-v3`, `meta`, or `concepts` libraries via CMake, please now use the namespace qualified target names: - `range-v3::range-v3` - `range-v3::meta` - `range-v3::concepts` Changes: * **NEW:** Rewritten concepts portability layer with simpler macros for better diagnostics. * **NEW:** The `views::cache1` view caches the most recent value in the range. This can help avoid reevaluation of transformations in complex view pipelines. * **NEW:** `ranges::contains` algorithm. * **NEW:** `enable_safe_range` trait for opting in to the _forwarding-range_ concept. These are ranges whose iterators remain valid even after the range itself has been destroyed; _e.g._, `std::string_view` and `ranges::subrange`. * The `readable` concept has changed such that types that are not _indirectly_ readable with `operator*` (_e.g., `std::optional`) no longer satisfy that concept. * Using `views::join` to join a range of xvalue ranges works again. * The following range access primitives no longer accept temporary containers (_i.e._, they refuse to return references known to be dangling): - `range::front` - `range::back` - `range::at` - `range::index` * `views::concat` with a single argument now simply returns its argument. * `ranges::ostream_iterator<T>` now coerces arguments to `T` before inserting them into the wrapped ostream. * Smaller iterators for `views::transform` and `views::take_while`. * `actions::split` and `actions::split_when` now support partial application and pipelining ([\#1085](https://github.com/ericniebler/range-v3/issues/1085)). * `views::group_by` and its iterator both get a `.base()` member to access the underlying range and iterator, respectively. * Improved diagnostics with clang. * Assorted bug fixes and compiler work-arounds: [\#284](https://github.com/ericniebler/range-v3/issues/284), [\#491](https://github.com/ericniebler/range-v3/issues/491), [\#499](https://github.com/ericniebler/range-v3/issues/499), [\#871](https://github.com/ericniebler/range-v3/issues/871), [\#1022](https://github.com/ericniebler/range-v3/issues/1022), [\#1043](https://github.com/ericniebler/range-v3/issues/1043), [\#1081](https://github.com/ericniebler/range-v3/issues/1081), [\#1085](https://github.com/ericniebler/range-v3/issues/1085), [\#1101](https://github.com/ericniebler/range-v3/issues/1101), [\#1116](https://github.com/ericniebler/range-v3/issues/1116), [\#1296](https://github.com/ericniebler/range-v3/issues/1296), [\#1305](https://github.com/ericniebler/range-v3/issues/1305), and [\#1335](https://github.com/ericniebler/range-v3/issues/1335). Many thanks to GitHub users @CaseyCarter, @morinmorin, @h-2, @MichaelWJung, @johelegp, @marehr, @alkino, @xuning97, @BRevzin, and @mpusz for their contributions. \section v0-9-1 Version 0.9.1 _Released:_ Sept 1, 2019. gcc-9.x portability fixes. \section v0-9-0 Version 0.9.0 "Std::ranger Things" _Released:_ Aug 26, 2019. Bring many interfaces into sync with the C++20 draft. * **NEW:** An improved concepts portability layer with macros that use C++20 concepts when the compiler supports them. * **NEW:** An improved directory structure that keeps disjoint parts of the library -- iterators, ranges, algorithms, actions, views, functional programming support, and general utilities -- physically separate. * **NEW:** A `RANGES_DEEP_STL_INTEGRATION` configuration option that makes your STL implementation default to structural conformance to infer iterator category, as in C++20. Applies to libc++, libstdc++, and MSVC's Standard Library. * **NEW:** A `ranges::cpp20` namespace that contains all the functionality of C++20's `std::ranges` namespace. * All concept names have been given standard_case (renamed from PascalCase) and have been harmonized with the C++20 draft. * The following range access customization points no longer accept rvalue ranges by default: - `ranges::begin` - `ranges::end` - `ranges::rbegin` - `ranges::rend` - `ranges::cbegin` - `ranges::cend` - `ranges::crbegin` - `ranges::crend` - `ranges::data` - `ranges::cdata` * Iterators may specify an `iterator_concept` type alias in addition to `iterator_category` -- either as a nested type or as a member of a `std::iterator_traits` specialization -- to denote conformance to the C++20 iterator concepts as distinct from the C++98 iterator requirements. (See [P1037 "Deep Integration of the Ranges TS"](http://wg21.link/p1037) for more information.) * The `ranges::value_type` trait has been renamed to `readable_traits`. * The `ranges::difference_type` trait has been renamed to `incrementable_traits`. * The `ranges::iterator_category` trait has been deprecated. Specialize `std::iterator_traits` to non-intrusively specify an iterator's category and (optionally) concept. * Rename the `ranges::view` namespace to `ranges::views` and `ranges::action` to `ranges::actions` (with deprecated namespace aliases for migration). * Rename `view::bounded` to `views::common`. * Rename `unreachable` to `unreachable_sentinel_t`. * Change `dangling` from a class template that wraps an iterator to a class that acts as a placeholder for an iterator that would otherwise dangle. * Implement C++20's `subrange` as a view that wraps an iterator/sentinel pair; deprecate `iterator_range`. * Deprecate implicit conversion from view types to containers; rename `ranges::to_` to `ranges::to` and extend it to support converting a range-of-ranges to a container-of-containers. * Deprecate the `ranges::v3` inline versioning namespace. * The following views have had minor changes to bring them into conformance with the C++20 working draft: - `join_view` - `single_view` - `empty_view` - `split_view` - `reverse_view` - `all_view` - `take_view` - `iota_view` <p/>`iota_view<std::[u]intmax_t>`, in particular, is given a user-defined `difference_type` that avoids integer overflow. * New names for the iterator and range type aliases: | Old Name | New Name | |-------------------------------|-----------------------------| | `value_type_t` | `iter_value_t` | | `reference_t` | `iter_reference_t` | | `difference_type_t` | `iter_difference_t` | | `size_type_t` | _deprecated_ | | `rvalue_reference_t` | `iter_rvalue_reference_t` | | `range_value_type_t` | `range_value_t` | | `range_difference_type_t` | `range_difference_t` | | `range_size_type_t` | `range_size_t` | \section v0-5-0 Version 0.5.0 _Released:_ Apr 30, 2019. * **NEW:** MSVC support, from @CaseyCarter :tada: (See the docs for the list of supported compilers.) * **NEW:** `view::enumerate`, from @MikeGitb * **NEW:** `view::addressof`, from @tower120 * **NEW:** `unstable_remove_if` algorithm and action, from @tower120 * **NEW:** `adjacent_remove_if` algorithm and action, from @cjdb * **NEW:** `ostream_joiner`, from @sv1990 * `view::drop_while` and `view::take_while` get projection support, from @mrpi * `view::filter` and `view::remove_if` get projection support, from @mrpi * `view::unique` accepts optional comparison operator, from @tete17 * `action::slice` supports sliding from the end, from @tete17 * Support coroutines on MSVC, from @CaseyCarter * Faster `view::generate_n`, from GitHub user @tower120 * Improved aligned new detection for libc++ on iOS, from @mtak- * Various CMake improvements, from @johelegp * `view_adaptor` supports `basic_iterator`-style mixins, from @tower120 * Fix `ranges::advance` for random-access iterators for `n==0`, from @tower120 * Bugs fixed: [#755](https://github.com/ericniebler/range-v3/issues/755), [#759](https://github.com/ericniebler/range-v3/issues/759), [#942](https://github.com/ericniebler/range-v3/issues/942), [#946](https://github.com/ericniebler/range-v3/issues/946), [#952](https://github.com/ericniebler/range-v3/issues/952), [#975](https://github.com/ericniebler/range-v3/issues/975), [#978](https://github.com/ericniebler/range-v3/issues/978), [#986](https://github.com/ericniebler/range-v3/issues/986), [#996](https://github.com/ericniebler/range-v3/issues/996), [#1041](https://github.com/ericniebler/range-v3/issues/1041), [#1047](https://github.com/ericniebler/range-v3/issues/1047), [#1088](https://github.com/ericniebler/range-v3/issues/1088), [#1094](https://github.com/ericniebler/range-v3/issues/1094), [#1107](https://github.com/ericniebler/range-v3/issues/1107), [#1129](https://github.com/ericniebler/range-v3/issues/1129) \section v0-4-0 Version 0.4.0 _Released:_ Oct 18, 2018. - Minor interface-breaking changes: * `single_view` returns by `const &` (see [#817](https://github.com/ericniebler/range-v3/issues/817)). * `reverse_view` of a non-Sized, non-Bounded RandomAccess range (eg., a null-terminated string) no longer satisfies SizedRange. * The `generate` and `generate_n` views now return the generated values by xvalue reference (`T &&`) to the value cached within the view (see [#905](https://github.com/ericniebler/range-v3/issues/905)). * Views no longer prefer returning constant iterators when they can; some views have different constant and mutable iterators. - Enhancements: * Views can successfully adapt other views that have different constant and mutable iterators. * The `single` and `empty` views are much closer to the versions as specified in [P0896](http://wg21.link/P0896). - Bug fixes: * "single_view should not copy the value" [#817](https://github.com/ericniebler/range-v3/issues/817). * "Calling back() on strided range does not return the correct last value in range" [#901](https://github.com/ericniebler/range-v3/issues/901). * "generate(foo) | take(n) calls foo n+1 times" [#819](https://github.com/ericniebler/range-v3/issues/819). * "generate seems broken with move-only return types" [#905](https://github.com/ericniebler/range-v3/issues/905). * "Unexpected behavior in generate with return by reference" [#807](https://github.com/ericniebler/range-v3/issues/807). * "Inconsistent behaviour of ranges::distance with ranges::view::zip using infinite views." [#783](https://github.com/ericniebler/range-v3/issues/783). * "Infinite loop when using ranges::view::cycle with an infinite range" [#780](https://github.com/ericniebler/range-v3/issues/780). * "Composing ranges::view::cycle with ranges::view::slice" [#778](https://github.com/ericniebler/range-v3/issues/778). * "cartesian_product view, now with moar bugs." [#919](https://github.com/ericniebler/range-v3/issues/919). \section v0-3-7 Version 0.3.7 _Released:_ Sept 19, 2018. - Improved support for clang-cl (thanks to @CaseyCarter). - Fix for `any_view<T, category::sized | category::input>` (see #869). - Fix `iter_move` of a `ranges::reverse_iterator` (see #888). - Fix `move_sentinel` comparisons (see #889). - Avoid ambiguity created by `boost::advance` and `std::advance` (see #893). \section v0-3-6 Version 0.3.6 _Released:_ May 15, 2018. - NEW: `view::exclusive_scan` (thanks to GitHub user @mitsutaka-takeda). - All views get non-`const` overloads of `.empty()` and `.size()` (see [ericniebler/stl2\#793](https://github.com/ericniebler/stl2/issues/793)). - Upgrade Conan support for conan 1.0. - `subspan` interface tweaks. - Fix bug in `view::split` (see [this stackoverflow question](https://stackoverflow.com/questions/49015671)). - Fix bug in `view::stride` (see [ericniebler/stl2\#805](https://github.com/ericniebler/stl2/issues/805)). - Fix `const`-correctness problem in `view::chunk` (see [this stackoverflow question](https://stackoverflow.com/questions/49210190)). - Replace uses of `ranges::result_of` with `ranges::invoke_result`. - Fix potential buffer overrun of `view::drop` over RandomAccessRanges. - Lots of `view::cartesian_product` fixes (see [ericniebler/stl2\#820](https://github.com/ericniebler/stl2/issues/820), [ericniebler/stl2\#823](https://github.com/ericniebler/stl2/issues/823)). - Work around gcc-8 regression regarding `volatile` `std::initializer_list`s (see [ericniebler/stl2\#826](https://github.com/ericniebler/stl2/issues/826)). - Fix `const`-correctness problem of `view::take`. \section v0-3-5 Version 0.3.5 _Released:_ February 17, 2018. - Rvalues may satisfy `Writable` (see [ericniebler/stl2\#387](https://github.com/ericniebler/stl2/issues/387)). - `view_interface` gets a bounds-checking `at` method. - `chunk_view` works on Input ranges. - Fix bug in `group_by_view`. - Improved concept checks for `partial_sum` numeric algorithm. - Define `ContiguousIterator` concept and `contiguous_iterator_tag` iterator category tag. - Sundry `span` fixes. - `action::insert` avoids interfering with `vector`'s exponentional growth strategy. - Add an experimental `shared` view for views that need container-like scratch space to do their work. - Faster, simpler `reverse_view`. - Rework `ranges::reference_wrapper` to avoid [LWG\#2993](https://wg21.link/lwg2993). - Reworked `any_view`, the type-erased view wrapper. - `equal` algorithm is `constexpr` in C++14. - `stride_view` no longer needs an `atomic` data member. - `const`-correct `drop_view`. - `adjacent_filter_view` supports bidirectional iteration. - Massive `view_adaptor` cleanup to remove the need for a `mutable` data member holding the adapted view. - Fix `counting_iterator` post-increment bug. - `tail_view` of an empty range is an empty range, not undefined behavior. - Various portability fixes for gcc and clang trunk. \section v0-3-0 Version 0.3.0 _Released:_ June 30, 2017. - Input views may now be move-only (from @CaseyCarter) - Input `any_view`s are now *much* more efficient (from @CaseyCarter) - Better support for systems lacking a working `<thread>` header (from @CaseyCarter) \section v0-2-6 Version 0.2.6 _Released:_ June 21, 2017. - Experimental coroutines with `ranges::experimental::generator` (from @CaseyCarter) - `ranges::optional` now behaves like `std::optional` (from @CaseyCarter) - Extensive bug fixes with Input ranges (from @CaseyCarter) \section v0-2-5 Version 0.2.5 _Released:_ May 16, 2017. - `view::chunk` works on Input ranges (from @CaseyCarter) - `for_each_n` algorithm (from @khlebnikov) - Portability fixes for MinGW, clang-3.6 and -3.7, and gcc-7; and cmake 3.0 \section v0-2-4 Version 0.2.4 _Released:_ April 12, 2017. Fix the following bug: - `action::stable_sort` of `vector` broken on Clang 3.8.1 since ~last Xmas (ericniebler/range-v3#632). \section v0-2-3 Version 0.2.3 _Released:_ April 4, 2017. Fix the following bug: - iterators that return move-only types by value do not satisfy Readable (ericniebler/stl2#399). \section v0-2-2 Version 0.2.2 _Released:_ March 30, 2017. New in this release: - `view::linear_distribute(from,to,n)` - A view of `n` elements between `from` and `to`, distributed evenly. - `view::indices(n)` - A view of the indices `[0,1,2...n-1]`. - `view::closed_indices(n)` - A view of the indices `[0,1,2...n]`. This release deprecates `view::ints(n)` as confusing to new users. \section v0-2-1 Version 0.2.1 _Released:_ March 22, 2017. New in this release: - `view::cartesian_product` - `action::reverse` \section v0-2-0 Version 0.2.0 _Released:_ March 13, 2017. Bring many interfaces into sync with the Ranges TS. - Many interfaces are simply renamed. The following table shows the old names and the new. (All names are in the `ranges::v3` namespace.) | Old Name | New Name | |-------------------------------|---------------------------| | `indirect_swap` | `iter_swap` | | `indirect_move` | `iter_move` | | `iterator_value_t` | `value_type_t` | | `iterator_reference_t` | `reference_t` | | `iterator_difference_t` | `difference_type_t` | | `iterator_size_t` | `size_type_t` | | `iterator_rvalue_reference_t` | `rvalue_reference_t` | | `iterator_common_reference_t` | `iter_common_reference_t` | | `range_value_t` | `range_value_type_t` | | `range_difference_t` | `range_difference_type_t` | | `range_size_t` | `range_size_type_t` | | `range_iterator_t` | `iterator_t` | | `range_sentinel_t` | `sentinel_t` | - `common_iterator` now requires that its two types (`Iterator` and `Sentinel`) are different. Use `common_iterator_t<I, S>` to get the old behavior (i.e., if the two types are the same, it is an alias for `I`; otherwise, it is `common_iterator<I, S>`). - The following iterator adaptors now work with iterators that return proxies from their postfix increment operator (i.e., `operator++(int)`): * `common_iterator` * `counted_iterator` - The following customization points are now implemented per the Ranges TS spec and will no longer find the associated unconstrained overload in namespace `std::`: * `ranges::begin` * `ranges::end` * `ranges::size` * `ranges::swap` * `ranges::iter_swap` (In practice, this has very little effect but it may effect overloading in rare situations.) - `ranges::is_swappable` now only takes one template parameter. The new `ranges::is_swappable_with<T, U>` tests whether `T` and `U` are swappable. `ranges::is_swappable<T>` is equivalent to `ranges::is_swappable_with<T &, T &>`. - The following object concepts have changed to conform with the Ranges TS specification, and approved changes (see [P0547](http://wg21.link/p0547)): * `Destructible` * `Constructible` * `DefaultConstructible` * `MoveConstructible` * `MoveConstructible` * `Movable` * `Assignable` - The `View` concept is no longer satisfied by reference types. - The syntax for defining a concept has changed slightly. See [iterator/concepts.hpp](https://github.com/ericniebler/range-v3/blob/master/include/range/v3/iterator/concepts.hpp) for examples. \section v0-1-1 Version 0.1.1 - Small tweak to `Writable` concept to fix #537. \section v0-1-0 Version 0.1.0 - March 8, 2017, Begin semantic versioning
0
repos/range-v3
repos/range-v3/doc/ignore_errors.sh
#!/bin/bash $* 2>/dev/null exit 0
0
repos/range-v3/doc
repos/range-v3/doc/std/header.html
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="607"> <tr> <td width="172" align="left" valign="top">Document number:</td> <td width="435"> <span style="background-color: #FFFF00">D4128</span>=yy-nnnn </td> </tr> <tr> <td width="172" align="left" valign="top">Date:</td> <td width="435">2014-10-10</td> </tr> <tr> <td width="172" align="left" valign="top">Project:</td> <td width="435">Programming Language C++, Library Working Group</td> </tr> <tr> <td width="172" align="left" valign="top">Reply-to:</td> <td width="435"> Eric Niebler &lt;<a href="mailto:[email protected]">[email protected]</a>&gt;,<br/> Sean Parent &lt;<a href="mailto:[email protected]">[email protected]</a>&gt;,<br/> Andrew Sutton &lt;<a href="mailto:[email protected]">[email protected]</a>&gt; </td> </tr> </table>
0
repos/range-v3/doc
repos/range-v3/doc/std/D4128.md
--- pagetitle: Ranges for the Standard Library, Revision 1 title: Ranges for the Standard Library, Revision 1 ... Introduction ===== This paper outlines what support for ranges in the C++ standard library might look like. Rather than presenting a final design, this paper proposes a set of concepts and guidelines for using them to implement range-based versions of the standard algorithms. It draws inspiration from the [Boost.Range][2][@boostrange] library, the range algorithms in [Adobe Source Libraries][3][@asl], *Elements of Programming* by Stepanov and McJones (2009) [@stepanov09], and from [N3351 "A Concept Design for the STL"][8] by Stroustrup and Sutton (2012) [@n3351]. In addition to presenting the concepts and guidelines, this paper discusses the rationale behind each, weighing different design options. The decision to defer any discussion about specific wording was taken in recognition of the fact that any range design is likely to undergo significant revision by the committee. The paper is intended merely as a starting point for discussion and as a basis for future work. This paper assumes the availability of Concepts Lite; however, everything suggested here has been implemented in C++11, where Concepts Lite has been simulated with the help of generalized SFINAE for expressions. Motivation and Scope ===== A *range* is an object that refers to a sequence of elements, conceptually similar to a pair of iterators. One prime motivation for ranges is to give users a simpler syntax for calling algorithms. Rather than this: std::vector<int> v { /*...*/ }; std::sort( v.begin(), v.end() ); Ranges would give us a pithier syntax: std::sort( v ); Allowing algorithms to take a single range object instead of separate begin and end iterators brings other benefits besides convenience. In particular: * It eliminates the possibility of mismatched iterators. * It opens the door to *range adaptors* which lazily transform or filter their underlying sequence in interesting ways. Range adaptors are far more compelling than iterator adaptors due to the fact that only a single object, the range object, needs to be adapted; hence, adaptors can be easily chained to create lazy computational pipelines, as in the code below which sums the first 10 squares: int total = accumulate(view::iota(1) | view::transform([](int x){return x*x;}) | view::take(10), 0); The standard defines the term "range" in [iterator.requirements.general]: > [...] in general, a range `[i,j)` refers to the elements in the data structure starting with the element pointed to by `i` and up to but not including the element pointed to by `j`. Range `[i,j)` is valid if and only if `j` is reachable from `i`. From the perspective of the standard library, a range *is* a pair of iterators. But there are other interesting ways to denote a range of elements: * An iterator and a count of elements * An iterator and a (possibly stateful) predicate that indicates when the range is exhausted. One of these three range types can be used to denote all other range types, like an iterator and a sentinel value (e.g. a null-terminated string), or a range that spans disjoint ranges. Ideally, we would like our Range abstraction to be general enough to accommodate the three different kinds of ranges since that would increase the applicability of the algorithms. ## Impact on the Standard Although this paper does not offer specific wording for any additions to the standard, we imagine that proper support for ranges in C++ would involve changes to the following parts of the standard: - New library-wide concepts related to ranges. - New iterator algorithms for efficiently dealing with the new abstractions. - Changes to existing algorithms to constrain the templates with concepts. - Additional overloads of existing algorithms that accept ranges instead of pairs of iterators. - Changes to the containers to allow containers to be constructed and assigned from ranges, and to allow range-based insert operations. - A new library section for range adaptors, which are views of existing data that have been transformed or filtered and that compose with other views. - General utilities for the construction of custom range adaptors. - A minor change to the specification of the range-based `for` to make it more efficient and general. Future papers will make specific recommendations for all of the above, modulo any feedback on the design presented here. Proposed Design ===== The design space for ranges is surprisingly large. At one end of the spectrum lies [Boost.Range][2][@boostrange] and [Adobe's ASL][3][@asl] in which ranges are a thin abstraction on top of iterators, which remain the primitives that glue together data structures and algorithms. At the other end of the spectrum we find the [D Standard Library's std.range module][4][@drange], in which ranges and operations on them are the primitives themselves. This proposal picks a single point in this design space, and here we present the decisions that led to the selection of that point, along with guidelines to be applied to the standard library and the rationale for each choice. ## Design Goals We feel that a well-designed range abstraction would: * Allow algorithms to operate on the three kinds of ranges with low or no abstraction penalty and a minimum of syntactic noise, * Allow range-based algorithms to share implementation with iterator-based algorithms, * Make it easy for users to reason about the complexity and expense of range operations (e.g. How many passes over the data are made? Are the elements copied? etc.), * Protect the user from lifetime issues, * Make it straightforward for users to make their types model one of the range concepts. It is helpful at this point to reflect on the success of C++11's range-based `for` loop. It succeeds because most of the types over which one would want to iterate already define iterators and `begin`/`end` members. Cleanly and efficiently interoperating with and reusing the existing abstractions of the STL is critical to the success of any range extensions. ## High-Level Design At the highest level, this paper proposes the addition of two related range concepts: Iterable and Range. An *Iterable* type is one for which we can call `begin()` and `end()` to yield an iterator/sentinel pair. (Sentinels are described below.) The Iterable concept says nothing about the type's constructibility or assignability. Range-based standard algorithms are constrained using the Iterable concept. Consider: int buf[5000]; // Fill buf std::sort( buf ); `buf` denotes a random access range of elements, so we should be able to sort it; but native arrays are neither copyable nor assignable, so these operations should not be required by whatever range-like concept is used to constrain `sort`. The above line of code is equivalent to: using std::begin; using std::end; std::sort( begin( buf ), end( buf ) ); For an Iterable object `o`, the concept requires the following: auto b = begin( o ); // b models Iterator auto e = end( o ); // e models Regular bool f = (b == e); // b and e model EqualityComparable Algorithms will typically be implemented to take iterator/sentinel pairs, rather than the iterator/iterator pairs as they do now. A typical algorithm might look like: template<Iterator I, Regular S, /*...*/> requires EqualityComparable<I, S> I some_algo(I first, S last, /*...*/) { for(; first != last; ++first) /*...*/ return first; } template<Iterable R, /*...*/> IteratorOf<R> some_algo( R & r, /*...*/ ) { return some_algo( begin(r), end(r), /*...*/ ); } The *Range* concept is modeled by lightweight objects that denote a range of elements they do not own. A pair of iterators can be a model of Range, whereas a `vector` is not. Range, as opposed to Iterable, requires copyability and assignability. Copying and assignment are required to execute in constant time; that is, the cost of these operations is not proportional to the number of elements in the Range. The Range concept refines the Iterable concept by additionally requiring following valid expressions for an object `o` of type `O`: // Constructible: auto o1 = o; auto o2 = std::move(o); O o3; // default-constructed, singular // Assignable: o2 = o1; o2 = std::move(o1); // Destructible o.~O(); The Range concept exists to give the range adaptors consistent and predictable semantics, and memory and performance characteristics. Since adaptors allow the composition of range objects, those objects must be efficiently copyable (or at least movable). The result of adapting a Range is a Range. The result of adapting a container is also a Range; the container -- or any Iterable that is not already a Range -- is first converted to a Range automatically by taking the container's `begin` and `end`. The precise definitions of the suggested concepts are given in [Section 4](#concept-definitions), along with other supporting concepts that have proven useful while porting the algorithms. The use of sentinels instead of iterators as an Iterable's bound is best understood by seeing how the three different kinds of ranges can be made to model the Iterable concept. Below is a sketch of how `begin` and `end` might work for each kind. - **Pair of iterators**: An end iterator is a perfectly acceptable sentinel. Existing code that uses iterator pairs to call STL algorithms will continue working with no changes. - **Iterator and predicate**: `begin(rng)` can return a normal iterator, `first`. `end(rng)` can return a sentinel `last` such that `first == last` returns the result of calling `last.predicate_(*first)`. See [Appendix 1](#appendix-1-sentinels-and-code-generation) for a discussion about the code generation benefits of letting the sentinel have a different type than the iterator. - **Iterator and count**: `begin(rng)` can return an iterator `first` that bundles the underlying iterator with the count to the end. Incrementing the iterator decrements the count. `end(rng)` can return an empty sentinel `last` such that `first == last` returns the result of `first.count_ == 0`. See [Appendix 4](#appendix-4-on-counted-ranges-and-efficiency) for a discussion of the performance implications of this design. ## Design Decisions, Guidelines, and Rationale Below we present the decisions that led to the chosen high-level design, along with guidelines to be applied to the standard library and the rationale for each choice. ### Iterator Operations are Primitive The most fundamental decision facing the designer of a generic library like the STL is: what are the *basis operations*? Basis operations are the primitive operations upon which all other desired operations can be efficiently built. In the STL, those operations are the operations on iterators, and they are clustered into the familiar iterator concept hierarchy. Two iterators are required to denote a range. Can these two positions be bundled together into a single range object and -- more ambitiously -- can operations on ranges be made the basis, obviating the need for iterators entirely? Below we describe two libraries that use range operations as the basis, and describe why they are not a good fit for the C++ Standard Library. #### D's Ranges In the C++ Standard Library, iterators fill several roles: * Two of them denote a sequence of elements. * One of them denotes a position within a range. * They allow access to an element at the current position. * They allow access to subsequent (and sometimes prior) positions in the sequence. The [D Standard Library][4][@drange] takes a different approach. In D, ranges and the operations on them form the basis operations of the standard algorithms. D-style ranges fill the following roles: * They denote a sequence of elements. * They allow access to the front of the range, and sometimes to the back or the N-th. * They allow the removal of elements from the front of the range, and sometimes from the back. Would C++ benefit from a similar design? The argument typically given in favor of D's ranges is that they lead to simpler code, both for the algorithms that operate on ranges as well as for users who wish to create custom range types. Code that manipulates positions directly can be harder to reason about and thus more bug-prone, and implementing custom iterators is famously complicated. D-style ranges can only ever shrink, and they have no notion of position within sequence. If one were to try to implement C++'s iterators on top of D's ranges, one would immediately run into trouble implementing ForwardIterator's `operator==`. As D's ranges do not represent position, there would be no way to test two ranges to see if their heads referred to the same element. (The `front` member function that returns the front of a D range is not required to return a reference, nor would that be sufficient to implement a hypothetical `hasSameFront` function; a repeating range might return the same element multiple times, leading to false positives.) Additionally, there would be trouble implementing BidirectionalIterator's `operator--` or RandomAccessIterator's `operator+=` as that might require a range to grow, and D ranges can't grow. On the other hand, two C++ iterators can easily be used to implement a D-style range; thus, every range-based design can be implemented in terms of iterators. Since iterators can implement D ranges, but D ranges cannot be used to implement iterators, we conclude that iterators form a more powerful and foundational basis. D avoids the limits of its ranges by carefully designing the algorithms such that the missing functionality is never needed. This can sometimes require some creativity, and leads to some awkward productions. A good example is the `find` family of algorithms. Since `find` cannot return the position of the found element, it must instead return a range. But which range to return? The D Standard Library has as many `find` algorithms as there are answers to this question ([`find`](http://dlang.org/phobos/std_algorithm.html#find), [`findSkip`](http://dlang.org/phobos/std_algorithm.html#.findSkip), [`findSplit`](http://dlang.org/phobos/std_algorithm.html#.findSplit), [`findSplitBefore`](http://dlang.org/phobos/std_algorithm.html#.findSplitBefore), [`findSplitAfter`](http://dlang.org/phobos/std_algorithm.html#.findSplitAfter)). All these algorithms find an element in a range; they only differ in the information they return. In contrast, C++ has just one `find` algorithm; it returns a position, and the user is free to construct any desired range from that. [Appendix 3](#appendix-3-d-ranges-and-algorithmic-complexity) contains an example of an algorithm that cannot be implemented with the same algorithmic complexity using D-style ranges. Any algorithm that needs to freely move an iterator forward and backward between two bounds will suffer from the same fundamental problem. Just writing the signature of an algorithm like `rotate`, which takes as an argument a position in a sequence, is challenging without a way to specify a position. Since C++ iterators cannot be implemented on top of D's ranges, iterators have to stay both for the increased expressive power and for backwards compatibility. To additionally provide D-style ranges -- essentially offering an incompatible set of basis operations -- would create a schism within the standard library between range-based and iterator-based algorithms, which couldn't share code. We, the authors, consider such a schism unacceptable. #### Position-Based Ranges If a range-first design that abandons "position" as a representable entity is undesirable for C++, perhaps adding position back in yields a satisfactory design. That is the approach taken by [James Touton's range library][5][@bekennrange], where ranges -- together with a new Position concept -- are the primitives. A Position, as its name suggests, represents a position in a range. Unlike an iterator, a position cannot be used to access the element at that position without the range into which it refers, nor can the position be advanced without the range. This design has the following advantages: * In making position a representable entity, it avoids the sometimes awkward constructions of D's range library. * In requiring the range in order to dereference the position, it avoids all dangling iterator issues. * In requiring the range in order to change the position, it makes range-checking trivial. This is a boon not just for debuggability, but also for the design of certain range adaptors like filter and stride whose iterators need to know the end of the range so as not to walk past it. * It permits a clean separation of element traversal and access, much like the suggested [cursor/property map abstraction][11][@n1873]. It is possible to implement iterators on top of a position-based range by bundling a position with a pointer to a range into an iterator. However that results in iterators that may be fatter than necessary. A more workable approach would be to reimplement all the algorithms in terms of the position-based range primitives, and have the iterator-based overloads (that are retained for backwards-compatibility) forward to the range-based versions. In such a scheme, two iterators can be turned into a position-based range by wrapping them in a single range object and using the iterators themselves as the "positions". Although workable in principle, in practice it means there will be two ways of representing a range: an object with `begin()` and `end()` members that return iterators, and one with `begin_pos()` and `end_pos()` members that return positions; and every function that accepts ranges will need to account for that. It would mean that everybody would need to learn a new way to write algorithms. And it would mean that sometimes algorithms would return iterators and sometimes they would return positions, and that users would need to learn a new way to access the elements of a range. As appealing as the design is, it is too disruptive a change for the Standard Library. #### Basis-Operations: Summary In short, it just doesn't seem worth the trouble to change basis-operation horses in midstream. Iterators have a proven track record as a solid basis for the algorithms, and the C++ community has a heavy investment in the abstraction. The most heavily used and vetted C++ range libraries, Boost.Range and ASL Ranges, are built on top of iterators and have shown that it works in practice. This proposal follows suit. ### Ranges Cannot Own Elements As described above, a Container is not a Range; it is, however, an Iterable. Distinguishing between the two makes it possible to be explicit about where copyability is required, and with what performance characteristics. The algorithms discussed in this proposal don't require any distinction between Ranges and Containers since they never copy or assign the ranges passed to them; they only request the `begin` and `end` iterators. The distinction between Iterables and Ranges only becomes important when defining adaptor chains. What does code like the following mean? auto rng = v | view::reverse; This creates a view of `v` that iterates in reverse order. Now: is `rng` copyable, and if so, how expensive is the copy operation? If `v` is a `vector`, can `rng` safely outlive `v`? How about if `v` is just a pair of iterators? What happens when a user does `*rng.begin() = 42`? Is `v` mutated? How do the answers change if we replaced `v` with an rvalue expression? If a copy of `rng` is made, and an element is mutated through the copy, does the original `rng` object "see" the change? By specifying that Ranges do *not* own their elements, and further specifying that range adaptors operate on and produce Ranges (not Containers), we are able to answer these questions in a clear and consistent way. The result of a chain of range adaptors is always a lightweight object that is cheap to copy and assign (O(1) as opposed to O(N)), and that refers to elements whose lifetime is managed by some other object. Mutating an element through the resulting Range object mutates the underlying sequence. Copies of the resulting range are aliases to the same elements, and mutations to the elements are visible through all the aliased ranges. If `v` is a Range in the above line of code, it is copied into the adaptor. If it is a `vector`, the `vector` is first used to construct a Range by taking the `begin` and `end` of the Container. This happens automatically. The downside of this design is that it is sometimes desirable to do this: // Try to adapt an rvalue container auto rng = vector<int>{1,2,3,4} | view::reverse; // OK? Adaptors operate on and yield Ranges; other Iterables (i.e., containers) are used to construct Ranges by first taking their begin and end. The code above is unsafe because `rng` will be left holding invalid iterators into a container that no longer exists. Our solution is to disallow the above code. *It is illegal to adapt an rvalue non-Range.* (Adapting rvalue Ranges, however, is perfectly acceptable; indeed necessary if adaptor pipelines are to work.) See [Appendix 6](#on-distinguishing-ranges-from-non-range-iterables) for the mechanics of how we distinguish between Iterables and Ranges. The alternative is for the rvalue container to be moved (or copied) into the adapted range and held by value. The resulting object would therefore no longer model Range; it would model Iterable. The authors feel that this weakening of the requirements on the return type makes it difficult to reason about the semantics and algorithmic complexity of range adaptors. The recommendation is to first declare the container and then create the adaptor separately. ### Ranges Are Semiregular We've already decided that Ranges (not Iterables) are copyable and assignable. They are, in the terminology of EoP[@stepanov09] and [N3351][8][@n3351], Semiregular types. It follows that copies are independent, even though the copies are both aliases of the same underlying elements. The ranges are independent in the same way that a copy of a pointer or an iterator is independent from the original. Likewise, iterators from two ranges that are copies of each other are also independent. When the source range goes out of scope, it does not invalidate an iterator into the destination range. Semiregular also requires DefaultConstructible in [N3351][8]. We follow suit and require all Ranges to be DefaultConstructible. Although this complicates the implementation of some range types, it has proven useful in practice, so we have kept this requirement. It is tempting to make Ranges Regular by requiring that they be EqualityComparable. A Range type would satisfy this additional requirement by testing whether two Ranges refer to the same elements in a sequence. (Note that it would be an error for `operator==` to test corresponding elements in two Ranges for equality, in the same way that it would be an error for `operator==` invoked on two pointers to compare the pointed-to elements. The state of a Range is not influenced by the content of its elements; a Range is defined only by the identity of the elements it references.) Although such a requirement is appealing in theory, it has problems: * It might conflict with users' expectations of what `rng1 == rng2` means. (See string_view for an example of a Range-like class that implements `operator==` in terms of the values of its elements, rather than identity.) * It is impossible to implement with those semantics in O(1) for some range types; for example, a filter range that stores a predicate. Functors and lambdas are generally not EqualityComparable. Another option is to allow Ranges to trivially model EqualityComparable by narrowly defining the domain over which the operation is valid. Iterators may only be compared if they refer into the same range. We can extend the reasoning to Ranges, which are logically little more than pairs of iterators. Taking this tack, we could allow a Range type to define its `operator==` as: rng1.begin() == rng2.begin() && rng1.end() == rng2.end() The assumption being that the operation is invalid if `rng1` and `rng2` refer to different elements. Although principled (for some set of principles), such a definition is almost certain to lead users into undefined behavior-land. As a result of the above, we have decided that the Range concept should not require EqualityComparable. Ranges are Semiregular, not Regular. If a user would like to check to see if two ranges have elements that compare equal, we suggest the `equal` algorithm: if(std::equal(rng1, rng2)) // ... ### Range Iterators Cannot Outlive Their Ranges Containers own their elements, so it is clear that the container must outlive the iterators it generates. But is the same true for a Range if it does not own its elements? For a trivial range consisting of two iterators, it's clearly not true; the iterators *may* outlive the range. It turns out that if we require that all range's iterators be permitted to outlive the range, a great many interesting range types become significantly more expensive at runtime. A good case study is the filter view. A filter view takes a range and a predicate, and presents a view of the sequence that skips the elements for which the predicate is false. (The filter view can be thought of as a lazy equivalent of the `copy_if` algorithm.) The existence of the `boost::filter_iterator` shows that such an iterator *can* be made such that it doesn't depend on a range, but at a cost. The `filter_iterator` stores: 1. An iterator that indicates the current position in the underlying sequence. 2. An iterator that indicates the end of the underlying sequence (needed by the increment operators to avoid falling off the end while searching for an element that satisfies the predicate). 3. The predicate. In today's STL, the begin and end iterators must have the same type, and they are both needed to call an algorithm. Thus, the information in (2) and (3) is duplicated. Also, the predicate may be expensive to copy, given the ease with which capture-by-value lambdas and `std::function`s can be created. When such iterators are composed with other kinds of views (e.g., a transformed, filtered view), the bloat compounds exponentially (see [Index-Based Ranges][10][@n3782]). By relaxing the constraint that a range's begin and end must have the same type, we can avoid the duplication, but the begin iterator still must hold everything, which is potentially expensive. If we could rely on the range object outliving the iterator, we can make the filter iterators smaller and lighter. The range object can hold the predicate and the underlying range's begin/end iterators. The filter view's iterator only needs to hold the current position and a pointer back to the range object. The same logic applies to the transform view, which applies a transformation function to elements on the fly. If the iterators are required to be valid beyond the lifetime of the transform range, then the transformation function must be cached inside each iterator. This could make the iterators expensive to copy. An implementor might instead want the freedom to put the transformation function in the range object. A final example is `istream_iterator<T>`. Every `istream_iterator<T>` holds a single cached `T` object inside it. If `T` is an expensive-to-copy type like `std::string`, then copying `istream_iterator`s is potentially causing dynamic allocations. The STL assumes iterators are cheap to copy and copies them freely. A better design would see the cached `string` object move into an `istream_range` object whose iterators merely stored pointers back to the range. This would make the iterators smaller and cheaper to copy, but they would become invalid once the range was destroyed. This tradeoff is probably worth it. ### An Iterable's End May Have a Different Type Than Its Begin In today's STL, `c.begin()` must have the same type as `c.end()`. This is because the only kind of range the STL supports is a pair of iterators. However, we've given examples of other kinds of ranges we would like to support, such as an iterator and a predicate, and an iterator and a count. These kinds of ranges can already be supported by shoe-horning them into the pair-of-iterators mold, but at a cost (see [Appendix 1](#appendix-1-sentinels-and-code-generation)). Loosening the constraints of the type of Iterable's end makes it possible to accommodate these other kinds of ranges with lower overhead. Allowing "end-ness" to be encoded in the type system also eliminates the need to mock-up dummy end iterators like `std::istream_iterator` and `std::regex_iterator`, the logic of which is tricky to get right. What's more, it improves code generation for these kinds of ranges. With the use of dummy end iterators, information which is known at compile-time -- namely, that an iterator represents the end -- must be encoded into runtime information in the iterator itself. This robs the compiler of the information it needs to eliminate branches from the core loops of many algorithms. See [Appendix 1](#appendix-1-sentinels-and-code-generation) for an example of how sentinels can positively affect code generation. When considering this choice for the range concept, it's helpful to think about how it would affect the algorithms. Consider `std::for_each`, which currently has this signature: template<class InputIterator, class Function> Function for_each(InputIterator first, InputIterator last, Function f) { for(; first != last; ++first) f(*first); return f; } With sentinels, `for_each` might look like this: template<InputIterator I, Regular S, Function<ValueType<I>> F> requires EqualityComparable<I, S> F for_each(I first, S last, F f) { for(; first != last; ++first) f(*first); return f; } None of the code in the algorithm had to change. No calling code would have to change either; this is a strictly backwards-compatible change. You might think that this opens a new category of programming errors where developers inadvertently pass mismatched iterator/sentinel pairs. However, this algorithm signature is constrained with concept checks that ensures that `I` and `S` satisfied the cross-type EqualityComparable concept (see [N3351][8][@n3351]). See [Appendix 2](#appendix-2-sentinels-iterators-and-the-cross-type-equalitycomparable-concept) for further discussion about iterator/sentinel cross-type EqualityComparability constraint. To see the benefit of this design, imagine a sentinel type `null_sentinel`: // For determining whether an iterator refers to a null value: struct null_sentinel { template<Iterator I> friend bool operator==(I i, null_sentinel) { return 0 == *i; } // ... and friends }; template<Iterator I> struct common_type<I, null_sentinel> ... see Appendix 2 ... Now we can use `std::for_each` on null-terminated strings without needing to know the length of the string: std::for_each(argv[1], null_sentinel(), f); Of course, all the algorithms would have overloads that also accept range arguments, so this can be further simplified to: std::for_each(null_terminated(argv[1]), f); where `null_terminated(InputIterator)` returns a range `r` such that the `std::end(r)` is a `null_sentinel`. #### Sentinels and Early Algorithm Termination One excuse sometimes given for not using the standard algorithm is that they don't give the users a way to break out of them early. The use of sentinels makes that possible. Consider a sentinel constructed from both an end iterator and a predicate. Such a sentinel would compare equal to an iterator *either* when the iterator equals the end iterator *or* when the predicate evaluates to true. Using such a sentinel has the effect of terminating an algorithm early. For instance: // Process work items in a queue, allowing for a user interrupt std::queue<Work> q; std::function<void(Work const &)> user_interrupt = /*...*/; std::for_each( q | view::until(user_interrupt), f ); In the above, `view::until` is a range modifier that adds `user_interrupt` as an extra termination condition. ### Algorithm Return Types are Changed to Accommodate Sentinels Notice that in the due course of evaluating `std::for_each` with `null_sentinel` above, the position of the null terminator is found. This is potentially useful information that can easily be returned to the user. It is, in fact, a far more interesting and useful result that the `Function` that `for_each` currently returns. So a better signature for `for_each` should look like this: // Returns an InputIterator i such that (i == last) is true: template<InputIterator I, Regular S, Function<ValueType<I>> F> requires EqualityComparable<I, S> I for_each(I first, S last, F f); In similar fashion, most algorithm get new return types when they are generalized to support sentinels. This is a source-breaking change in many cases. In some cases, like `for_each`, the change is unlikely to be very disruptive. In other cases it may be more so. Merely accepting the breakage is clearly not acceptable. We can imagine three ways to mitigate the problem: 1. Only change the return type when the types of the iterator and the sentinel differ. This leads to a slightly more complicated interface that may confuse users. It also greatly complicates generic code, which would need metaprogramming logic just to use the result of calling some algorithms. For this reason, this possibility is not explored here. 2. Make the new return type of the algorithms implicitly convertible to the old return type. Consider `copy`, which currently returns the ending position of the output iterator. When changed to accommodate sentinels, the return type would be changed to something like `pair<I, O>`; that is, a pair of the input and output iterators. Instead of returning a `pair`, we could return a kind of pair that is implicitly convertible to its second argument. This avoids breakage in some, but not all, scenarios. This subterfuge is unlikely to go completely unnoticed. 3. Deliver the new standard library in a separate namespace that users must opt into. In that case, no code is broken until the user explicitly ports their code. The user would have to accommodate the changed return types then. An automated upgrade tool similar to [clang modernize][16][@clangmodernize] can greatly help here. We, the authors, prefer (3). Our expectation is that the addition of concepts will occasion a rewrite of the STL to properly concept-ify it. The experience with C++0x Concepts taught us that baking concepts into the STL in a purely backward-compatible way is hard and leads to an unsatisfactory design with a proliferation of meaningless, purely syntactic concepts. The spirit of [N3351][8][@n3351] is to conceptify the STL in a meaningful way, even at the expense of minor breakage. Although the issue has not yet been discussed, one likely solution would be to deliver a new STL in a separate namespace. Once that happens, it opens the door for other minor breaking changes, provided the benefits are deemed worthy. ### Orthogonality of Traversal and Access Is Not Surfaced in the Iterator Concepts The current iterator concept hierarchy ties together the traversal and access properties of iterators. For instance, no forward iterator may return an rvalue proxy when it is dereferenced; the ForwardIterator concept requires that unary `operator*` return an lvalue. There is no room in the hierarchy for, say, a random-access iterator that returns proxies. This problem is not new to ranges; however, it has serious consequences for lazy ranges that apply transformations to elements on the fly. If the transformation function does not return an lvalue, the range's iterator can model no concept stronger than InputIterator, even if the resulting iterator could in theory allow random access. The result in practice is that most range adaptors today have the unfortunate effect of degrading the underlying range's category to Input, thereby limiting the number of algorithms it can be passed to -- often for no good reason. Prior work has been done by [Abrahams et. al.][9][@new-iter-concepts] to separate the traversal and access properties of iterators in a way that is backwards compatible. When formalizing the iterator concepts for a range library, should new iterator concepts be used, or should we hew to the old, simpler concept hierarchy with its known limitations? A close reading of the iterator concepts proposed by [N3351][8][@n3351] shows that the problematic requirement on ForwardIterator's reference type has been dropped. That is, if the concepts proposed by Stroustrup, Sutton, et. al., are adopted, there will be nothing wrong with, say, a random-access iterator with a proxy for a reference type. The problems described above go away without any need for further complication of the iterator refinement hierarchy. It's unclear at this time if that was the authors' intent, and if so what impact it has on the standard algorithms. This area requires more research. It is noted here that this proposal adopts the [N3351][8][@n3351] iterator concepts as-is. ### Additional Overloads of the Algorithms As should be obvious, this range proposal recommends adding additional overloads of the existing algorithms to allow them to work directly on Iterables. This is done in accordance with the following suggested guidelines: - Any algorithm that currently operates on a range denoted by two iterators gets an overload where the two iterator arguments are replaced with a single Iterable argument. (NOTE: This does *not* include the counted algorithms like `copy_n` that take an iterator and a count instead of two iterators.) - All overloads of an algorithm, whether they take Iterables or separate iterator/sentinel arguments, are *semantically identical*. All overloads have the same return type. All evaluate eagerly. The intention is that the Iterable-based overloads delegate to the iterator-based ones and have the same semantics and algorithmic complexity. - As described above, algorithms that necessarily process their entire input sequence return the iterator position at the end in addition to whatever else they return. The purpose is to return potentially useful information that is computed as a side-effect of the normal execution of the algorithm. Exceptions to this design guideline are made when one of the following is true: * The algorithm might in some cases not consume the entire input sequence. (The point of this exception is to avoid forcing the algorithm to compute something that is not necessary for successful completion. For example, `find`.) * When the sole purpose of the algorithm is specifically to compute a single value; hence, changing the return type will necessarily break code using the C++11 version. Examples include `is_sorted` and `accumulate`. - "Three-legged" iterator-based algorithms (i.e. algorithms that operate on two ranges, the second of which is specified by only a single iterator and is assumed to be long enough) now have 4 versions: 1. The old three-legged iterator version, 2. A four-legged version that uses the sentinel of the second sequence as an additional termination condition, 3. A version that takes an Iterable and an Iterator (which dispatches to the three-legged iterator-based version), and 4. A version that takes two Iterables (which dispatches to the four-legged iterator-based version). Note: Purely as an implementation consideration, overloads (3) and (4) above must be coded to avoid ambiguity when a native array is passed as the second parameter (where either an Iterable or an Iterator may appear). Arrays are Iterables, but if (3) is naively coded to take an Iterator by value, a native array would also match, since native arrays decay into pointers. - If an algorithm returns an iterator into an Iterable argument, the Iterable must be an lvalue. This is to avoid returning an iterator that is immediately made invalid. Conversely, if no iterator into an Iterable argument is returned, then the Iterable should be taken by forwarding reference (aka ["universal reference"][13][@universal-references]). - Algorithms that do not mutate their input sequence must also work when braced initializer lists [dcl.init] are used in place of Iterables. This can require additional `initializer_list` overloads since a type cannot be deduced from a *braced-init-list* used as an argument. ### Range-based for Loop is Changed to Accommodate Sentinels The current range-based `for` loop assumes that a range's end has the same type as its begin. This restriction can be relaxed to allow range-based `for` to operate on Iterables. The range-based for loop is currently specified as: { auto && __range = range-init; for ( auto __begin = begin-expr, __end = end-expr; __begin != __end; ++__begin ) { for-range-declaration = *__begin; statement } } To accommodate Iterables, the change is as simple as: { auto && __range = range-init; auto __begin = begin-expr; auto __end = end-expr; for ( ; __begin != __end; ++__begin ) { for-range-declaration = *__begin; statement } } This is the only core language change required to fully support Iterables. ### Allow Mutable-Only Iterables If a cv-unqualified type `T` models Iterable, then the type `T const` need not. This permits ranges that maintain mutable internal state such as an `istream_range`. Consider the performance short-comings of `istream_iterator<string>`. The iterator reads a string from an `istream` and must store it internally so it can be returned from `operator*`. This means that copying an `istream_iterator<string>` probably incurs a dynamic allocation. Copying iterators is not supposed to be expensive. An alternative range-based design would be to define an `istream_range` class template: template<class T> class istream_range { T value_; istream * postr_; public: class iterator { istream_range * prng_; public: /*...*/ }; iterator begin() {/*...*/} iterator end() {/*...*/} }; In this design, the cached value lives in the range object, not in the iterator. The iterator merely stores a pointer back to the range. As the iterator is advanced, values are read from the stream and stored in the cache. Since the range object is mutated as it is iterated, it would be a lie to provide const overloads of `begin()` and `end()`. The need for a range that is mutated in the course of iteration also came up in the design of a `view::flatten` adaptor that takes a range of ranges, and turns it into a single range. This adapted range also must mutate an internal cache. The adaptor is used to make Ranges monads, and is used in the implementation of [Range Comprehensions][12][@range-comprehensions], which are akin to Python's and Haskell's List Comprehensions. (That discussion is beyond the scope of this document.) ### Range Adaptors are Lazy Algorithms Consider the example given at the start of paper: int total = accumulate(view::iota(1) | view::transform([](int x){return x*x;}) | view::take(10), 0); The semantics of the adaptors (the things in the `view::` namespace) are such that computations are only done on demand, when the resulting adapted range is iterated. In this case, the range pipeline expression does no work aside from setting up a computation. Only as `accumulate` executes is the sequence of integers generated and transformed. All adaptors have these lazy semantics. This gives users the ability to reason about the algorithmic complexity of their programs. If an underlying range is transformed and filtered and then passed to an algorithm, users can be certain that the sequence will be traversed exactly once. ### All Algorithms Accept Sentinels Even If They Need An End Iterator Some algorithms like `reverse` really need an end iterator to do their job. One option would be to require users to pass an actual end iterator instead of a non-iterator sentinel. The other option is to accept a sentinel and do an O(N) probe for the end first. We opted for the latter option. No such algorithms have complexity better than O(N), so such a probe doesn't affect the overall algorithmic complexity of the algorithm. And it saves the user the hassle of having to find the end herself before calling the algorithm. In short, it should be possible to `reverse` a null-terminated string *without* needing to call `strlen` first. ### There Is No Function Signature To Express Does-Not-Mutate-The-Range-Elements Raw pointers have an advantage over iterators with regard to the const-correctness of function interfaces; namely, that you can use `const` to guarantee that the function will not mutate the pointed-to data. Consider: // This will not mutate the data template<typename T> void some_function(const T * data, std::size_t count); When we move to iterators, we lose that expressiveness: // Will this mutate the data? template<typename Iter> void some_function(Iter first, Iter last); Since the suggested range design is built on top of iterators, it inherits this limitation. Consider what happens when we change to a range-based API with a simple `range` type like that proposed by [N3350][21][@n3350]: // Accepts a const Range object, but mutates its elements template<Iterable Rng> void some_function(Rng const & rng) { ++*rng.begin(); // Deeply questionable behavior } template<typename I> struct range : pair<I, I> { using pair<I, I>::pair; I begin() const { return this->first; } I end() const { return this->second; } }; int main() { int arr[] = {1,2,3,4}; range<int*> rng{ arr, arr + 3 }; some_function(rng); // arr is now {2,2,3,4} } Keep in mind that the Iterable concept describes types like `vector` where a top-level const *does* affect the mutability of the iterable's elements, as well as simple pair-of-iterator style ranges like `range` above, where the top-level constness does *not* affect the elements' mutability. Concepts Lite doesn't help, either. Although it's not hard to write a concept that only matches immutable iterables and use it to constrain an algorithm, it doesn't solve the problem. See below: template<Iterable Rng> concept ConstIterable = is_const<remove_reference_t< decltype(*begin(declval<Rng &>())) >>::value; // This is over-constrained: template<ConstIterable Rng> void non_mutating_algorithm(Rng const & rng); int rgi[] = {1,2,3,4}; range<int *> rng{rgi, rgi+4}; // a pair of mutable iterators non_mutating_algorithm(rng); // <== ERROR rng is not a ConstIterable The trouble is that the type `Rng` is deduced as `range<int *>` which doesn't satisfy the requirements of the ConstIterable concept. The const in the function signature doesn't help because it doesn't change the const-ness of the iterator's reference type. Even if `rng` is const, `rng.begin()` returns an `int*`. There is no way to write the function signature such that template type deduction works *and* const-ness is applied deeply to the range's elements. That's because such a transformation would necessarily involve a change to the range's type, and type deduction makes no allowance for arbitrary type transformations during the deduction process. #### But it works for `array_view`. Why? [N3851](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3851.pdf) proposes an `array_view` class for the second Library Fundamentals TS. That type allows users to independently specify the mutability of the elements and of the view with the `const` keyword. From N3851: > A view can be created over an arbitrary *value_type*, as long as there exists a conversion from the pointer to the underlying collection object type to the pointer to the *value_type*. This allows to distinguish two levels of constness, analogously to the pointer semantics -- the constness of the view and the constness of the data over which the view is defined -- see Table 2. Interfaces of both the *array_view* and the *strided_array_view* allow for implicit conversions from non-const-qualified views to const-qualified views. With this scheme, you presumably would be able to pass any Container (defined in N3851 to be arrays and class types with `size` and `data` member functions) to an algorithm as follows: void some_algorithm( array_view<const int, 1> const & arr ); vector<int> vi {1,2,3,4}; array_view<int, 1> arr { vi } some_algorithm( arr ); // OK! In this case, the signature of the algorithm, together with the constructors of `array_view` and the implicit conversion of `int*` to `const int*`, conspire to make `some_function` guarantee deep-constness. If it can work for `array_view`, why can it not work in general for all Iterables? In other words, is there no range design in which users can put `const` somewhere in their function signatures to make their algorithms deeply const? The answer, sadly, is no. Even a trivial change to the above signature shows how fragile the `array_view` design is, and why it cannot be generalized to all range types: template<typename T> void some_algorithm( array_view<const T, 1> const & arr ); vector<int> rgi{1,2,3,4}; array_view<int, 1> arr { vi } some_algorithm( arr ); // ERROR! The compiler cannot figure out what type to pick for `T` during type deduction, and there's no way for the author of `array_view` to give the compiler that guidance. When generalized to arbitrary Iterables and Ranges, the problem is further compounded. There is no place to put a second, "deep" `const` in a signature like below: template<Iterable Rng> void some_algorithm( Rng const & rng ); And even if there were, the problem would be the same as for `array_view`: template type deduction would fail. #### Constraints and contracts There is no clever way around the problem in today's language, or even with Concepts Lite. This is an artifact of the style of generic programming used in C++: stating constraints on template arguments is significantly different than adding `const`-ness to a concrete type or template specialization. A template's constraints define part of that template's contract, and this contract applies not only to the user of that template, but also its implementer. In the earlier example, `some_function` requires its template arguments to satisfy the requirements of the Iterable concept. Under that contract, the implementation should use only the expressions allowed by the concept on objects whose types are constrained by the concept. In other words, those requirements define a set of expressions and types that are *admissible* within the template. Recall the `some_function` define above: // Accepts a const Range object, but mutates its elements template<Iterable Rng> void some_function(Rng const & rng) { ++*rng.begin(); // Deeply questionable behavior } The expression `++*rng.begin()` invokes not one, but two operations not admitted by the requirements of the Iterable concept: - `rng.begin()` (which should be `using std::begin; begin(rng)`), and - `++x` where `x` is the object returned by `*begin(rng)`. While this program is syntactically well-formed, and instantiation may even succeed, its behavior would be undefined under the terms of its contract. In other words, the implementation does not conform to its constraints. This is not fundamentally different than using a `const_cast` to modify the value of a `const`-qualified function argument: it might work, but the modification invokes undefined behavior. *Every* proposed range design will have the same problem. The lack of a library solution to this problem should not hold up a proposal. A work-around is for users to test each algorithm with an archetypal non-mutable iterator, as has been done with the [Boost Concept Check Library][1][@boostconceptcheck]. The standard library could make this task simpler by providing debug archetypal iterators for testing purposes. ### Singular Ranges Are Not Empty Ranges are default-constructible. The question is, what can be done with a such a range? Given a Range type `R` and an object `r` defined as follows: R r; // "singular" range assert( begin(r) == end(r) ); // Is this OK? Default-constructed standard containers are empty. Can we expect the same is true for ranges? No, we cannot. The intention is that a simple pair of iterators may qualify as a valid range. The section [iterator.requirements.general]/5 explains what can be done with singular iterators, and comparing them for equality is not listed as one of the valid operations. Therefore, singular ranges are not "empty". In terms of EoP, they are partially formed objects that must be assigned to before they can be used [8]. A particular model of the Range concept may choose to provide this guarantee, but it is not required by the Range concept itself and, as such, should not be relied upon. Concept Definitions ===== The following concepts are proposed to constrain the standard library. The iterator concepts mentioned here are identical to those specified in [N3351][8][@n3351] except where specified. ## Iterator Concepts The range concepts presented below build on the following iterator concepts. These are largely as found in [N3351][8][@n3351], with the addition of WeakIterator, Iterator, WeakOutputIterator and OutputIterator. The entire hierarchy is presented here for completeness. An important, new concept is: concept WeakIterator<typename I> = WeaklyIncrementable<I> && Copyable<I> && requires(I i) { { *i } -> auto&&; }; A WeakIterator is a WeaklyIncrementable type that is both copyable and dereferencable, in addition to being pre-incrementable. The only requirement on the result of dereferencing the iterator is that its type can be deduced from `auto&&`. Effectively, the result of dereferencing shall not be `void`. The WeakIterator concept allows iterator adaptors to provide a dereferencing operator for both InputIterators and OutputIterators. This concept is refined by the addition of either Readable or Writable, which allow reading from and writing to a dereferenced iterator, respectively. The Iterator and WeakIterator also obviate the need for separate InputRange and OutputRange concepts (as we see later). concept Iterator<typename I> = WeakIterator<I> && EqualityComparable<I>; concept WeakOutputIterator<typename I, typename T> = WeakIterator<I> && Writable<I, T>; concept OutputIterator<typename I, typename T> = WeakOutputIterator<I> && EqualityComparable<I>; N3351 does not define WeakOutputIterator or OutputIterator, preferring instead to define all the algorithms in terms of WeaklyIncrementable and (separately) Writable. We see no disadvantage to rolling these two into the familiar (Weak)OutputIterator concept as a convenience; it saves typing. The WeakInputIterator concept defines requirements for a type whose referred to values can be read (from the requirement for Readable) and which be both pre- and post-incremented. However, WeakInputIterators are not required to be compared for equality. There are a number of algorithms whose input ranges are defined by the equality of comparison of another input range (e.g., `std::mismatch` and `std::equal`). concept WeakInputIterator<WeakIterator I> = Readable<I> && requires(I i) { typename IteratorCategory<I>; { i++ } -> Readable; requires Derived<IteratorCategory<I>, weak_input_iterator_tag>; }; An InputItreator is a WeakInputIterator that can be compared for equality comparison. This concept defines the basic requirements for a very large number of the algorithm in the standard library. concept InputIterator<typename I> = WeakInputIterator<I> && EqualityComparable<I> && Derived<IteratorCategory<I>, input_iterator_tag>; The ForwardIterator concept refines the InputIterator concept, but the refinement is *semantic*. It guarantees the "multipass" property: it allows multiple iterations of a range of elements. This is something that cannot be done with, say, an `istream_iterator`. The current element is consumed when the iterator is incremented. concept ForwardIterator<typename I> = InputIterator<I> && Incrementable<I> && Derived<IteratorCategory<I>, forward_iterator_tag>; The BidirectionalIterator concept refines the ForwardIterator concept, and allows both incrementing and decrementing. concept BidirectionalIterator<typename I> = ForwardIterator<I> && Derived<IteratorCategory<I>, bidirectional_iterator_tag> && requires decrement (I i, I j) { { ––i } -> I&; { i–– } -> I; }; The RandomAccess concept refines the BidirectionalIterator concept and provides support for constant-time advancement using `+=`, `+`, and `-=`, and the computation of distance in constant time using `-`. Random access iterators also support array notation via subscripting. concept RandomAccessIterator<typename I> = BidirectionalIterator<I> && TotallyOrdered<I> && Derived<IteratorCategory<I>, random_access_iterator_tag> && SignedIntegral<DistanceType<I>> && SizedIteratorRange<I, I> && // see below requires advance (I i, I j, DifferenceType<I> n) { { i += n } -> I&; { i + n } -> I; { n + i } -> I; { i –= n } -> I&; { i – n } -> I; { i[n] } -> ValueType<I>; }; ## Iterator Range Concepts The IteratorRange concept defines a pair of types (an Iterator and a Sentinel), that can be compared for equality. This concept is the key that allows iterator ranges to be defined by pairs of types that are not the same. concept IteratorRange<typename I, typename S> = Iterator<I> && Regular<S> && EqualityComparable<I, S>; The SizedIteratorRange allows the use of the `-` operator to compute the distance between to an Iterator and a Sentinel. concept SizedIteratorRange<typename I, typename S> = IteratorRange<I, S> && requires difference (I i, S j) { typename Distance_type<I>; { i - i } -> Distance_type<I>; { j - j } -> Distance_type<I>; { i - j } -> Distance_type<I>; { j - i } -> Distance_type<I>; requires SignedIntegral<DifferenceType>; }; ## Iterable Concepts This proposal introduces a new concept for describing the requirements on algorithms that require access to the `begin` and `end` of a Range or Container. concept Iterable<typename T> = requires(T t) { typename IteratorType<T>; typename SentinelType<T>; { begin(t) } -> IteratorType<T>; { end(t) } -> SentinelType<T>; requires IteratorRange<IteratorType, SentinelType>; } The Iterable concept requires two associated operations: `begin`, and `end`. Note that the return types of these operations are not required to be the same. The names of those return types are `IteratorType<T>` and `SentinelType<T>`, respectively. Furthermore, that pair of types must satisfy the requirements of the IteratorRange concept defined in the previous section. Iterable types have no other requirements. Most algorithms requiring this concept simply forward to an Iterator-based algorithm by calling `begin` and `end`. The Range concept refines the Iterable concept and defines a view on a range of elements that it does not own. concept Range<typename T> = Iterable<T> && Semiregular<T> && is_range<T>::value; A possible implementation of the `is_range` predicate is shown below. // For exposition only: struct range_base {}; concept ContainerLike<Iterable T> = !Same<decltype(*begin(declval<T &>())), decltype(*begin(declval<T const &>()))>; // For exposition only: template<typename T> struct is_range_impl_ : std::integral_constant< bool, Iterable<T> && (!ContainerLike<T> || Derived<T, range_base>) > {}; // Specialize this if the default is wrong. template<typename T, typename Enable = void> struct is_range : conditional< is_same<T, remove_const_t<remove_reference_t<T>>>::value, is_range_impl_<T>, is_range<remove_const_t<remove_reference_t<T>>> >::type {}; Note that the "multipass" property--the property that guarantees that you can iterate the same range twice, accessing the same objects in each pass--is guaranteed by the `forward_iterator_tag` class. That is, any iterator having whose iterator category is derived from that tag class is required to be a multipass iterator. ## Sized Iterable Concepts The `SizedIterable` concept exists for the same reasons as `SizedIteratorRange`. There are some iterables that, though they are not random-access, know their size in O(1). A prime example is `std::list`. Another example is a counted view (i.e., a range specified by an iterator and a count). Some algorithms can select a better implementation when the size of the range is known, even if the iterators don't allow random access. (One example is a `search` algorithm that knows to stop searching when there is no longer room in the input sequence for the pattern to match.) // For exposition only: concept SizedIterableLike<Iterable R> = requires(R r) { typename SizeType<R>; { size(r) } -> SizeType<R>; // ADL customization point requires Integral<SizeType>; } concept SizedIterable<SizedIterableLike R> = is_sized_iterable<R>::value; Like [N4017][20][@n4017], we propose `size(r)` as a customization point for accessing the size of an Iterable. A SizedIterable requires that `size(r)` returns the same value as `distance(begin(r), end(r))` (module a possible change in the signed-ness of the Integral type). As in N4017, we suggest `size` overloads in `std::` for arrays and for class types with a `size()` member. In recognition of the fact that nominal conformance to a concept is insufficiently fine-grained, the SizedIterable concept is defined in terms of a `is_sized_iterable` trait. This is to give users explicit control in the case of accidental conformance with the syntactic requirements of the concept. A possible default implementation of the `is_sized_iterable` trait is shown below. // For exposition only: template<typename R> struct is_sized_iterable_impl_ : std::integral_constant< bool, SizedIterableLike<R> > {}; // Specialize this if the default is wrong. template<typename R> struct is_sized_iterable : conditional< is_same<R, remove_const_t<remove_reference_t<R>>>::value, is_sized_iterable_impl_<R>, is_sized_iterable<remove_const_t<remove_reference_t<R>>> >::type {}; Technical Specifications ===== This section is intentionally left blank. Future Directions ===== More work is necessary to get ranges into the standard. Subsequent proposals will recommend specific components for standardization as described in [Impact on the Standard](#impact-on-the-standard). In addition, below are some additional areas that are currently open for research. - Range extensions to things like regex. Make it work with null-terminated strings, e.g.. - Discuss the pros and cons of tying this work with work on a concept-ified standard library (aka Concepts Lite TS2). - Discuss the pros and cons of making this (and the concept-ified standard library) *strictly* backwards compatible, versus delivering the new, conceptified and range-ified standard library in a separate, versioned namespace (and what such a solution should look like). - Discuss how an extension to the Concepts Lite proposal, implicit conversion to concept, bears on the Iterable/Range concepts and the way the algorithms are constrained. Also discuss how it can give a syntax to express "this function does not mutate the range elements." - Assess the impact of allowing ForwardIterators to return proxies. - Consider integrating ContiguousIterator from [N4132][18][@n4132] Acknowledgements ===== I would like to give special thanks to Sean Parent for his advice and feedback on early designs of the range library on which this proposal is based, in addition to his work on the [Adobe Source Libraries][3][@asl] from which this proposal has borrowed liberally. Also deserving of special thanks is Andrew Sutton. His work on Concepts Lite and on the formulations of the algorithms as specified in [N3351][8][@n3351] has proven invaluable, and he has generously donated his time and expertise to expound on the ideas there and improve the quality of this proposal. Chandler Carruth has also helped more than he probably knows. I am indebted to him for his support and perspective. I would be remiss if I didn't acknowledge the foundational work of all the people whose ideas and sweat have gone into various range libraries and proposals in the past. They are too many to list, but I certainly benefited from the work of Dave Abrahams, Dietmar Kühl, Neil Groves, Thorsten Ottosen, Arno Schoedl, Daniel Walker, and Jeremy Seik. Neil Groves also submitted a particularly extensive review of this document. Of course none of this work would be possible without Alex Stepanov's giant leap forward with the STL, or without Bjarne Stroustrup who gave Alex the instrument he needed to most clearly realize his vision. References ===== --- references: - id: boostconceptcheck title: Boost Concept Check Library URL: 'http://boost.org/libs/concept_check' type: webpage accessed: year: 2014 month: 10 day: 8 - id: boostrange title: Boost.Range Library URL: 'http://boost.org/libs/range' type: webpage accessed: year: 2014 month: 10 day: 8 - id: asl title: Adobe Source Libraries URL: 'http://stlab.adobe.com' type: webpage accessed: year: 2014 month: 10 day: 8 - id: drange title: D Phobos std.range URL: 'http://dlang.org/phobos/std_range.html' type: webpage accessed: year: 2014 month: 10 day: 8 - id: bekennrange title: Position-Based Ranges URL: 'https://github.com/Bekenn/range' type: webpage accessed: year: 2014 month: 10 day: 8 - id: stepanov09 title: Elements of Programming type: book author: - family: Stepanov given: Alexander - family: McJones given: Paul edition: 1 isbn: 032163537X, 9780321635372 issued: year: 2009 publisher: Addison-Wesley Professional - id: n3351 title: 'N3351: A Concept Design for the STL' type: article author: - family: Stroustrup given: Bjarne - family: Sutton given: Andrew issued: year: 2012 month: 1 URL: 'http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3351.pdf' - id: n1873 title: 'N1873: The Cursor/Property Map Abstraction' type: article author: - family: Dietmar given: Kühl - family: Abrahams given: David issued: year: 2005 month: 8 day: 26 URL: 'http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1873.html' - id: n3782 title: 'N3782: Index-Based Ranges' type: article author: - family: Schödl given: Arno - family: Fracassi given: Fabio issued: year: 2013 month: 9 day: 24 URL: 'http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3782.pdf' - id: clangmodernize title: Clang Modernize URL: 'http://clang.llvm.org/extra/clang-modernize.html' type: webpage accessed: year: 2014 month: 10 day: 8 - id: new-iter-concepts title: New Iterator Concepts URL: 'http://www.boost.org/libs/iterator/doc/new-iter-concepts.html' type: webpage accessed: year: 2014 month: 10 day: 8 - id: universal-references title: Universal References in C++11 URL: 'http://isocpp.org/blog/2012/11/universal-references-in-c11-scott-meyers' type: webpage accessed: year: 2014 month: 10 day: 8 - id: range-comprehensions title: Range Comprehensions URL: 'http://ericniebler.com/2014/04/27/range-comprehensions/' type: webpage accessed: year: 2014 month: 10 day: 8 - id: n4132 title: 'N4132: Contiguous Iterators' type: article author: - family: Maurer given: Jens issued: year: 2014 month: 9 day: 10 accessed: year: 2014 month: 10 day: 8 URL: 'https://isocpp.org/files/papers/n4132.html' - id: ntcts-iterator title: NTCTS Iterator URL: 'https://github.com/Beman/ntcts_iterator' type: webpage accessed: year: 2014 month: 10 day: 8 - id: range-v3 title: Range v3 URL: 'http://www.github.com/ericniebler/range-v3' type: webpage accessed: year: 2014 month: 10 day: 8 - id: llvm-sroa title: 'Debug info: Support fragmented variables' URL: 'http://reviews.llvm.org/D2680' type: webpage accessed: year: 2014 month: 10 day: 8 - id: libcxx title: 'libc++ C++ Standard Library' URL: 'http://libcxx.llvm.org/' type: webpage accessed: year: 2014 month: 10 day: 8 - id: austern98 title: 'Segmented Iterators and Hierarchical Algorithms' URL: 'http://dl.acm.org/citation.cfm?id=647373.724070' author: - family: Austern given: Matthew type: paper-conference container-title: Selected Papers from the International Seminar on Generic Programming page: 80-90 issued: year: 2000 - id: cpp-seasoning title: 'C++ Seasoning' author: - family: Parent given: Sean type: speech URL: 'https://github.com/sean-parent/sean-parent.github.com/wiki/presentations/2013-09-11-cpp-seasoning/cpp-seasoning.pdf' container-title: 'GoingNative 2013' issued: year: 2013 month: 9 day: 11 - id: muchnick97 title: 'Advanced Compiler Design Implementation' author: - family: Muchnick given: Steven publisher: 'Morgan Kaufmann' issued: year: 1997 isbn: '1558603204, 9781558603202' - id: n4017 title: 'N4017: Non-member size() and more' type: article author: - family: Marcangelo given: Riccardo issued: year: 2014 month: 5 day: 22 accessed: year: 2014 month: 10 day: 10 URL: 'http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4017.htm' - id: n3350 title: 'N3350: A minimal std::range<Iter>' type: article author: - family: Yasskin given: Jeffrey issued: year: 2012 month: 1 day: 16 accessed: year: 2014 month: 10 day: 10 URL: 'http://www.open-std.org/Jtc1/sc22/wg21/docs/papers/2012/n3350.html' ... [1]: http://boost.org/libs/concept_check "Boost Concept Check Library" [2]: http://www.boost.org/libs/range "Boost.Range" [3]: http://stlab.adobe.com/ "Adobe Source Libraries" [4]: http://dlang.org/phobos/std_range.html "D Phobos std.range" [5]: https://github.com/Bekenn/range "Position-Based Ranges" [6]: https://github.com/sean-parent/sean-parent.github.com/wiki/presentations/2013-09-11-cpp-seasoning/cpp-seasoning.pdf "C++ Seasoning, Sean Parent" [7]: http://www.github.com/ericniebler/range-v3 "Range v3" [8]: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3351.pdf "A Concept Design for the STL" [9]: http://www.boost.org/libs/iterator/doc/new-iter-concepts.html "New Iterator Concepts" [10]: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3782.pdf "Indexed-Based Ranges" [11]: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1873.html "The Cursor/Property Map Abstraction" [12]: http://ericniebler.com/2014/04/27/range-comprehensions/ "Range Comprehensions" [13]: http://isocpp.org/blog/2012/11/universal-references-in-c11-scott-meyers "Universal References in C++11" [14]: http://lafstern.org/matt/segmented.pdf "Segmented Iterators and Hierarchical Algorithms" [15]: http://reviews.llvm.org/D2680 "Debug info: Support fragmented variables." [16]: http://clang.llvm.org/extra/clang-modernize.html "Clang Modernize" [17]: http://libcxx.llvm.org/ "libc++ C++ Standard Library" [18]: https://isocpp.org/files/papers/n4132.html "Contiguous Iterators" [19]: https://github.com/Beman/ntcts_iterator "ntcts_iterator" [20]: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4017.htm "Non-member size() and more" [21]: http://www.open-std.org/Jtc1/sc22/wg21/docs/papers/2012/n3350.html "A minimal std::range<Iter>" Appendix 1: Sentinels and Code Generation ===== In this appendix we explore the effect of sentinels on code generation. I'll show that allowing the type of the end iterator to differ from the begin can have a positive effect on the performance of algorithms. First, I'll note that nothing that can be done with sentinels cannot also be done with appropriately designed end iterators. Here, for instance, is the code for an iterator that can be used to adapt a null-terminated string to the STL. It is implemented with the help of the Boost.Iterators library: #include <cassert> #include <iostream> #include <boost/iterator/iterator_facade.hpp> struct c_string_range { private: char const *str_; public: using const_iterator = struct iterator : boost::iterator_facade< iterator , char const , std::forward_iterator_tag > { private: friend class boost::iterator_core_access; friend struct c_string_range; char const * str_; iterator(char const * str) : str_(str) {} bool equal(iterator that) const { return str_ ? (that.str_ == str_ || (!that.str_ && !*str_)) : (!that.str_ || !*that.str_); } void increment() { assert(str_ && *str_); ++str_; } char const& dereference() const { assert(str_ && *str_); return *str_; } public: iterator() : str_(nullptr) {} }; c_string_range(char const * str) : str_(str) { assert(str_); } iterator begin() const { return iterator{str_}; } iterator end() const { return iterator{}; } explicit operator bool() const { return !!*str_; } }; int c_strlen(char const *sz) { int i = 0; for(; *sz; ++sz) ++i; return i; } int range_strlen( c_string_range::iterator begin, c_string_range::iterator end) { int i = 0; for(; begin != end; ++begin) ++i; return i; } The code traverses the sequence of characters without first computing its end. It does it by creating a dummy end iterator such that any time a real iterator is compared to it, it checks to see if the real iterator points to the null terminator. All the comparison logic is in the `c_string_range::iterator::equal` member function. The functions `c_strlen` and `range_strlen` implement equivalent procedures for computing the length of a string, the first using raw pointers and a check for the null terminator, the second using `c_string_range`'s STL iterators. The resulting optimized assembly code (clang 3.4 -O3 -DNDEBUG) generated for the two functions highlights the lost optimization opportunities. <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="607"> <tr><td><pre><code>c_strlen</code></pre></td><td><pre><code>range_strlen</code></pre></td></tr> <tr><td valign="top"><pre><code> pushl %ebp movl %esp, %ebp movl 8(%ebp), %ecx xorl %eax, %eax cmpb $0, (%ecx) je LBB1_3 xorl %eax, %eax .align 16, 0x90 LBB1_2: cmpb $0, 1(%ecx,%eax) leal 1(%eax), %eax jne LBB1_2 LBB1_3: popl %ebp ret</code></pre></td><td><pre><code> pushl %ebp movl %esp, %ebp pushl %esi leal 8(%ebp), %ecx movl 12(%ebp), %esi xorl %eax, %eax testl %esi, %esi movl 8(%ebp), %edx jne LBB2_4 jmp LBB2_1 .align 16, 0x90 LBB2_8: incl %eax incl %edx movl %edx, (%ecx) LBB2_4: testl %edx, %edx jne LBB2_5 cmpb $0, (%esi) jne LBB2_8 jmp LBB2_6 .align 16, 0x90 LBB2_5: cmpl %edx, %esi jne LBB2_8 jmp LBB2_6 .align 16, 0x90 LBB2_3: leal 1(%edx,%eax), %esi incl %eax movl %esi, (%ecx) LBB2_1: movl %edx, %esi addl %eax, %esi je LBB2_6 cmpb $0, (%esi) jne LBB2_3 LBB2_6: popl %esi popl %ebp ret</code></pre></td></tr> </table> Code like `c_string_range` exists in the wild; for instance, see [Beman Dawes' `ntcts_iterator`][19][@ntcts-iterator]. But more typically, when users want to use an STL algorithm on a C-style string, they call `strlen` to find the end first (this is what the standard regex algorithms do when passed C-style strings). That traverses the string an extra time needlessly. Also, such a trick is not possible for input sequences like those traversed by `std::istream_iterator` that consume their input. Rather than mocking up a dummy end iterator with a computationally expensive equality comparison operation, we can use a sentinel type that encodes end-ness in its type. Below is an example from the [Range-v3 library][7][@range-v3], which uses a `range_facade` class template to generate iterators and sentinels from a simple range-like interface: using namespace ranges; struct c_string_iterable : range_facade<c_string_iterable> { private: friend range_access; char const *sz_; char const & current() const { return *sz_; } void next() { ++sz_; } bool done() const { return *sz_ == 0; } bool equal(c_string_iterable const &that) const { return sz_ == that.sz_; } public: c_string_iterable() = default; c_string_iterable(char const *sz) : sz_(sz) {} }; // Iterable-based int iterable_strlen( range_iterator_t<c_string_iterable> begin, range_sentinel_t<c_string_iterable> end) { int i = 0; for(; begin != end; ++begin) ++i; return i; } The assembly generated for `iterable_strlen` is nearly identical to that for the hand-coded `c_strlen`: <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="607"> <tr><td><pre><code>c_strlen</code></pre></td><td><pre><code>iterable_strlen</code></pre></td></tr> <tr><td valign="top"><pre><code> pushl %ebp movl %esp, %ebp movl 8(%ebp), %ecx xorl %eax, %eax cmpb $0, (%ecx) je LBB1_3 xorl %eax, %eax .align 16, 0x90 LBB1_2: cmpb $0, 1(%ecx,%eax) leal 1(%eax), %eax jne LBB1_2 LBB1_3: popl %ebp ret</code></pre></td><td><pre><code> pushl %ebp movl %esp, %ebp movl 8(%ebp), %ecx xorl %eax, %eax cmpb $0, (%ecx) je LBB1_4 leal 8(%ebp), %edx .align 16, 0x90 LBB1_2: cmpb $0, 1(%ecx,%eax) leal 1(%eax), %eax jne LBB1_2 addl %eax, %ecx movl %ecx, (%edx) LBB1_4: popl %ebp ret</code></pre></td></tr> </table> The generated code for `iterable_strlen` is better than for `range_strlen` because the sentinel has a different type than the iterator, so that the expression `begin != end` can be optimized into `*begin == 0`. In `range_strlen`, `begin == end` is comparing two objects of the same type, and since either `begin` or `end` could be a sentinel -- or both, or neither -- the compiler can't elide the extra checks without extra information from the surrounding calling context, which isn't always available; hence, the worse code gen. In addition to the performance impact, the complexity of implementing a correct `operator==` for an iterator with a dummy sentinel can present problems. Chandler Carruth reports that such comparison operators have been a rich source of bugs for Google. Appendix 2: Sentinels, Iterators, and the Cross-Type EqualityComparable Concept ===== This appendix describes the theoretical justification for sentinels from the perspective of the STL concepts as set out in [N3351][8][@n3351]. In that paper, the foundational concept EqualityComparable is described in depth, not only its syntactic constraints but also its semantic axioms. It is not enough that the syntax `a == b` compiles. It has to be a meaningful comparison. Here I explain why I believe it is meaningful to compare an iterator with a sentinel of a different type for equality. In the expression `x == y`, where `x` and `y` have different types, the EqualityComparable concept requires that the types of both `x` and `y` must themselves be EqualityComparable, and there must be a common type to which they can both be converted, and that type must also be EqualityComparable. Think of comparing a `char` with a `short`. It works because both `char` and `short` are EqualityComparable, and because they can both be converted to an `int` which is also EqualityComparable. Iterators are comparable, and sentinels are trivially comparable (they always compare equal). The tricky part is the common type requirement. Logically, every iterator/sentinel pair has a common type that can be constructed as follows: assume the existence of a new iterator type `I` that is a tagged union that contains *either* an iterator *or* a sentinel. When an iterator is compared to a sentinel, it behaves semantically as if both the iterator and the sentinel were first converted to two objects of type `I` — call them `lhs` and `rhs` — and then compared according to the following truth table: LHS IS SENTINEL ? | RHS IS SENTINEL ? | LHS == RHS ? ----------------- | ----------------- | ------------ `true` | `true` | `true`<sup>[\[*\]](#sentinel-equality "Sentinel Equality")</sup> `true` | `false` | `done(rhs.iter)` `false` | `true` | `done(lhs.iter)` `false` | `false` | `lhs.iter == rhs.iter` In [Appendix 1](#appendix-1-sentinels-and-code-generation), there is an implementation of `c_string_range` whose iterator's `operator==` is a procedure for evaluating this truth table. That’s no coincidence; that was a special case of this more general construction. In summary, for every iterator/sentinel pair, we can construct a common iterator type that implements an equivalent procedure for computing equality. The existence of this common type is what allows iterator/sentinel pairs to satisfy the EqualityComparable requirement. As a final note, the Range v3 library has a general implementation of this common iterator type as a parametrized type, and appropriate specializations of `std::common_type` that allow the constrained algorithms to type-check correctly. It works well in practice, both for the purpose of type-checking the algorithms and for adapting ranges with iterator/sentinel pairs to old code that expects the begin and end of a range to have the same type. ## Sentinel Equality The first line of table above shows that sentinels always compare equal -- regardless of their state. This can seem unintuitive in some situations. For instance: auto s = "Hello World!?"; // Hypothetical range-like facilities for exposition only: auto r1 = make_range( &s[0], equal_to('!') ); auto r2 = make_range( &s[0], equal_to('?') ); // 'end()' returns each 'equal_to' sentinel object: assert(r1.end() == r2.end() && "really?"); In the above example, it's clear that `r1.end()` and `r2.end()` are referring to different elements, and that's reflected in their having different state. So shouldn't sentinel equality be a stateful comparison? It's incorrect to think of sentinels as objects whose position is determined by their value. Thinking that way leads to logical inconsistencies. It's not hard to define sentinels that -- if you consider their state during comparison -- compare equal when they represent a different position, and not equal when they represent the same position. Consider: auto s = "hello! world!"; auto r1 = make_range( &s[0], equal_to('!') ); auto r2 = make_range( &s[7], equal_to('!') ); assert(r1.end() == r2.end() && "really?"); In the above code, although the sentinels have the same type and the same state, they refer to different elements. Also imagine a counted iterator that stores an underlying iterator and a count that starts at zero. It's paired with a sentinel that contains an ending count: auto s = "hello"; // Hypothetical range-like facilities for exposition only: auto r1 = make_range( counting(&s[0]), end_count(5) ); auto r2 = make_range( counting(&s[1]), end_count(4) ); assert(r1.end() != r2.end() && "really?"); The end sentinels have the same type and different state, but they refer to the same element. The question then is: What does it *mean* to compare sentinels for equality? The meaning has to be taken from the context in which the operation appears. In that context -- the algorithms -- the sentinel is one of two positions denoting a range. Iterator comparison is a position comparison. A sentinel, when it's paired with an iterator as in the algorithms, denotes a unique position. Since iterators must be valid sentinels, comparing sentinels should also be a position comparison. In this context, sentinels always represent the same position -- the end -- even though that position is not yet know. Hence, sentinels compare equal always, without any need to consider state. Anything else yields results that are inconsistent with the use of iterators to denote the end of a range. What about the examples above where sentinel comparison seems to give nonsensical results? In those examples, we are expecting sentinels to have meaning outside of their valid domain -- when they are considered in isolation of their paired iterator. It is the paired iterator that give the sentinel its "unique-position-ness", so we shouldn't expect an operation that compares position to make sense on an object that is not capable of representing a position by itself. Appendix 3: D Ranges and Algorithmic Complexity ===== As currently defined, D's ranges make it difficult to implement algorithms over bidirectional sequences that take a position in the middle as an argument. A good example is a hypothetical `is_word_boundary` algorithm. In C++ with iterators, it might look like this: template< BidirectionalIterator I > bool is_word_boundary( I begin, I middle, I end ) { bool is_word_prev = middle == begin ? false : isword(*prev(middle)); bool is_word_this = middle == end ? false : isword(*middle); return is_word_prev != is_word_this; } Users might call this in a loop to find the first word boundary in a range of characters as follows: auto i = myrange.begin(); for( ; i != myrange.end(); ++i ) if( is_word_boundary( myrange.begin(), i, myrange.end() ) ) break; The question is how such an API should be designed in D, since D doesn't have iterators. In a private email exchange, Andrei Alexandrescu, the designer of D's range library, described this potential implementation (the detailed implementation is ours): bool is_word_boundary(Range1, Range2)( Range1 front, Range2 back ) if (isBidirectionalRange!Range1 && isInputRange!Range2 ) { bool is_word_prev = front.empty ? false : isword(front.back); bool is_word_this = back.empty ? false : isword(back.front); return is_word_prev != is_word_this; } range r = myrange; size_t n = 0; for(range r = myrange; !r.empty; r.popFront(), ++n) if( is_word_boundary( takeExactly(myrange, n), r) ) break; This example uses D's `takeExactly` range adaptor. `takeExactly` is like Haskell's `take` function which creates a list from another list by taking the first `n` elements, but `takeExactly` requires that the input range has at least `n` elements begin with. The trouble with the above implementation is that `takeExactly` demotes Bidirectional ranges to Forward ranges. For example, taking the first *N* elements of a linked list cannot give access to the final element in O(1). So the `for` loop is trying to pass a Forward range to an algorithm that clearly requires a Bidirectional range. The only fix is to loosen the requirements of `Range1` to be Forward. To do that, the implementation of `is_word_boundary` needs to change so that, when it is passed a Forward range, it walks to the end of the `front` range and tests the last character. Obviously, that's an O(N) operation. In other words, by converting the `is_word_boundary` from iterators to D-style ranges, the algorithm goes from O(1) to O(N). From this we draw the following conclusion: D's choice of algorithmic *basis operations* is inherently less efficient than C++'s. Appendix 4: On Counted Ranges and Efficiency ===== The three types of ranges that we would like the Iterable concept to be able to efficiently model are: 1. Two iterators 2. An iterator and a predicate 3. An iterator and a count The Iterator/Sentinel abstraction is what makes it possible for the algorithms to handle these three cases with uniform syntax. However, the third option presents challenges when trying to make some algorithms optimally efficient. Counted ranges, formed by specifying a position and a count of elements, have iterators -- as all Iterables do. The iterators of a counted range must know the range's extent and how close they are to reaching it. Therefore, the counted range's iterators must store both an iterator into the underlying sequence and a count -- either a count to the end or a count from the front. Here is one potential design: class counted_sentinel {}; template<WeakIterator I> class counted_iterator { I it_; DistanceType<I> n_; // distance to end public: // ... constructors... using iterator_category = typename iterator_traits<I>::iterator_category; decltype(auto) operator*() const { return *it_; } counted_iterator & operator++() { ++it_; --n_; return *this; } friend bool operator==(counted_iterator const & it, counted_sentinel) { return it.n_ == 0; } // ... other operators... }; template<WeakIterator I> class counted_range { I begin_; DistanceType<I> count_; public: // ... constructors ... counted_iterator<I> begin() const { return {begin_, count_}; } counted_sentinel end() const { return {}; } }; template<WeakIterator I> struct common_type<counted_iterator<I>, counted_sentinel> // ... see Appendix 2 ... There are some noteworthy things about the code above. First, `counted_iterator` bundles an iterator and a count. Right off, we see that copying counted iterators is going to be more expensive, and iterators are copied frequently. A mitigating factor is that the sentinel is empty. Passing a `counted_iterator` and a `counted_sentinel` to an algorithm copies as much data as passing an iterator and a count. When passed separately, the compiler probably has an easier time fitting them in registers, but some modern compilers are capable passing the members of a struct in registers. This compiler optimization is sometimes called Scalar Replacement of Aggregates (see Muchnick 1997, ch. 12.2 [@muchnick97]) and is known to be implemented in gcc and LLVM (see [this recent LLVM commit][15][@llvm-sroa] for example). Also, incrementing a counted iterator is expensive: it involves incrementing the underlying iterator and decrementing the internal count. To see why this is potentially expensive, consider the trivial case of passing a `counted_iterator<list<int>::iterator>` to `advance`. That counted iterator type is bidirectional, and `advance` must increment it *n* times: template<BidirectionalIterator I> void advance(I & i, DistanceType<I> n) { if(n >= 0) for(; n != 0; --n) ++i; else for(; n != 0; ++n) --i; } Notice that for each `++i` or `--i` here, *two* increments or decrements are happening when `I` is a `counted_iterator`. This is sub-optimal. A better implementation for `counted_iterator` is: template<BidirectionalIterator I> void advance(counted_iterator<I> & i, DistanceType<I> n) { i.n_ -= n; advance(i.it_, n); } This has a noticeable effect on the generated code. As it turns out, `advance` is one of the relatively few places in the standard library where special handling of `counted_iterator` is advantageous. Let's examine some algorithms to see why that's the case. ## Single-Pass Algorithms with Counted Iterators First, let's look at a simple algorithm like `for_each` that makes exactly one pass through its input sequence: template<InputIterator I, Regular S, Function<ValueType<I>> F> requires EqualityComparable<I, S> I for_each(I first, S last, F f) { for(; first != last; ++first) f(*first); return first; } When passed counted iterators, at each iteration of the loop, we do an increment, a decrement (for the underlying iterator and the count), and a comparison. Let's compare this against a hypothetical `for_each_n` algorithm that takes the underlying iterator and the count separately. It might look like this: template<InputIterator I, Function<ValueType<I>> F> I for_each_n(I first, DifferenceType<I> n, F f) { for(; n != 0; ++first, --n) f(*first); return first; } For the hypothetical `for_each_n`, at each loop iteration, we do an increment, a decrement, and a comparison. That's exactly as many operations as `for_each` does when passed counted iterators. So a separate `for_each_n` algorithm is probably unnecessary if we have sentinels and `counted_iterator`s. This is true for any algorithm that makes only one pass through the input range. That turns out to be a lot of algorithms. ## Multi-Pass Algorithms with Counted Iterators There are other algorithms that make more than one pass over the input sequence. Most of those, however, use `advance` when they need to move iterators by more than one hop. Once we have specialized `advance` for `counted_iterator`, those algorithms that use `advance` get faster without any extra work. Consider `partition_point`. Here is one example implementation, taken from [libc++][17][@libcxx] and ported to Concepts Lite and sentinels: template<ForwardIterator I, Regular S, Predicate<ValueType<I>> P> requires EqualityComparable<I, S> I partition_point(I first, S last, P pred) { DifferenceType<I> len = distance(first, last); while (len != 0) { DifferenceType<I> l2 = len / 2; I m = first; advance(m, l2); if (pred(*m)) { first = ++m; len -= l2 + 1; } else len = l2; } return first; } Imagine that `I` is a forward `counted_iterator` and `S` is a `counted_sentinel`. If the library does not specialize `advance`, this is certainly inefficient. Every time `advance` is called, needless work is being done. Compare it to a hypothetical `partition_point_n`: template<ForwardIterator I, Predicate<ValueType<I>> P> I partition_point_n(I first, DifferenceType<I> len, P pred) { while (len != 0) { DifferenceType<I> l2 = len / 2; I m = first; advance(m, l2); if (pred(*m)) { first = ++m; len -= l2 + 1; } else len = l2; } return first; } The first thing we notice is that `partition_point_n` doesn't need to call `distance`! The more subtle thing to note is that calling `partition_point_n` with a raw iterator and a count saves about O(N) integer decrements over the equivalent call to `partition_point` with `counted_iterator`s ... unless, of course, we have specialized the `advance` algorithm as shown above. Once we have, we trade the O(N) integer decrements for O(log N) integer subtractions. That's a big improvement. But what about the O(N) call to `distance`? Actually, that's easy, and it's the reason why the SizedIteratorRange concept exists. `counted_iterator` stores the distance to the end. So the distance between a `counted_iterator` and a `counted_sentinel` (or between two `counted_iterators`) is known in O(1) *regardless of the iterator's category*. The SizedIteratorRange concept tests whether an iterator `I` and a sentinel `S` can be subtracted to get the distance. This concept is modeled by random-access iterators by their nature, but also by counted iterators and their sentinels. The `distance` algorithm is specialized for SizedIteratorRange, so it is O(1) for counted iterators. With these changes, we see that `partition_point` with counted iterators is very nearly as efficient as a hypothetical `partition_point_n` would be, and we had to make no special accommodations. Why can't we make `partition_point` *exactly* as efficient as `partition_point_n`? When `partition_point` is called with a counted iterator, it also *returns* a counted iterator. Counted iterators contain two datums: the position and distance to the end. But when `partition_point_n` returns just the position, it is actually computing and returning less information. Sometimes users don't need the extra information. But sometimes, after calling `partition_point_n`, the user might want to pass the resulting iterator to another algorithm. If *that* algorithm calls `distance` (like `partition_point` and other algorithms do), then it will be O(N). With counted iterators, however, it's O(1). So in the case of `partition_point`, counted iterators cause the algorithm to do O(log N) extra work, but it sometimes saves O(N) work later. To see an example, imagine a trivial `insertion_sort` algorithm: template<ForwardIterator I, Regular S> requires EqualityComparable<I, S> && Sortable<I> // from N3351 void insertion_sort(I begin, S end) { for(auto it = begin; it != end; ++it) { auto insertion = upper_bound(begin, it, *it); rotate(insertion, it, next(it)); } } Imagine that `I` is a `counted_iterator`. The first thing `upper_bound` does is call `distance`. Making `distance` O(1) for `counted_iterator`s saves N calls of an O(N) algorithm. To get comparable performance for an equivalent procedure in today's STL, users would have to write a separate `insertion_sort_n` algorithm that dispatches to an `upper_bound_n` algorithm -- that they would also need to write themselves. ## Counted Algorithms with Counted Iterators We've seen that regular algorithms with counted iterators can be made nearly as efficient as dedicated counted algorithms, and that sometimes we are more than compensated for the small performance loss. All is not roses, however. There are a number of *counted algorithms* in the standard (the algorithms whose names end with `_n`). Consider `copy_n`: template<WeakInputIterator I, WeakOutputIterator<ValueType<I>> O> pair<I, O> copy_n(I in, DifferenceType<I> n, O out) { for(; n != 0; ++in, ++out, --n) *out = *in; return {in, out}; } (We've changed the return type of `copy_n` so as not to lose information.) If `I` is a counted iterator, then for every `++in`, an increment and a decrement are happening, and in this case the extra decrement is totally unnecessary. For *any* counted (i.e., `_n`) algorithm, something special needs to be done to keep the performance from degrading when passed counted iterators. The algorithm author has two options here, and neither of them is ideal. **Option 1: Overload the algorithm** The following is an optimized version of `copy_n` for counted iterators: template<WeakInputIterator I, WeakOutputIterator<ValueType<I>> O> pair<I, O> copy_n(counted_iterator<I> in, DifferenceType<I> n, O out) { for(auto m = in.n_ - n; in.n_ != m; ++in.i_, --in.n_, ++out) *out = *in; return {in, out}; } Obviously, creating an overload for counted iterators is unsatisfying. **Option 2: Separate the iterator from the count** This option shows how a library implementer can write just one version of `copy_n` that is automatically optimized for counted iterators. First, we need to provide two utility functions for unpacking and repacking counted iterators: template<WeakIterator I> I uncounted(I i) { return i; } template<WeakIterator I> I uncounted(counted_iterator<I> i) { return i.it_; } template<WeakIterator I> I recounted(I const &, I i, DifferenceType<I>) { return i; } template<WeakIterator I> counted_iterator<I> recounted(counted_iterator<I> const &j, I i, DifferenceType<I> n) { return {i, j.n_ - n}; } With the help of `uncounted` and `recounted`, we can write an optimized `copy_n` just once: template<WeakInputIterator I, WeakOutputIterator<ValueType<I>> O> pair<I, O> copy_n(I in_, DifferenceType<I> n_, O out) { auto in = uncounted(in_); for(auto n = n_; n != 0; ++in, --n, ++out) *out = *in; return {recounted(in_, in, n_), out}; } This version works optimally for both counted and non-counted iterators. It is not a thing of beauty, however. It's slightly annoying to have to do the `uncounted`/`recounted` dance, but it's mostly needed only in the counted algorithms. As a final note, the overload of `advance` for counted iterators can be eliminated with the help of `uncounted` and `recounted`. After all, `advance` is a counted algorithm. ## Benchmark: Insertion Sort To test how expensive counted ranges and counted iterators are, we wrote a benchmark. The benchmark program pits counted ranges against a dedicated `_n` algorithm for [Insertion Sort](http://en.wikipedia.org/wiki/Insertion_sort). The program is listed below: #include <chrono> #include <iostream> #include <range/v3/range.hpp> class timer { private: std::chrono::high_resolution_clock::time_point start_; public: timer() { reset(); } void reset() { start_ = std::chrono::high_resolution_clock::now(); } std::chrono::milliseconds elapsed() const { return std::chrono::duration_cast<std::chrono::milliseconds>( std::chrono::high_resolution_clock::now() - start_); } friend std::ostream &operator<<(std::ostream &sout, timer const &t) { return sout << t.elapsed().count() << "ms"; } }; template<typename It> struct forward_iterator { It it_; template<typename U> friend struct forward_iterator; public: typedef std::forward_iterator_tag iterator_category; typedef typename std::iterator_traits<It>::value_type value_type; typedef typename std::iterator_traits<It>::difference_type difference_type; typedef It pointer; typedef typename std::iterator_traits<It>::reference reference; forward_iterator() : it_() {} explicit forward_iterator(It it) : it_(it) {} reference operator*() const {return *it_;} pointer operator->() const {return it_;} forward_iterator& operator++() {++it_; return *this;} forward_iterator operator++(int) {forward_iterator tmp(*this); ++(*this); return tmp;} friend bool operator==(const forward_iterator& x, const forward_iterator& y) {return x.it_ == y.it_;} friend bool operator!=(const forward_iterator& x, const forward_iterator& y) {return !(x == y);} }; template<typename I, typename V2> I upper_bound_n(I begin, typename std::iterator_traits<I>::difference_type d, V2 const &val) { while(0 != d) { auto half = d / 2; auto middle = std::next(begin, half); if(val < *middle) d = half; else { begin = ++middle; d -= half + 1; } } return begin; } template<typename I> void insertion_sort_n(I begin, typename std::iterator_traits<I>::difference_type n) { auto m = 0; for(auto it = begin; m != n; ++it, ++m) { auto insertion = upper_bound_n(begin, m, *it); ranges::rotate(insertion, it, std::next(it)); } } template<typename I, typename S> void insertion_sort(I begin, S end) { for(auto it = begin; it != end; ++it) { auto insertion = ranges::upper_bound(begin, it, *it); ranges::rotate(insertion, it, std::next(it)); } } template<typename Rng> void insertion_sort(Rng && rng) { ::insertion_sort(std::begin(rng), std::end(rng)); } std::unique_ptr<int[]> data(int i) { std::unique_ptr<int[]> a(new int[i]); auto rng = ranges::view::counted(a.get(), i); ranges::iota(rng, 0); return a; } void shuffle(int *a, int i) { auto rng = ranges::view::counted(a, i); ranges::random_shuffle(rng); } constexpr int cloops = 3; template<typename I> void benchmark_n(int i) { auto a = data(i); long ms = 0; for(int j = 0; j < cloops; ++j) { ::shuffle(a.get(), i); timer t; insertion_sort_n(I{a.get()}, i); ms += t.elapsed().count(); } std::cout << (int)((double)ms/cloops) << std::endl; } template<typename I> void benchmark_counted(int i) { auto a = data(i); long ms = 0; for(int j = 0; j < cloops; ++j) { ::shuffle(a.get(), i); timer t; insertion_sort(ranges::view::counted(I{a.get()}, i)); ms += t.elapsed().count(); } std::cout << (int)((double)ms/cloops) << std::endl; } int main(int argc, char *argv[]) { if(argc < 2) return -1; int i = std::atoi(argv[1]); std::cout << "insertion_sort_n (random-access) : "; benchmark_n<int*>(i); std::cout << "insertion_sort (random-access) : "; benchmark_counted<int*>(i); std::cout << "\n"; std::cout << "insertion_sort_n (forward) : "; benchmark_n<forward_iterator<int*>>(i); std::cout << "insertion_sort (forward) : "; benchmark_counted<forward_iterator<int*>>(i); } The program implements both `insertion_sort_n`, a dedicated counted algorithm, and `insertion_sort`, a general algorithm that accepts any Iterable, to which we pass a counted range. The latter is implemented in terms of the general-purpose `upper_bound` as provided by the Range v3 library, whereas the former requires a dedicated `upper_bound_n` algorithm, which is also provided. The test is run both with raw pointers (hence, random-access) and with an iterator wrapper that only models ForwardIterator. Each test is run three times, and the resulting times are averaged. The test was compiled with `g++` version 4.9.0 with `-O3 -std=gnu++11 -DNDEBUG` and run on a Linux machine. The results are reported below, for N == 30,000: &nbsp; | `insertion_sort_n` | `insertion_sort` --------------|--------------------|----------------- random-access | 2.692 s | 2.703 s forward | 23.853 s | 23.817 s The performance difference, if there is any, is lost in the noise. At least in this case, with this compiler, on this hardware, there is no performance justification for a dedicated `_n` algorithm. **Summary** In short, counted iterators are not a *perfect* abstraction. There is some precedent here. The iterators for `deque`, and for any segmented data structure, are known to be inefficient (see [Segmented Iterators and Hierarchical Algorithms][14], Austern 1998[@austern98]). The fix for that problem, new iterator abstractions and separate hierarchical algorithm implementations, is invasive and is not attempted in any STL implementation we are aware of. In comparison, the extra complications that come with counted iterators seem quite small. For segmented iterators, the upside was the simplicity and uniformity of the Iterator abstraction. In the case of counted ranges and iterators, the upside is the simplicity and uniformity of the Iterable concept. Algorithms need only one form, not separate bounded, counted, and sentinel forms. Our benchmark gives us reasonable assurance that we aren't sacrificing performance for the sake of a unifying abstraction. Appendix 5: Drive-By Improvements to the Standard Algorithms ===== As we are making changes to the standard algorithms, not all of which are strictly source compatible, here are some other drive-by changes that we might consider making. The changes suggested below have nothing to do with ranges *per se*, but they increase the power and uniformity of the STL and they have proven useful in the Adobe Source Library, so we might consider taking all these changes in one go. ## Higher-Order Algorithms Should Take Invokables Instead of Functions Some algorithms like `for_each` are higher-order; they take functions as parameters. In [N3351][8][@n3351], they are constrained with the `Function` concept which, among other things, requires that its parameters can be used to form a valid callable expression `f(a)`. However, consider a class `S` with a member function `Do`, like: class S { public: void Do() const; }; If we have a `vector` of `S` objects and we want to `Do` all of them, this is what we need to do: for_each( v, [](auto & s) { s.Do(); }); or, more concisely with a `bind` expression: for_each( v, bind(&S::Do, _1) ); Note that `bind` is specified in terms of a hypothetical INVOKE utility in [func.require]. Wouldn't it be more convenient if all the algorithms were required to merely take INVOKE-able things -- that is, things that can be passed to `bind` -- as arguments, instead of Functions? Then we can express the above call to `for_each` more concisely as: for_each( v, &S::Do ); We can define an `invokable` utility function as: template<typename R, typename T> auto invokable(R T::* p) const -> decltype(std::mem_fn(p)) { return std::mem_fn(p); } template<typename T, typename U = decay_t<T>> auto invokable(T && t) const -> enable_if_t<!is_member_pointer<U>::value, T> { return std::forward<T>(t); } template<typename F> using invokable_t = decltype(invokable(std::declval<F>())); We can define an Invokable concept as: concept Invokable<Semiregular F, typename... As> = Function<invokable_t<F>, As...> && requires (F f, As... as) { InvokableResultOf<F, As...>; InvokableResultOf<F, As...> == invokable(f)(as...); }; The Invokable concept can be used to constrain algorithms instead of the Function concept. The algorithms would need to apply `invokable` to each Invokable argument before invoking it. This is pure extension and would break no code. ## Algorithms Should Take Invokable Projections The [Adobe Source Libraries (ASL)][3][@asl] pioneered the use of "projections" to make the algorithms more powerful and expressive by increasing interface symmetry. Sean Parent gives a motivating example in his ["C++ Seasoning" talk][6][@cpp-seasoning], on slide 38. With today's STL, when using `sort` and `lower_bound` together with user-defined predicates, the predicate must sometimes differ. Consider: std::sort(a, [](const employee& x, const employee& y) { return x.last < y.last; }); auto p = std::lower_bound(a, "Parent", [](const employee& x, const string& y) { return x.last < y; }); Notice the different predicates used in the invocations of `sort` and `lower_bound`. Since the predicates are different, there is a chance they might get out of sync leading to subtle bugs. By introducing the use of projections, this code is simplified to: std::sort(a, std::less<>(), &employee::last); auto p = std::lower_bound(a, "Parent", std::less<>(), &employee::last); Every element in the input sequence is first passed through the projection `&employee::last`. As a result, the simple comparison predicate `std::less<>` can be used in both places. No effort was made in ASL to use projections consistently. This proposal bakes them in everywhere it makes sense. Here are the guidelines to be applied to the standard algorithms: - Wherever appropriate, algorithms should optionally take INVOKE-able *projections* that are applied to each element in the input sequence(s). This, in effect, allows users to trivially transform each input sequence for the sake of that single algorithm invocation. - Algorithms that take two input sequences should (optionally) take two projections. - For algorithms that optionally accept functions/predicates (e.g. `transform`, `sort`), projection arguments follow functions/predicates. There are no algorithm overloads that allow the user to specify the projection without also specifying a predicate, even if the default would suffice. This is to reduce the number of overloads and also to avoid any potential for ambiguity. An open design question is whether all algorithms should take projections, or only the higher-order algorithms. In our current design, all algorithms take projections. This makes it trivial to, say, copy all the keys of a map by using the standard `copy` algorithm with `&pair<const key,value>::first` as the projection. ### Projections versus Range Transform View In a sense, the use of a projection parameter to an algorithm is similar to applying a transform view directly to a range. For example, calling `std::find` with a projection is similar to applying a transform to a range and calling without the projection: auto it = std::find( a, 42, &employee::age ); auto a2 = a | view::transform( &employee::age ); auto it2 = std::find( a2, 42 ); Aside from the extra verbosity of the view-based solution, there are two meaningful differences: (1) The type of the resulting iterator is different; `*it` refers to an `employee` whereas `*it2` refers to an `int`. And (2) if the transform function returns an rvalue, then the transformed view cannot model a forward sequence due to the current requirements on the ForwardIterator concept. The result of applying a transform view is an Input range unless the transform function returns an lvalue. The projection-based interface suffers no such degradation of the iterator category. (Note: if the concepts in [N3351][8][@n3351] are adopted, this argument is no longer valid.) For those reasons, range transform adapters are not a replacement for projection arguments to algorithms. See [Algorithm Implementation with Projections](#algorithm-implementation-with-projections) for a discussion of how projections affect the implementation. The addition of projection arguments to the algorithms is pure extension. Appendix 6: Implementation Notes ===== ## On Distinguishing Ranges from Non-Range Iterables The design of the range library depends on the ability to tell apart Ranges from Iterables. Ranges are lightweight objects that refer to elements they do not own. As a result, they can guarantee O(1) copyability and assignability. Iterables, on the other hand, may or may not own their elements, and so cannot guarantee anything about the algorithmic complexity of their copy and assign operations. Indeed, an Iterable may not be copyable at all: it may be a native array or a `vector` of move-only types. But how to tell Ranges apart from Iterables? After all, whether an Iterable owns its elements or not is largely a semantic difference with no purely syntactic way to differentiate. Well, that's almost true... It turns out that there is a reasonably good heuristic we can use to tell Iterables and Ranges apart. Imagine that we have some Iterable type `T` that is either a container like `list`, `vector`, or a native array; or else it's a Range like `pair<int*,int*>`. Then we can imagine taking iterators to `T` and `const T`, dereferencing them, and comparing the resulting reference types. The following table gives the results we might expect to find. Expression | Container | Range --------------------------------|-----------------------|----------------------- `*begin(declval<T&>())` | `value_type &` | `[const] value_type &` `*begin(declval<const T&>())` | `const value_type &` | `[const] value_type &` Notice how containers and ranges differ in the way a top-level cv-qualifier affects the reference type. Since a range is a proxy to elements stored elsewhere, a top-level `const` qualification on the *range* object typically has no effect at all on its iterator's reference type. But that's not true for a container that owns its elements. We can use this to build an `is_range` traits that gives a pretty good guess whether an Iterable type is a range or not. This trait can be used to define the Range concept. Obviously since it's a trait, users are free to specialize it if the trait guesses wrong. Some people want their range types to behave like containers with respect to the handling of top-level `const`; that is, they would like their ranges to be designed such that if the range object is `const`, the range's elements cannot be mutated through it. There is nothing about the Range concepts that precludes that design, but it does require the developer of such a range to specialize the `is_range` trait. If anything, the default behavior of the trait can be seen as gentle encouragement to handle top-level `const` in a way that is consistent with ranges' nature as a lightweight proxy. As an added convenience, we can provide a class, `range_base`, from which users can create a derived type as another way of opting in to "range-ness". The `is_range` trait can test for derivation from `range_base` as an extra test. This would save users the trouble of opening the `std` namespace to specialize the `is_range` trait on the rare occasions that that is necessary. The `is_range` trait will also need to be specialized for immutable containers, for which both the mutable and const iterators have the same reference type. A good example is `std::set`. If the `is_range` trait erroneously reports `false` for a type that is actually a range, then the library errs on the side of caution and will prevent the user from using rvalues of that type in range adaptor pipelines. If, on the other hand, the `is_range` trait gets the answer wrong for a type that is actually a container, the container ends up being copied or moved into range adaptors. This is a performance bug, and it may give surprising results at runtime if the original container doesn't get mutated when the user thinks it should. It's not a memory error, though. ## Algorithm Implementation with Projections Rather than requiring additional overloads, the addition of projection arguments has very little cost to library implementers. The use of function template default parameters obviates the need for overloads. For instance, `find` can be defined as: template<InputIterator I, Regular S, typename V, Invokable<ValueType<I>> Proj = identity> requires EqualityComparable<I, S> && EqualityComparable<V, InvokableResultOf<Proj, ValueType<I>>> I find(I first, S last, V const & val, Proj proj = Proj{}) { /* ... */ } ## Algorithms That Need An End Iterator Some algorithms need to know the real physical end of the input sequence so that the sequence can be traversed backwards, like `reverse`. In those cases, it's helpful to have an algorithm `advance_to` that takes an iterator and a sentinel and returns a real end iterator. `advance_to` looks like this: template<Iterator I, Regular S> requires IteratorRange<I, S> I advance_to( I i, S s ) { while(i != s) ++i; return i; } template<Iterator I, Regular S> requires SizedIteratorRange<I, S> I advance_to( I i, S s ) { advance( i, s - i ); return i; } template<Iterator I> I advance_to( I, I s ) { return s; } When the sentinel is actually an iterator, we already know where the end is so we can just return it. Notice how we handle SizedIteratorRanges specially and dispatch to `advance` with a count. [Appendix 4](#appendix-4-on-counted-ranges-and-efficiency) shows how `advance` is optimized for counted iterators. By dispatching to `advance` when we can, we make `advance_to` faster for counted iterators, too. With `advance_to` we can implement `reverse` generically as: template<BidirectionalIterator I, Regular S> requires EqualityComparable<I, S> && Permutable<I> I reverse( I first, S last_ ) { I last = advance_to( first, last_ ), end = last; while( first != last ) { if( first == --last ) break; iter_swap( first, last ); ++first; } return end; } Since this algorithm necessarily computes the end of the sequence if it isn't known already, we return it.
0
repos/range-v3/doc
repos/range-v3/doc/std/pandoc-template.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"$if(lang)$ lang="$lang$" xml:lang="$lang$"$endif$> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <meta name="generator" content="pandoc" /> $for(author-meta)$ <meta name="author" content="$author-meta$" /> $endfor$ $if(date-meta)$ <meta name="date" content="$date-meta$" /> $endif$ <title>$if(title-prefix)$$title-prefix$ - $endif$$pagetitle$</title> <style type="text/css">code{white-space: pre;}</style> $if(quotes)$ <style type="text/css">q { quotes: "“" "”" "‘" "’"; }</style> $endif$ $if(highlighting-css)$ <style type="text/css"> $highlighting-css$ </style> $endif$ $for(css)$ <link rel="stylesheet" href="$css$" $if(html5)$$else$type="text/css" $endif$/> $endfor$ $if(math)$ $math$ $endif$ $for(header-includes)$ $header-includes$ $endfor$ </head> <body> $for(include-before)$ $include-before$ $endfor$ $if(title)$ <div id="$idprefix$header"> <h1 class="title">$title$</h1> $if(subtitle)$ <h1 class="subtitle">$subtitle$</h1> $endif$ $for(author)$ <h2 class="author">$author$</h2> $endfor$ $if(date)$ <h3 class="date">$date$</h3> $endif$ </div> $endif$ <blockquote> <p>“A beginning is the time for taking the most delicate care that the balances are correct.”</p> <p> – Frank Herbert, <em>Dune</em> </p> </blockquote> $if(toc)$ <div id="$idprefix$TOC"> $toc$ </div> $endif$ $body$ $for(include-after)$ $include-after$ $endfor$ </body> </html>
0
repos
repos/zig-vb6_x86/import.bat
copy zig-dll-sample\zig-out\lib\zig-dll-sample.dll vb6-dll-import\
0
repos
repos/zig-vb6_x86/README.md
<h3 align="center"> Proof of Concept: Testing Interoperability Between <a href="https://github.com/ziglang/zig">Zig</a> and <a href="https://en.wikipedia.org/wiki/Visual_Basic_(classic)">VB6</a><br/><br/> <img src="https://raw.githubusercontent.com/ezekielbaniaga/zig-vb6_x86/master/screenshot.png" width="960"/> </h3> <p align="center"> Discover the compatibility of Zig and VB6 in this interoperability test. This project serves as a proof of concept, demonstrating how these technologies can work together effectively. </p> <br/><br/> <h3 align="left">Code Features</h3> <p align="left"> This code demonstrates several important concepts, including the implementation of callback functions, the seamless exchange of String or u8 slices between Zig and VB6, the passing of integers (i32) in both directions, and the utilization of the CopyMemory API from the kernel32 library. </p> <h3 align="left">Note</h3> <p align="left"> To run this code successfully, it's essential to create an executable from it. Simply running it inside VB6 IDE won't suffice. An error "Bad DLL calling convention" might occur when running inside VB6 IDE. </p> <p align="left"> If you come across a solution to the 'Bad DLL calling convention' error, please don't hesitate to reach out and share your findings. Your insights and expertise could greatly benefit our community, and we appreciate your willingness to contribute to the resolution of this issue. </p> <h3 align="left">DLL Output Using Zig</h3> <p align= "left"> <b>Default Target:</b> This project is configured with Windows X86 and the MSVC ABI as the default target for the `zig build` command. If your project is intended for this target, you can simply use: <br/> ``` zig build ``` Zig will automatically build your project for Windows X86 with the MSVC ABI when you run the command without specifying a target. Check build.zig for more info. </p> <h3 align="left">VB6 Note:</h3> <p align="left"> Installing Visual Basic 6 (VB6) on modern operating systems can be a bit challenging due to compatibility issues. However, there are several helpful tutorials available on the internet that guide you through the installation process and offer workarounds to make VB6 run smoothly on the latest platforms. </p>
0
repos/zig-vb6_x86
repos/zig-vb6_x86/zig-dll-sample/build.zig
const std = @import("std"); // Although this function looks imperative, note that its job is to // declaratively construct a build graph that will be executed by an external // runner. pub fn build(b: *std.Build) void { // Standard target options allows the person running `zig build` to choose // what target to build for. Here we do not override the defaults, which // means any target is allowed, and the default is native. Other options // for restricting supported target set are available. const target = b.standardTargetOptions(.{ .default_target = .{ .cpu_arch = std.Target.Cpu.Arch.x86, .os_tag = std.Target.Os.Tag.windows, .abi = std.Target.Abi.msvc } }); // Standard optimization options allow the person running `zig build` to select // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not // set a preferred release mode, allowing the user to decide how to optimize. const optimize = b.standardOptimizeOption(.{}); // Use this for generating static library -> .lib file // const lib = b.addStaticLibrary(.{ // Use to create shared .dll file const lib = b.addSharedLibrary(.{ .name = "zig-dll-sample", // In this case the main source file is merely a path, however, in more // complicated build scripts, this could be a generated file. .root_source_file = .{ .path = "src/main.zig" }, .target = target, .optimize = optimize, }); // This declares intent for the library to be installed into the standard // location when the user invokes the "install" step (the default step when // running `zig build`). b.installArtifact(lib); // Creates a step for unit testing. This only builds the test executable // but does not run it. const main_tests = b.addTest(.{ .root_source_file = .{ .path = "src/main.zig" }, .target = target, .optimize = optimize, }); const run_main_tests = b.addRunArtifact(main_tests); // This creates a build step. It will be visible in the `zig build --help` menu, // and can be selected like this: `zig build test` // This will evaluate the `test` step rather than the default, which is "install". const test_step = b.step("test", "Run library tests"); test_step.dependOn(&run_main_tests.step); }
0
repos/zig-vb6_x86/zig-dll-sample
repos/zig-vb6_x86/zig-dll-sample/src/main.zig
const std = @import("std"); const testing = std.testing; // Declarations for testMsg var stat: i32 = 0; pub const fnCallbackTestMsg = *const fn () void; // Declarations for testString var lastMessage: [*:0]const u8 = undefined; pub const fnCallbackTestString = *const fn () void; export fn add(a: i32, b: i32) i32 { return a + b; } export fn testMsg(msg: [*:0]const u8, cbk: fnCallbackTestMsg) void { _ = std.os.windows.user32.MessageBoxA(null, msg, "MessageBox From Zig", 0); _ = std.os.windows.user32.MessageBoxA(null, "The internal variable 'stat' has been mutated.\n Call 'getStat' to retrieve its value", "MessageBox from Zig", 0); stat = 12; cbk(); } export fn testString(cbk: fnCallbackTestString) void { _ = std.os.windows.user32.MessageBoxA(null, "The internal variable 'lastMessage' has been mutated.\n Call 'getLastMessage' to retrieve its value", "MessageBox from Zig", 0); lastMessage = "This is the last message"; cbk(); } export fn getStat() i32 { return @as(i32, stat); } export fn getLastMessage() [*:0]const u8 { return lastMessage; } test "basic add functionality" { try testing.expect(add(3, 7) == 10); } test "hello Test" { testMsg("Hello there!"); std.time.sleep(3 * std.time.ns_per_s); }
0
repos
repos/zig-serial/README.md
# Zig Serial Port Library Library for configuring and listing serial ports. ## Features - Basic serial port configuration - Baud Rate - Parity (none, even, odd, mark, space) - Stop Bits (one, two) - Handshake (none, hardware, software) - Byte Size (5, 6, 7, 8) - Flush serial port send/receive buffers - List available serial ports - API: supports Windows, Linux and Mac ## Example ```zig // Port configuration. // Serial ports are just files, \\.\COM1 for COM1 on Windows: var serial = try std.fs.cwd().openFile("\\\\.\\COM1", .{ .mode = .read_write }) ; defer serial.close(); try zig_serial.configureSerialPort(serial, zig_serial.SerialConfig{ .baud_rate = 19200, .word_size = 8, .parity = .none, .stop_bits = .one, .handshake = .none, }); ``` ## Usage ### Library integration Integrate the library in your project via the Zig package manager: - add `serial` to your `.zig.zon` file by providing the URL to the archive of a tag or specific commit of the library - to update the hash, run `zig fetch --save [URL/to/tag/or/commit.tar.gz]` ### Running tests The `build.zig` file contains a test step that can be called with `zig build test`. Note that this requires a serial port to be available on the system; - Linux: `/dev/ttyUSB0` - Mac: `/dev/cu.usbmodem101` - Windows: `COM3` ### Building the examples You can build the examples from the `./examples` directory by calling `zig build examples`. Binaries will be generated in `./zig-out/bin` by default. - Note that the `list_port_info` example currently only works on Windows
0
repos
repos/zig-serial/build.zig.zon
.{ .name = "serial", .version = "0.0.1", .paths = .{ "src", // all files in src directory "README.md", "LICENSE", "build.zig", "build.zig.zon", }, }
0
repos
repos/zig-serial/build.zig
const std = @import("std"); const log = std.log.scoped(.serial_lib__build); const example_files = [_][]const u8{ "echo", "list", "list_port_info", }; pub fn build(b: *std.Build) void { const optimize = b.standardOptimizeOption(.{}); const target = b.standardTargetOptions(.{}); const serial_mod = b.addModule("serial", .{ .root_source_file = b.path("src/serial.zig"), }); const unit_tests = b.addTest(.{ .root_source_file = b.path("src/serial.zig"), .target = target, .optimize = optimize, }); const run_unit_tests = b.addRunArtifact(unit_tests); const test_step = b.step("test", "Run unit tests"); test_step.dependOn(&run_unit_tests.step); const example_step = b.step("examples", "Build examples"); { for (example_files) |example_name| { const example = b.addExecutable(.{ .name = example_name, .root_source_file = b.path( b.fmt("examples/{s}.zig", .{example_name}), ), .target = target, .optimize = optimize, }); // port info only works on Windows! // TODO: Linux and MacOS port info support if (std.mem.eql(u8, example_name, "list_port_info") and example.rootModuleTarget().os.tag != .windows) { log.warn("skipping example 'list_port_info' - only supported on Windows", .{}); continue; } example.root_module.addImport("serial", serial_mod); const install_example = b.addInstallArtifact(example, .{}); example_step.dependOn(&example.step); example_step.dependOn(&install_example.step); } } }
0
repos/zig-serial
repos/zig-serial/src/serial.zig
const std = @import("std"); const builtin = @import("builtin"); const c = @cImport(@cInclude("termios.h")); pub fn list() !PortIterator { return try PortIterator.init(); } pub fn list_info() !InformationIterator { return try InformationIterator.init(); } pub const PortIterator = switch (builtin.os.tag) { .windows => WindowsPortIterator, .linux => LinuxPortIterator, .macos => DarwinPortIterator, else => @compileError("OS is not supported for port iteration"), }; pub const InformationIterator = switch (builtin.os.tag) { .windows => WindowsInformationIterator, .linux, .macos => @panic("'Port Information' not yet implemented for this OS"), else => @compileError("OS is not supported for information iteration"), }; pub const SerialPortDescription = struct { file_name: []const u8, display_name: []const u8, driver: ?[]const u8, }; pub const PortInformation = struct { port_name: []const u8, system_location: []const u8, friendly_name: []const u8, description: []const u8, manufacturer: []const u8, serial_number: []const u8, // TODO: review whether to remove `hw_id`. // Is this useless/being used in a Windows-only way? hw_id: []const u8, vid: u16, pid: u16, }; const HKEY = std.os.windows.HKEY; const HWND = std.os.windows.HANDLE; const HDEVINFO = std.os.windows.HANDLE; const DEVINST = std.os.windows.DWORD; const SP_DEVINFO_DATA = extern struct { cbSize: std.os.windows.DWORD, classGuid: std.os.windows.GUID, devInst: std.os.windows.DWORD, reserved: std.os.windows.ULONG_PTR, }; const WindowsPortIterator = struct { const Self = @This(); key: HKEY, index: u32, name: [256:0]u8 = undefined, name_size: u32 = 256, data: [256]u8 = undefined, filepath_data: [256]u8 = undefined, data_size: u32 = 256, pub fn init() !Self { const HKEY_LOCAL_MACHINE = @as(HKEY, @ptrFromInt(0x80000002)); const KEY_READ = 0x20019; var self: Self = undefined; self.index = 0; if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\SERIALCOMM\\", 0, KEY_READ, &self.key) != 0) return error.WindowsError; return self; } pub fn deinit(self: *Self) void { _ = RegCloseKey(self.key); self.* = undefined; } pub fn next(self: *Self) !?SerialPortDescription { defer self.index += 1; self.name_size = 256; self.data_size = 256; return switch (RegEnumValueA(self.key, self.index, &self.name, &self.name_size, null, null, &self.data, &self.data_size)) { 0 => SerialPortDescription{ .file_name = try std.fmt.bufPrint(&self.filepath_data, "\\\\.\\{s}", .{self.data[0 .. self.data_size - 1]}), .display_name = self.data[0 .. self.data_size - 1], .driver = self.name[0..self.name_size], }, 259 => null, else => error.WindowsError, }; } }; const WindowsInformationIterator = struct { const Self = @This(); index: std.os.windows.DWORD, device_info_set: HDEVINFO, port_buffer: [256:0]u8, sys_buffer: [256:0]u8, name_buffer: [256:0]u8, desc_buffer: [256:0]u8, man_buffer: [256:0]u8, serial_buffer: [256:0]u8, hw_id: [256:0]u8, const Property = enum(std.os.windows.DWORD) { SPDRP_DEVICEDESC = 0x00000000, SPDRP_MFG = 0x0000000B, SPDRP_FRIENDLYNAME = 0x0000000C, }; // GUID taken from <devguid.h> const DIGCF_PRESENT = 0x00000002; const DIGCF_DEVICEINTERFACE = 0x00000010; const device_setup_tokens = .{ .{ std.os.windows.GUID{ .Data1 = 0x4d36e978, .Data2 = 0xe325, .Data3 = 0x11ce, .Data4 = .{ 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 } }, DIGCF_PRESENT }, .{ std.os.windows.GUID{ .Data1 = 0x4d36e96d, .Data2 = 0xe325, .Data3 = 0x11ce, .Data4 = .{ 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 } }, DIGCF_PRESENT }, .{ std.os.windows.GUID{ .Data1 = 0x86e0d1e0, .Data2 = 0x8089, .Data3 = 0x11d0, .Data4 = .{ 0x9c, 0xe4, 0x08, 0x00, 0x3e, 0x30, 0x1f, 0x73 } }, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE }, .{ std.os.windows.GUID{ .Data1 = 0x2c7089aa, .Data2 = 0x2e0e, .Data3 = 0x11d1, .Data4 = .{ 0xb1, 0x14, 0x00, 0xc0, 0x4f, 0xc2, 0xaa, 0xe4 } }, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE }, }; pub fn init() !Self { var self: Self = undefined; self.index = 0; inline for (device_setup_tokens) |token| { const guid = token[0]; const flags = token[1]; self.device_info_set = SetupDiGetClassDevsW( &guid, null, null, flags, ); if (self.device_info_set != std.os.windows.INVALID_HANDLE_VALUE) break; } if (self.device_info_set == std.os.windows.INVALID_HANDLE_VALUE) return error.WindowsError; return self; } pub fn deinit(self: *Self) void { _ = SetupDiDestroyDeviceInfoList(self.device_info_set); self.* = undefined; } pub fn next(self: *Self) !?PortInformation { var device_info_data: SP_DEVINFO_DATA = .{ .cbSize = @sizeOf(SP_DEVINFO_DATA), .classGuid = std.mem.zeroes(std.os.windows.GUID), .devInst = 0, .reserved = 0, }; if (SetupDiEnumDeviceInfo(self.device_info_set, self.index, &device_info_data) != std.os.windows.TRUE) { return null; } defer self.index += 1; var info: PortInformation = std.mem.zeroes(PortInformation); @memset(&self.hw_id, 0); // NOTE: have not handled if port startswith("LPT") var length = getPortName(&self.device_info_set, &device_info_data, &self.port_buffer); info.port_name = self.port_buffer[0..length]; info.system_location = try std.fmt.bufPrint(&self.sys_buffer, "\\\\.\\{s}", .{info.port_name}); length = deviceRegistryProperty(&self.device_info_set, &device_info_data, Property.SPDRP_FRIENDLYNAME, &self.name_buffer); info.friendly_name = self.name_buffer[0..length]; length = deviceRegistryProperty(&self.device_info_set, &device_info_data, Property.SPDRP_DEVICEDESC, &self.desc_buffer); info.description = self.desc_buffer[0..length]; length = deviceRegistryProperty(&self.device_info_set, &device_info_data, Property.SPDRP_MFG, &self.man_buffer); info.manufacturer = self.man_buffer[0..length]; if (SetupDiGetDeviceInstanceIdA( self.device_info_set, &device_info_data, @ptrCast(&self.hw_id), 255, null, ) == std.os.windows.TRUE) { length = @as(u32, @truncate(std.mem.indexOfSentinel(u8, 0, &self.hw_id))); info.hw_id = self.hw_id[0..length]; length = parseSerialNumber(&self.hw_id, &self.serial_buffer) catch 0; if (length == 0) { length = getParentSerialNumber(device_info_data.devInst, &self.hw_id, &self.serial_buffer) catch 0; } info.serial_number = self.serial_buffer[0..length]; info.vid = parseVendorId(&self.hw_id) catch 0; info.pid = parseProductId(&self.hw_id) catch 0; } else { return error.WindowsError; } return info; } fn getPortName(device_info_set: *const HDEVINFO, device_info_data: *SP_DEVINFO_DATA, port_name: [*]u8) std.os.windows.DWORD { const hkey: HKEY = SetupDiOpenDevRegKey( device_info_set.*, device_info_data, 0x00000001, // #define DICS_FLAG_GLOBAL 0, 0x00000001, // #define DIREG_DEV, std.os.windows.KEY_READ, ); defer { _ = std.os.windows.advapi32.RegCloseKey(hkey); } inline for (.{ "PortName", "PortNumber" }) |key_token| { var port_length: std.os.windows.DWORD = std.os.windows.NAME_MAX; var data_type: std.os.windows.DWORD = 0; const result = RegQueryValueExA( hkey, @as(std.os.windows.LPSTR, @ptrCast(@constCast(key_token))), null, &data_type, port_name, &port_length, ); // if this is valid, return now if (result == 0 and port_length > 0) { return port_length; } } return 0; } fn deviceRegistryProperty(device_info_set: *const HDEVINFO, device_info_data: *SP_DEVINFO_DATA, property: Property, property_str: [*]u8) std.os.windows.DWORD { var data_type: std.os.windows.DWORD = 0; var bytes_required: std.os.windows.DWORD = std.os.windows.MAX_PATH; const result = SetupDiGetDeviceRegistryPropertyA( device_info_set.*, device_info_data, @intFromEnum(property), &data_type, property_str, std.os.windows.NAME_MAX, &bytes_required, ); if (result == std.os.windows.FALSE) { std.debug.print("GetLastError: {}\n", .{std.os.windows.kernel32.GetLastError()}); bytes_required = 0; } return bytes_required; } fn getParentSerialNumber(devinst: DEVINST, devid: []const u8, serial_number: [*]u8) !std.os.windows.DWORD { if (std.mem.startsWith(u8, devid, "FTDI")) { // Should not be called on "FTDI" so just return the serial number. return try parseSerialNumber(devid, serial_number); } else if (std.mem.startsWith(u8, devid, "USB")) { // taken from pyserial const max_usb_device_tree_traversal_depth = 5; const start_vidpid = std.mem.indexOf(u8, devid, "VID") orelse return error.WindowsError; const vidpid_slice = devid[start_vidpid .. start_vidpid + 17]; // "VIDxxxx&PIDxxxx" // keep looping over parent device to extract serial number if it contains the target VID and PID. var depth: u8 = 0; var child_inst: DEVINST = devinst; while (depth <= max_usb_device_tree_traversal_depth) : (depth += 1) { var parent_id: DEVINST = undefined; var local_buffer: [256:0]u8 = std.mem.zeroes([256:0]u8); if (CM_Get_Parent(&parent_id, child_inst, 0) != 0) return error.WindowsError; if (CM_Get_Device_IDA(parent_id, @ptrCast(&local_buffer), 256, 0) != 0) return error.WindowsError; defer child_inst = parent_id; if (!std.mem.containsAtLeast(u8, local_buffer[0..255], 1, vidpid_slice)) continue; const length = try parseSerialNumber(local_buffer[0..255], serial_number); if (length > 0) return length; } } return error.WindowsError; } fn parseSerialNumber(devid: []const u8, serial_number: [*]u8) !std.os.windows.DWORD { var delimiter: ?[]const u8 = undefined; if (std.mem.startsWith(u8, devid, "USB")) { delimiter = "\\&"; } else if (std.mem.startsWith(u8, devid, "FTDI")) { delimiter = "\\+"; } else { // What to do here? delimiter = null; } if (delimiter) |del| { var it = std.mem.tokenize(u8, devid, del); // throw away the start _ = it.next(); while (it.next()) |segment| { if (std.mem.startsWith(u8, segment, "VID_")) continue; if (std.mem.startsWith(u8, segment, "PID_")) continue; // If "MI_{d}{d}", this is an interface number. The serial number will have to be // sourced from the parent node. Probably do not have to check all these conditions. if (segment.len == 5 and std.mem.eql(u8, "MI_", segment[0..3]) and std.ascii.isDigit(segment[3]) and std.ascii.isDigit(segment[4])) return 0; @memcpy(serial_number, segment); return @as(std.os.windows.DWORD, @truncate(segment.len)); } } return error.WindowsError; } fn parseVendorId(devid: []const u8) !u16 { var delimiter: ?[]const u8 = undefined; if (std.mem.startsWith(u8, devid, "USB")) { delimiter = "\\&"; } else if (std.mem.startsWith(u8, devid, "FTDI")) { delimiter = "\\+"; } else { delimiter = null; } if (delimiter) |del| { var it = std.mem.tokenize(u8, devid, del); while (it.next()) |segment| { if (std.mem.startsWith(u8, segment, "VID_")) { return try std.fmt.parseInt(u16, segment[4..], 16); } } } return error.WindowsError; } fn parseProductId(devid: []const u8) !u16 { var delimiter: ?[]const u8 = undefined; if (std.mem.startsWith(u8, devid, "USB")) { delimiter = "\\&"; } else if (std.mem.startsWith(u8, devid, "FTDI")) { delimiter = "\\+"; } else { delimiter = null; } if (delimiter) |del| { var it = std.mem.tokenize(u8, devid, del); while (it.next()) |segment| { if (std.mem.startsWith(u8, segment, "PID_")) { return try std.fmt.parseInt(u16, segment[4..], 16); } } } return error.WindowsError; } }; extern "advapi32" fn RegOpenKeyExA( key: HKEY, lpSubKey: std.os.windows.LPCSTR, ulOptions: std.os.windows.DWORD, samDesired: std.os.windows.REGSAM, phkResult: *HKEY, ) callconv(std.os.windows.WINAPI) std.os.windows.LSTATUS; extern "advapi32" fn RegCloseKey(key: HKEY) callconv(std.os.windows.WINAPI) std.os.windows.LSTATUS; extern "advapi32" fn RegEnumValueA( hKey: HKEY, dwIndex: std.os.windows.DWORD, lpValueName: std.os.windows.LPSTR, lpcchValueName: *std.os.windows.DWORD, lpReserved: ?*std.os.windows.DWORD, lpType: ?*std.os.windows.DWORD, lpData: [*]std.os.windows.BYTE, lpcbData: *std.os.windows.DWORD, ) callconv(std.os.windows.WINAPI) std.os.windows.LSTATUS; extern "advapi32" fn RegQueryValueExA( hKey: HKEY, lpValueName: std.os.windows.LPSTR, lpReserved: ?*std.os.windows.DWORD, lpType: ?*std.os.windows.DWORD, lpData: ?[*]std.os.windows.BYTE, lpcbData: ?*std.os.windows.DWORD, ) callconv(std.os.windows.WINAPI) std.os.windows.LSTATUS; extern "setupapi" fn SetupDiGetClassDevsW( classGuid: ?*const std.os.windows.GUID, enumerator: ?std.os.windows.PCWSTR, hwndParanet: ?HWND, flags: std.os.windows.DWORD, ) callconv(std.os.windows.WINAPI) HDEVINFO; extern "setupapi" fn SetupDiEnumDeviceInfo( devInfoSet: HDEVINFO, memberIndex: std.os.windows.DWORD, device_info_data: *SP_DEVINFO_DATA, ) callconv(std.os.windows.WINAPI) std.os.windows.BOOL; extern "setupapi" fn SetupDiDestroyDeviceInfoList(device_info_set: HDEVINFO) callconv(std.os.windows.WINAPI) std.os.windows.BOOL; extern "setupapi" fn SetupDiOpenDevRegKey( device_info_set: HDEVINFO, device_info_data: *SP_DEVINFO_DATA, scope: std.os.windows.DWORD, hwProfile: std.os.windows.DWORD, keyType: std.os.windows.DWORD, samDesired: std.os.windows.REGSAM, ) callconv(std.os.windows.WINAPI) HKEY; extern "setupapi" fn SetupDiGetDeviceRegistryPropertyA( hDevInfo: HDEVINFO, pSpDevInfoData: *SP_DEVINFO_DATA, property: std.os.windows.DWORD, propertyRegDataType: ?*std.os.windows.DWORD, propertyBuffer: ?[*]std.os.windows.BYTE, propertyBufferSize: std.os.windows.DWORD, requiredSize: ?*std.os.windows.DWORD, ) callconv(std.os.windows.WINAPI) std.os.windows.BOOL; extern "setupapi" fn SetupDiGetDeviceInstanceIdA( device_info_set: HDEVINFO, device_info_data: *SP_DEVINFO_DATA, deviceInstanceId: *?std.os.windows.CHAR, deviceInstanceIdSize: std.os.windows.DWORD, requiredSize: ?*std.os.windows.DWORD, ) callconv(std.os.windows.WINAPI) std.os.windows.BOOL; extern "cfgmgr32" fn CM_Get_Parent( pdnDevInst: *DEVINST, dnDevInst: DEVINST, ulFlags: std.os.windows.ULONG, ) callconv(std.os.windows.WINAPI) std.os.windows.DWORD; extern "cfgmgr32" fn CM_Get_Device_IDA( dnDevInst: DEVINST, buffer: std.os.windows.LPSTR, bufferLen: std.os.windows.ULONG, ulFlags: std.os.windows.ULONG, ) callconv(std.os.windows.WINAPI) std.os.windows.DWORD; const LinuxPortIterator = struct { const Self = @This(); const root_dir = "/sys/class/tty"; // ls -hal /sys/class/tty/*/device/driver dir: std.fs.Dir, iterator: std.fs.Dir.Iterator, full_path_buffer: [std.fs.max_path_bytes]u8 = undefined, driver_path_buffer: [std.fs.max_path_bytes]u8 = undefined, pub fn init() !Self { var dir = try std.fs.cwd().openDir(root_dir, .{ .iterate = true }); errdefer dir.close(); return Self{ .dir = dir, .iterator = dir.iterate(), }; } pub fn deinit(self: *Self) void { self.dir.close(); self.* = undefined; } pub fn next(self: *Self) !?SerialPortDescription { while (true) { if (try self.iterator.next()) |entry| { // not a dir => we don't care var tty_dir = self.dir.openDir(entry.name, .{}) catch continue; defer tty_dir.close(); // we need the device dir // no device dir => virtual device var device_dir = tty_dir.openDir("device", .{}) catch continue; defer device_dir.close(); // We need the symlink for "driver" const link = device_dir.readLink("driver", &self.driver_path_buffer) catch continue; // full_path_buffer // driver_path_buffer var fba = std.heap.FixedBufferAllocator.init(&self.full_path_buffer); const path = try std.fs.path.join(fba.allocator(), &.{ "/dev/", entry.name, }); return SerialPortDescription{ .file_name = path, .display_name = path, .driver = std.fs.path.basename(link), }; } else { return null; } } return null; } }; const DarwinPortIterator = struct { const Self = @This(); const root_dir = "/dev/"; dir: std.fs.Dir, iterator: std.fs.Dir.Iterator, full_path_buffer: [std.fs.max_path_bytes]u8 = undefined, driver_path_buffer: [std.fs.max_path_bytes]u8 = undefined, pub fn init() !Self { var dir = try std.fs.cwd().openDir(root_dir, .{ .iterate = true }); errdefer dir.close(); return Self{ .dir = dir, .iterator = dir.iterate(), }; } pub fn deinit(self: *Self) void { self.dir.close(); self.* = undefined; } pub fn next(self: *Self) !?SerialPortDescription { while (true) { if (try self.iterator.next()) |entry| { if (!std.mem.startsWith(u8, entry.name, "cu.")) { continue; } else { var fba = std.heap.FixedBufferAllocator.init(&self.full_path_buffer); const path = try std.fs.path.join(fba.allocator(), &.{ "/dev/", entry.name, }); return SerialPortDescription{ .file_name = path, .display_name = path, .driver = "darwin", }; } } else { return null; } } return null; } }; pub const Parity = enum { /// No parity bit is used none, /// Parity bit is `0` when an even number of bits is set in the data. even, /// Parity bit is `0` when an odd number of bits is set in the data. odd, /// Parity bit is always `1` mark, /// Parity bit is always `0` space, }; pub const StopBits = enum { /// The length of the stop bit is 1 bit one, /// The length of the stop bit is 2 bits two, }; pub const Handshake = enum { /// No handshake is used none, /// XON-XOFF software handshake is used. software, /// Hardware handshake with RTS/CTS is used. hardware, }; pub const WordSize = enum { five, six, seven, eight, }; pub const SerialConfig = struct { /// Symbol rate in bits/second. Not that these /// include also parity and stop bits. baud_rate: u32, /// Parity to verify transport integrity. parity: Parity = .none, /// Number of stop bits after the data stop_bits: StopBits = .one, /// Number of data bits per word. /// Allowed values are 5, 6, 7, 8 word_size: WordSize = .eight, /// Defines the handshake protocol used. handshake: Handshake = .none, }; const CBAUD = 0o000000010017; //Baud speed mask (not in POSIX). const CMSPAR = 0o010000000000; const CRTSCTS = 0o020000000000; const VTIME = 5; const VMIN = 6; const VSTART = 8; const VSTOP = 9; /// This function configures a serial port with the given config. /// `port` is an already opened serial port, on windows these /// are either called `\\.\COMxx\` or `COMx`, on unixes the serial /// port is called `/dev/ttyXXX`. pub fn configureSerialPort(port: std.fs.File, config: SerialConfig) !void { switch (builtin.os.tag) { .windows => { var dcb = std.mem.zeroes(DCB); dcb.DCBlength = @sizeOf(DCB); if (GetCommState(port.handle, &dcb) == 0) return error.WindowsError; // std.log.err("{s} {s}", .{ dcb, flags }); dcb.BaudRate = config.baud_rate; dcb.flags = @bitCast(DCBFlags{ .fParity = config.parity != .none, .fOutxCtsFlow = config.handshake == .hardware, .fOutX = config.handshake == .software, .fInX = config.handshake == .software, .fRtsControl = @as(u2, if (config.handshake == .hardware) 1 else 0), }); dcb.wReserved = 0; dcb.ByteSize = switch (config.word_size) { .five => @as(u8, 5), .six => @as(u8, 6), .seven => @as(u8, 7), .eight => @as(u8, 8), }; dcb.Parity = switch (config.parity) { .none => @as(u8, 0), .even => @as(u8, 2), .odd => @as(u8, 1), .mark => @as(u8, 3), .space => @as(u8, 4), }; dcb.StopBits = switch (config.stop_bits) { .one => @as(u2, 0), .two => @as(u2, 2), }; dcb.XonChar = 0x11; dcb.XoffChar = 0x13; dcb.wReserved1 = 0; if (SetCommState(port.handle, &dcb) == 0) return error.WindowsError; }, .linux, .macos => |tag| { var settings = try std.posix.tcgetattr(port.handle); const baudmask = switch (tag) { .macos => try mapBaudToMacOSEnum(config.baud_rate), .linux => try mapBaudToLinuxEnum(config.baud_rate), else => unreachable, }; // initialize CFLAG with the baudrate bits var strct_cflag: std.os.linux.tc_cflag_t = @bitCast(@intFromEnum(baudmask)); strct_cflag.CREAD = true; // 0x80 settings.iflag = .{}; settings.oflag = .{}; settings.cflag = strct_cflag; settings.lflag = .{}; settings.ispeed = .B0; settings.ospeed = .B0; switch (config.parity) { .none => {}, .odd => settings.cflag.PARODD = true, .even => {}, // even parity is default when parity is enabled .mark => { settings.cflag.PARODD = true; // settings.cflag.CMSPAR = true; settings.cflag._ |= (1 << 14); }, .space => settings.cflag._ |= 1, } if (config.parity != .none) { settings.iflag.INPCK = true; // enable parity checking settings.cflag.PARENB = true; // enable parity generation } switch (config.handshake) { .none => settings.cflag.CLOCAL = true, .software => { settings.iflag.IXON = true; settings.iflag.IXOFF = true; }, // .hardware => settings.cflag.CRTSCTS = true, .hardware => settings.cflag._ |= 1 << 15, } switch (config.stop_bits) { .one => {}, .two => settings.cflag.CSTOPB = true, } switch (config.word_size) { .five => settings.cflag.CSIZE = .CS5, .six => settings.cflag.CSIZE = .CS6, .seven => settings.cflag.CSIZE = .CS7, .eight => settings.cflag.CSIZE = .CS8, } settings.ispeed = baudmask; settings.ospeed = baudmask; settings.cc[VMIN] = 1; settings.cc[VSTOP] = 0x13; // XOFF settings.cc[VSTART] = 0x11; // XON settings.cc[VTIME] = 0; try std.posix.tcsetattr(port.handle, .NOW, settings); }, else => @compileError("unsupported OS, please implement!"), } } /// Flushes the serial port `port`. If `input` is set, all pending data in /// the receive buffer is flushed, if `output` is set all pending data in /// the send buffer is flushed. pub fn flushSerialPort(port: std.fs.File, input: bool, output: bool) !void { if (!input and !output) return; switch (builtin.os.tag) { .windows => { const success = if (input and output) PurgeComm(port.handle, PURGE_TXCLEAR | PURGE_RXCLEAR) else if (input) PurgeComm(port.handle, PURGE_RXCLEAR) else if (output) PurgeComm(port.handle, PURGE_TXCLEAR) else @as(std.os.windows.BOOL, 0); if (success == 0) return error.FlushError; }, .linux => if (input and output) try tcflush(port.handle, TCIOFLUSH) else if (input) try tcflush(port.handle, TCIFLUSH) else if (output) try tcflush(port.handle, TCOFLUSH), .macos => if (input and output) try tcflush(port.handle, c.TCIOFLUSH) else if (input) try tcflush(port.handle, c.TCIFLUSH) else if (output) try tcflush(port.handle, c.TCOFLUSH), else => @compileError("unsupported OS, please implement!"), } } pub const ControlPins = struct { rts: ?bool = null, dtr: ?bool = null, }; pub fn changeControlPins(port: std.fs.File, pins: ControlPins) !void { switch (builtin.os.tag) { .windows => { const CLRDTR = 6; const CLRRTS = 4; const SETDTR = 5; const SETRTS = 3; if (pins.dtr) |dtr| { if (EscapeCommFunction(port.handle, if (dtr) SETDTR else CLRDTR) == 0) return error.WindowsError; } if (pins.rts) |rts| { if (EscapeCommFunction(port.handle, if (rts) SETRTS else CLRRTS) == 0) return error.WindowsError; } }, .linux => { const TIOCM_RTS: c_int = 0x004; const TIOCM_DTR: c_int = 0x002; // from /usr/include/asm-generic/ioctls.h // const TIOCMBIS: u32 = 0x5416; // const TIOCMBIC: u32 = 0x5417; const TIOCMGET: u32 = 0x5415; const TIOCMSET: u32 = 0x5418; var flags: c_int = 0; if (std.os.linux.ioctl(port.handle, TIOCMGET, @intFromPtr(&flags)) != 0) return error.Unexpected; if (pins.dtr) |dtr| { if (dtr) { flags |= TIOCM_DTR; } else { flags &= ~TIOCM_DTR; } } if (pins.rts) |rts| { if (rts) { flags |= TIOCM_RTS; } else { flags &= ~TIOCM_RTS; } } if (std.os.linux.ioctl(port.handle, TIOCMSET, @intFromPtr(&flags)) != 0) return error.Unexpected; }, .macos => {}, else => @compileError("changeControlPins not implemented for " ++ @tagName(builtin.os.tag)), } } const PURGE_RXABORT = 0x0002; const PURGE_RXCLEAR = 0x0008; const PURGE_TXABORT = 0x0001; const PURGE_TXCLEAR = 0x0004; extern "kernel32" fn PurgeComm(hFile: std.os.windows.HANDLE, dwFlags: std.os.windows.DWORD) callconv(std.os.windows.WINAPI) std.os.windows.BOOL; extern "kernel32" fn EscapeCommFunction(hFile: std.os.windows.HANDLE, dwFunc: std.os.windows.DWORD) callconv(std.os.windows.WINAPI) std.os.windows.BOOL; const TCIFLUSH = 0; const TCOFLUSH = 1; const TCIOFLUSH = 2; const TCFLSH = 0x540B; fn tcflush(fd: std.os.linux.fd_t, mode: usize) !void { switch (builtin.os.tag) { .linux => { if (std.os.linux.syscall3(.ioctl, @as(usize, @bitCast(@as(isize, fd))), TCFLSH, mode) != 0) return error.FlushError; }, .macos => { const err = c.tcflush(fd, @as(c_int, @intCast(mode))); if (err != 0) { std.debug.print("tcflush failed: {d}\r\n", .{err}); return error.FlushError; } }, else => @compileError("unsupported OS, please implement!"), } } fn mapBaudToLinuxEnum(baudrate: usize) !std.os.linux.speed_t { return switch (baudrate) { // from termios.h 50 => .B50, 75 => .B75, 110 => .B110, 134 => .B134, 150 => .B150, 200 => .B200, 300 => .B300, 600 => .B600, 1200 => .B1200, 1800 => .B1800, 2400 => .B2400, 4800 => .B4800, 9600 => .B9600, 19200 => .B19200, 38400 => .B38400, // from termios-baud.h 57600 => .B57600, 115200 => .B115200, 230400 => .B230400, 460800 => .B460800, 500000 => .B500000, 576000 => .B576000, 921600 => .B921600, 1000000 => .B1000000, 1152000 => .B1152000, 1500000 => .B1500000, 2000000 => .B2000000, 2500000 => .B2500000, 3000000 => .B3000000, 3500000 => .B3500000, 4000000 => .B4000000, else => error.UnsupportedBaudRate, }; } fn mapBaudToMacOSEnum(baudrate: usize) !std.os.darwin.speed_t { return switch (baudrate) { // from termios.h 50 => .B50, 75 => .B75, 110 => .B110, 134 => .B134, 150 => .B150, 200 => .B200, 300 => .B300, 600 => .B600, 1200 => .B1200, 1800 => .B1800, 2400 => .B2400, 4800 => .B4800, 9600 => .B9600, 19200 => .B19200, 38400 => .B38400, 7200 => .B7200, 14400 => .B14400, 28800 => .B28800, 57600 => .B57600, 76800 => .B76800, 115200 => .B115200, 230400 => .B230400, else => error.UnsupportedBaudRate, }; } const DCBFlags = packed struct(u32) { fBinary: bool = true, // u1 fParity: bool = false, // u1 fOutxCtsFlow: bool = false, // u1 fOutxDsrFlow: bool = false, // u1 fDtrControl: u2 = 1, // u2 fDsrSensitivity: bool = false, // u1 fTXContinueOnXoff: bool = false, // u1 fOutX: bool = false, // u1 fInX: bool = false, // u1 fErrorChar: bool = false, // u1 fNull: bool = false, // u1 fRtsControl: u2 = 0, // u2 fAbortOnError: bool = false, // u1 fDummy2: u17 = 0, // u17 }; /// Configuration for the serial port /// /// Details: https://learn.microsoft.com/es-es/windows/win32/api/winbase/ns-winbase-dcb const DCB = extern struct { DCBlength: std.os.windows.DWORD, BaudRate: std.os.windows.DWORD, flags: u32, wReserved: std.os.windows.WORD, XonLim: std.os.windows.WORD, XoffLim: std.os.windows.WORD, ByteSize: std.os.windows.BYTE, Parity: std.os.windows.BYTE, StopBits: std.os.windows.BYTE, XonChar: u8, XoffChar: u8, ErrorChar: u8, EofChar: u8, EvtChar: u8, wReserved1: std.os.windows.WORD, }; extern "kernel32" fn GetCommState(hFile: std.os.windows.HANDLE, lpDCB: *DCB) callconv(std.os.windows.WINAPI) std.os.windows.BOOL; extern "kernel32" fn SetCommState(hFile: std.os.windows.HANDLE, lpDCB: *DCB) callconv(std.os.windows.WINAPI) std.os.windows.BOOL; test "iterate ports" { var it = try list(); while (try it.next()) |port| { _ = port; // std.debug.print("{s} (file: {s}, driver: {s})\n", .{ port.display_name, port.file_name, port.driver }); } } test "basic configuration test" { const cfg = SerialConfig{ .handshake = .none, .baud_rate = 115200, .parity = .none, .word_size = .eight, .stop_bits = .one, }; var tty: []const u8 = undefined; switch (builtin.os.tag) { .windows => tty = "\\\\.\\COM3", .linux => tty = "/dev/ttyUSB0", .macos => tty = "/dev/cu.usbmodem101", else => unreachable, } var port = try std.fs.cwd().openFile(tty, .{ .mode = .read_write }); defer port.close(); try configureSerialPort(port, cfg); } test "basic flush test" { var tty: []const u8 = undefined; // if any, these will likely exist on a machine switch (builtin.os.tag) { .windows => tty = "\\\\.\\COM3", .linux => tty = "/dev/ttyUSB0", .macos => tty = "/dev/cu.usbmodem101", else => unreachable, } var port = try std.fs.cwd().openFile(tty, .{ .mode = .read_write }); defer port.close(); try flushSerialPort(port, true, true); try flushSerialPort(port, true, false); try flushSerialPort(port, false, true); try flushSerialPort(port, false, false); } test "change control pins" { _ = changeControlPins; }
0
repos/zig-serial
repos/zig-serial/examples/echo.zig
const std = @import("std"); const zig_serial = @import("serial"); pub fn main() !u8 { const port_name = if (@import("builtin").os.tag == .windows) "\\\\.\\COM1" else "/dev/ttyUSB0"; var serial = std.fs.cwd().openFile(port_name, .{ .mode = .read_write }) catch |err| switch (err) { error.FileNotFound => { std.debug.print("Invalid config: the serial port '{s}' does not exist.\n", .{port_name}); return 1; }, else => return err, }; defer serial.close(); try zig_serial.configureSerialPort(serial, zig_serial.SerialConfig{ .baud_rate = 115200, .word_size = .eight, .parity = .none, .stop_bits = .one, .handshake = .none, }); try serial.writer().writeAll("Hello, World!\r\n"); while (true) { const b = try serial.reader().readByte(); try serial.writer().writeByte(b); } return 0; }
0
repos/zig-serial
repos/zig-serial/examples/list_port_info.zig
const std = @import("std"); const zig_serial = @import("serial"); pub fn main() !u8 { var iterator = try zig_serial.list_info(); defer iterator.deinit(); while (try iterator.next()) |info| { std.debug.print("\nPort name: {s}\n", .{info.port_name}); std.debug.print(" - System location: {s}\n", .{info.system_location}); std.debug.print(" - Friendly name: {s}\n", .{info.friendly_name}); std.debug.print(" - Description: {s}\n", .{info.description}); std.debug.print(" - Manufacturer: {s}\n", .{info.manufacturer}); std.debug.print(" - Serial #: {s}\n", .{info.serial_number}); std.debug.print(" - HW ID: {s}\n", .{info.hw_id}); std.debug.print(" - VID: 0x{X:0>4} PID: 0x{X:0>4}\n", .{ info.vid, info.pid }); } return 0; }
0
repos/zig-serial
repos/zig-serial/examples/list.zig
const std = @import("std"); const zig_serial = @import("serial"); pub fn main() !u8 { var iterator = try zig_serial.list(); defer iterator.deinit(); while (try iterator.next()) |port| { std.debug.print("path={s},\tname={s},\tdriver={s}\n", .{ port.file_name, port.display_name, port.driver orelse "<no driver recognized>" }); } return 0; }
0
repos
repos/exploratory-tech-studio/README.md
# Exploratory Tech Studio ## About the project This project is an interdisciplinary repository for collaborative projects spanning various fields, such as hardware (e.g., Arduino UNO), financial engineering, machine learning, natural language processing, and smaller tools, as well as design patterns, algorithms, and much more. This repository serves as a platform for sharing and developing projects that integrate principles from these diverse disciplines, fostering innovation and collaboration at the intersection of technology and science. ## Content overview * [tech-studio-projects](/tech-studio-projects/) * [algorithms](/tech-studio-projects/algorithms/) * [cryptography](/tech-studio-projects/algorithms/cryptography/) - rsa-encryption, sha256-hashing * [divide-and-conquer](/tech-studio-projects/algorithms/divide-and-conquer/) - lowest-common-ancestor * [dynamic-programming](/tech-studio-projects/algorithms/dynamic-programming/) - knapsack-problem, depth-first-search-for-a-graph, shortest-path-problem-with-dijkstra * [graph](/tech-studio-projects/algorithms/graph/) - breadth-first-search, * [linear-algebra](/tech-studio-projects/algorithms/linear-algebra/) - gaussian-elimination, jacobi-iteration, least-squares-method * [eigenvalue-algorithms](/tech-studio-projects/algorithms/linear-algebra/eigenvalue-algorithms/) - lanczos-algorithm, power-iteration, qr-algorithm * [machine-learning](/tech-studio-projects/algorithms/machine-learning/) - linear-regression * [numerical-optimization-algorithms](/tech-studio-projects/algorithms/numerical-optimization-algorithms/) - classical-genetic-algorithms, conjugate-gradient, gradient-descent, simulated-annealing * [root-finding-optimization](/tech-studio-projects/algorithms/root-finding-optimization/) - lanczos-algorithm, power-iteration, qr-algorithm * [searching](/tech-studio-projects/algorithms/searching/) - binary-search, boyer-moore, informed-search, knutt-morris-pratt, linear-search, rabin-karp, uninformed-search * [sorting](/tech-studio-projects/algorithms/sorting/) - classical sorting algorithms * [statistical-analysis](/tech-studio-projects/algorithms/statistical-analysis/) - bayesian-inference, least-squares-fitting, maximum-likelihood-estimation, monte-carlo * [trees](/tech-studio-projects/algorithms/trees/) - avl, binary-search-tree, fenwick-tree, kd-tree, minimum-spanning-tree-with-kruskal, nearset-neighbour-with-kd-tree, breadth-first-search, prefix-tree, radix-tree, segment-tree, splay-tree, suffix-tree, tree-map * [arduino-uno](/tech-studio-projects/arduino-uno/) - projects realized with the arduino uno board * [analog-to-voltage-monitor](/tech-studio-projects/arduino-uno/analog-to-voltage-monitor/) - reads an analog voltage from pin A0, converts it to a voltage value * [cw-to-hp](/tech-studio-projects/arduino-uno/cw-to-hp/) - convert kilowatt to horsepower * [digital-clock](/tech-studio-projects/arduino-uno/digital-clock/) - a digital clock showing seconds, minuites and hours * [frequency-measurement](/tech-studio-projects/arduino-uno/frequency-measurement/) - measure frequency in Hz and KHz * [measure-temperature-and-humidity](/tech-studio-projects/arduino-uno/measure-temperature-and-humidity/) - measure temperature and humidity * [traffic-light-system](/tech-studio-projects/arduino-uno/traffic-light-system/) - fully working traffic light system * [command-line-tools](/tech-studio-projects/command-line-tools/) * [directory-tree-generator](/tech-studio-projects/command-line-tools/directory-tree-generator/) * [license-file-creator](/tech-studio-projects/command-line-tools/license-file-creator/) * [data-structures](/tech-studio-projects/data-structures/) * [disjoint-set](/tech-studio-projects/data-structures/disjoint-set/) * [double-linked-list](/tech-studio-projects/data-structures/double-linked-list/) * [dynamic-array](/tech-studio-projects/data-structures/dynamic-array/) * [hash-map](/tech-studio-projects/data-structures/hash-map/) * [heap](/tech-studio-projects/data-structures/heap/) * [lock-free-linked-list](/tech-studio-projects/data-structures/lock-free-linked-list/) * [object-oriented-programming](/tech-studio-projects/data-structures/object-oriented-programming/) * [single_linked-list](/tech-studio-projects/data-structures/single_linked-list/) * [skip-list](/tech-studio-projects/data-structures/skip-list/) * [suffix-array](/tech-studio-projects/data-structures/suffix-array/) * [user-defined-data-structures-in-python](/tech-studio-projects/data-structures/suffix-array/) * [design-patterns](/tech-studio-projects/design-patterns/) * [abstract-factory-pattern](/tech-studio-projects/design-patterns/abstract-factory-pattern/) * [adapter-pattern](/tech-studio-projects/design-patterns/adapter-pattern/) * [builder-pattern](/tech-studio-projects/design-patterns/builder-pattern/) * [command-pattern](/tech-studio-projects/design-patterns/command-pattern/) * [composite-pattern](/tech-studio-projects/design-patterns/composite-pattern/) * [decorator-pattern](/tech-studio-projects/design-patterns/decorator-pattern/) * [factory-method-pattern](/tech-studio-projects/design-patterns/factory-method-pattern/) * [flyweight-pattern](/tech-studio-projects/design-patterns/flyweight-pattern/) * [oberserver-pattern](/tech-studio-projects/design-patterns/oberserver-pattern/) * [prototype-pattern](/tech-studio-projects/design-patterns/prototype-pattern/) * [proxy-pattern](/tech-studio-projects/design-patterns/proxy-pattern/) * [singleton-pattern](/tech-studio-projects/design-patterns/singleton-pattern/) * [strategy-pattern](/tech-studio-projects/design-patterns/strategy-pattern/) * [template-method-pattern](/tech-studio-projects/design-patterns/template-method-pattern/) * [financial-industry](/tech-studio-projects/financial-industry//) * [quantitative-trading](/tech-studio-projects/financial-industry/quantitative-trading/) * [execution-system](/tech-studio-projects/financial-industry/quantitative-trading/execution-system/) * [market-sentiment-analysis](/tech-studio-projects/financial-industry/quantitative-trading/market-sentiment-analysis/) * [portfolio-optimization-tool](/tech-studio-projects/financial-industry/quantitative-trading/portfolio-optimization-tool/) * [stock-price-analysis-dashboard](/tech-studio-projects/financial-industry/quantitative-trading/stock-price-analysis-dashboard/) * [trading-strategies](/tech-studio-projects/financial-industry/quantitative-trading/trading-strategies/) * [regulatory-reporting](/tech-studio-projects/financial-industry/regulatory-reporting/) * [us-gaap](/tech-studio-projects/financial-industry/regulatory-reporting/us-gaap/) * [machine-learning](/tech-studio-projects/machine-learning/) * [detecting-credit-card-fraud](/tech-studio-projects/machine-learning/detecting-credit-card-fraud/) * [image-classification](/tech-studio-projects/machine-learning/image-classification/) * [image-creation](/tech-studio-projects/machine-learning/image-creation/) * [movie-recommendation-system](/tech-studio-projects/machine-learning/movie-recommendation-system/) * [natural-language-processing](/tech-studio-projects/natural-language-processing/) * [prompt-engineering-experiments](/tech-studio-projects/prompt-engineering-experiments/) * [web-applications](/tech-studio-projects/web-applications/) * [diy-store](/tech-studio-projects/web-applications/diy-store/) * [github-user-finder](/tech-studio-projects/web-applications/github-user-finder/) * [guestbook](/tech-studio-projects/web-applications/guestbook/) * [text-analyzation](/tech-studio-projects/web-applications/text-analyzation/) * [travel-agency](/tech-studio-projects/web-applications/travel-agency/) * [weather-prediction-app](/tech-studio-projects/web-applications/weather-prediction-app/) * [.gitignore](/.gitignore) - list of files not tracked by github * [COPYRIGHT](/COPYRIGHT) - project copyright * [LICENSE](/LICENSE) - project license * [README.md](/README.md) - project information ---- ## Getting started To get started with the projects, please explore the folders in the [Content overview](#content-overview) section. ## Resources used to create this project * C Programming Language * [JTC1/SC22/WG14 - C](https://www.open-std.org/jtc1/sc22/wg14/) * [C - Approved standards](https://www.open-std.org/JTC1/SC22/WG14/www/standards) * C++ * [C++ reference](https://en.cppreference.com/w/) * [C++ Programming Language](https://devdocs.io/cpp/) * Python * [Python 3.12 documentation](https://docs.python.org/3/) * [Built-in Functions](https://docs.python.org/3/library/functions.html) * [Python Module Index](https://docs.python.org/3/py-modindex.html) * Java * [Java Platform Standard Edition 22 Documentation](https://docs.oracle.com/en/java/javase/) * Zig * [ZIG](https://ziglang.org/) * Frameworks * [Apache Spark - A Unified engine for large-scale data analytics](https://spark.apache.org/docs/latest/) * [Apache Hadoop](https://hadoop.apache.org/docs/stable/) * CI/CD * [Jenkins](https://www.jenkins.io/doc/book/) * Editors * [Arduino IDE](https://docs.arduino.cc/software/ide/) * [IntelliJ IDEA Community Edition](https://www.jetbrains.com/idea/download/?section=windows) * [PyCharm Community Edition](https://www.jetbrains.com/pycharm/download/?section=windows) * [spyder](https://www.spyder-ide.org/) * [Visual Studio Code](https://code.visualstudio.com/) * Hardware * [Arduino UNO R3](https://docs.arduino.cc/hardware/uno-rev3/) * Markdwon * [Basic syntax](https://www.markdownguide.org/basic-syntax/) * [Complete list of github markdown emofis](https://dev.to/nikolab/complete-list-of-github-markdown-emoji-markup-5aia) * [Awesome template](http://github.com/Human-Activity-Recognition/blob/main/README.md) * [.gitignore file](https://git-scm.com/docs/gitignore) ## License This project is licensed under the terms of the [MIT License](LICENSE). ## Copyright See the [COPYRIGHT](COPYRIGHT) file for copyright and licensing details.
0
repos/exploratory-tech-studio/tech-studio-projects/command-line-tools
repos/exploratory-tech-studio/tech-studio-projects/command-line-tools/directory-tree-generator/CMakeLists.txt
# CMakeList.txt : Top-level CMake project file, do global configuration # and include sub-projects here. # cmake_minimum_required (VERSION 3.8) # Enable Hot Reload for MSVC compilers if supported. if (POLICY CMP0141) cmake_policy(SET CMP0141 NEW) set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>") endif() project ("directory-tree-generator") # Include sub-projects. add_subdirectory ("directory-tree-generator")
0
repos/exploratory-tech-studio/tech-studio-projects/command-line-tools
repos/exploratory-tech-studio/tech-studio-projects/command-line-tools/directory-tree-generator/CMakePresets.json
{ "version": 3, "configurePresets": [ { "name": "windows-base", "hidden": true, "generator": "Ninja", "binaryDir": "${sourceDir}/out/build/${presetName}", "installDir": "${sourceDir}/out/install/${presetName}", "cacheVariables": { "CMAKE_C_COMPILER": "cl.exe", "CMAKE_CXX_COMPILER": "cl.exe" }, "condition": { "type": "equals", "lhs": "${hostSystemName}", "rhs": "Windows" } }, { "name": "x64-debug", "displayName": "x64 Debug", "inherits": "windows-base", "architecture": { "value": "x64", "strategy": "external" }, "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" } }, { "name": "x64-release", "displayName": "x64 Release", "inherits": "x64-debug", "cacheVariables": { "CMAKE_BUILD_TYPE": "Release" } }, { "name": "x86-debug", "displayName": "x86 Debug", "inherits": "windows-base", "architecture": { "value": "x86", "strategy": "external" }, "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" } }, { "name": "x86-release", "displayName": "x86 Release", "inherits": "x86-debug", "cacheVariables": { "CMAKE_BUILD_TYPE": "Release" } } ] }
0
repos/exploratory-tech-studio/tech-studio-projects/command-line-tools
repos/exploratory-tech-studio/tech-studio-projects/command-line-tools/directory-tree-generator/README.md
# Directory Tree Generator ## :newspaper: About the project A simple directory tree generator. > [!NOTE] > NOTE: This program code has been adapted, simplified and provided with references to datatypes and comments. The original code can be viewed [here](https://realpython.com/directory-tree-generator-python/). ### How it works A folder can be passed to the program, and by recursively iterating over the folder, a directory tree diagram will be displayed. ### Content overview . ├── directory-tree-generator/ - program logic of the directory tree generator ├── out/ - test directory for the program ├── .gitignore - list of files and folders ignored by git ├── CMakeLists.txt - cmake configuration file ├── CMakePresets.json - define presets for cmake projects ├── COPYRIGHT - project copyright ├── LICENSE - license text └── README.md - contains project information ## :runner: Getting started 0. Clone the repository: ```sh git clone https://github.com/CH6832/directory-tree-generator.git ``` 1. Navigate into root folder ```sh cd directory-tree-generator ``` 2. Run the `main.cpp` ```sh py main.cpp test_folder ``` ## :books: Resources used to create this project * CPlusPlus * [C++ Programming Language](https://devdocs.io/cpp/) * [Standard C++ Library reference](https://cplusplus.com/reference/) * [C++ reference](https://en.cppreference.com/w/) * [CMake Documentation and Community](https://cmake.org/documentation/) * Editor * [Visual Studio Community Edition](https://code.visualstudio.com/) ## :bookmark: License This project is licensed under the terms of the [GLP v3 License](LICENSE). ## :copyright: Copyright See the [COPYRIGHT](COPYRIGHT) file for copyright and licensing details.
0
repos/exploratory-tech-studio/tech-studio-projects/command-line-tools/directory-tree-generator
repos/exploratory-tech-studio/tech-studio-projects/command-line-tools/directory-tree-generator/directory-tree-generator/cli.cpp
#include "cli.h" void CLI::main(int argc, char* argv[]) { CommandLineArguments args = parseCommandLineArguments(argc, argv); DirectoryTree tree(args.rootDir); tree.generate(); } CLI::CommandLineArguments CLI::parseCommandLineArguments(int argc, char* argv[]) { CommandLineArguments args; if (argc > 1) { args.rootDir = argv[1]; } else { // Default to the current working directory args.rootDir = std::filesystem::current_path().string(); } // Check if the root directory exists if (!std::filesystem::exists(args.rootDir)) { std::cerr << "Error: Root directory not found: " << args.rootDir << std::endl; // Handle the error (e.g., exit the program or provide a default directory) // For now, let's exit the program exit(EXIT_FAILURE); } return args; }
0
repos/exploratory-tech-studio/tech-studio-projects/command-line-tools/directory-tree-generator
repos/exploratory-tech-studio/tech-studio-projects/command-line-tools/directory-tree-generator/directory-tree-generator/dirtree.cpp
#include "dirtree.h" #include <iostream> DirectoryTree::DirectoryTree(const std::filesystem::path& rootDir) : _rootDir(rootDir) {} void DirectoryTree::generate() { _treeHead(); _treeBody(_rootDir); for (const auto& entry : _tree) { std::cout << entry << std::endl; } } void DirectoryTree::_treeHead() { _tree.push_back((_rootDir / std::filesystem::path{ std::string(1, std::filesystem::path::preferred_separator) }).string()); _tree.push_back(PIPE); } void DirectoryTree::_treeBody(const std::filesystem::path& directory, std::string prefix) { auto entries = std::vector<std::filesystem::path>{}; std::copy(std::filesystem::directory_iterator(directory), std::filesystem::directory_iterator(), std::back_inserter(entries)); std::sort(entries.begin(), entries.end()); auto entriesCount = entries.size(); for (auto index = 0; index < entriesCount; ++index) { auto connector = (index == entriesCount - 1) ? ELBOW : TEE; auto entry = entries[index]; if (std::filesystem::is_directory(entry)) { _addDirectory(entry, index, entriesCount, prefix, connector); } else { _addFile(entry, prefix, connector); } } } void DirectoryTree::_addDirectory(const std::filesystem::path& directory, int index, int entriesCount, std::string& prefix, const std::string& connector) { _tree.push_back(prefix + connector + " " + directory.filename().string() + std::string(1, std::filesystem::path::preferred_separator)); if (index != entriesCount - 1) { prefix += PIPE_PREFIX; } else { prefix += SPACE_PREFIX; } _treeBody(directory, prefix); _tree.push_back(prefix.erase(prefix.size() - PIPE_PREFIX.size())); } void DirectoryTree::_addFile(const std::filesystem::path& file, const std::string& prefix, const std::string& connector) { _tree.push_back(prefix + connector + " " + file.filename().string()); }
0
repos/exploratory-tech-studio/tech-studio-projects/command-line-tools/directory-tree-generator
repos/exploratory-tech-studio/tech-studio-projects/command-line-tools/directory-tree-generator/directory-tree-generator/dirtree.h
#ifndef DIRTREE_HPP #define DIRTREE_HPP #include <string> #include <filesystem> #include <vector> #include <algorithm> class DirectoryTree { public: DirectoryTree(const std::filesystem::path& rootDir); void generate(); private: std::filesystem::path _rootDir; std::vector<std::string> _tree; const std::string PIPE = "|"; const std::string ELBOW = "`--"; const std::string TEE = "|--"; const std::string PIPE_PREFIX = "| "; const std::string SPACE_PREFIX = " "; void _treeHead(); void _treeBody(const std::filesystem::path& directory, std::string prefix = ""); void _addDirectory(const std::filesystem::path& directory, int index, int entriesCount, std::string& prefix, const std::string& connector); void _addFile(const std::filesystem::path& file, const std::string& prefix, const std::string& connector); }; #endif // DIRTREE_HPP
0
repos/exploratory-tech-studio/tech-studio-projects/command-line-tools/directory-tree-generator
repos/exploratory-tech-studio/tech-studio-projects/command-line-tools/directory-tree-generator/directory-tree-generator/CMakeLists.txt
# CMakeList.txt : CMake project for directory-tree-generator, include source and define # project specific logic here. # # Add source to this project's executable. add_executable (directory-tree-generator "dirtree.cpp" "dirtree.h" "main.cpp" "cli.h" "cli.cpp") if (CMAKE_VERSION VERSION_GREATER 3.12) set_property(TARGET directory-tree-generator PROPERTY CXX_STANDARD 20) endif() # TODO: Add tests and install targets if needed.
0
repos/exploratory-tech-studio/tech-studio-projects/command-line-tools/directory-tree-generator
repos/exploratory-tech-studio/tech-studio-projects/command-line-tools/directory-tree-generator/directory-tree-generator/main.cpp
#include "cli.h" int main(int argc, char* argv[]) { CLI::main(argc, argv); return 0; }
0
repos/exploratory-tech-studio/tech-studio-projects/command-line-tools/directory-tree-generator
repos/exploratory-tech-studio/tech-studio-projects/command-line-tools/directory-tree-generator/directory-tree-generator/cli.h
#ifndef CLI_HPP #define CLI_HPP #include <iostream> #include <string> #include <filesystem> #include "dirtree.h" class CLI { public: static void main(int argc, char* argv[]); private: struct CommandLineArguments { std::string rootDir = "./test_folder"; // std::string rootDir = std::filesystem::current_path().string(); }; static CommandLineArguments parseCommandLineArguments(int argc, char* argv[]); }; #endif // CLI_HPP
0
repos/exploratory-tech-studio/tech-studio-projects/command-line-tools
repos/exploratory-tech-studio/tech-studio-projects/command-line-tools/license-file-creator/Constants.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Constants.py """ # pylint settings (https://docs.pylint.org/) # pylint: disable=line-too-long, trailing-whitespace, multiple-statements, fixme, locally-disabled from typing import * class Constants: """ Class contains getter methods to retrieve all constants for the license approval composition. The costants are the necessary properties text for the tables in the DOCX file. """ def __init__(self): self.HEADER_TEXT: str = "" self.TITLE_MAIN_SECTION: str = "" self.SENDER_FORM: str = "" self.SUBMISSION_TEXT_PROPERTY: str = "" self.SUBMISSION_TEXT_NAME: str = "" self.SUBMISSION_TO: str = "" self.APPT_OR_REJ_TEXT: str = "" self.SUBM_DATE: str = "" self.DATE_APPR_TEXT: str = "" self.THIRD_PARTY_NAME_PROP: str = "" self.VERSION_YEAR_PROP: str = "" self.UPDATE_PROP: str = "" self.SOFTW_DESC_PROP: str = "" self.LINK_PROPERTY_PROP: str = "" self.LICENSE_PROP: str = "" self.LINK_LIC_PROP: str = "" self.PROD_PROP: str = "" self.TIME_VER_PROP: str = "" # header section def get_header_text(self) -> str: self.HEADER_TEXT = "INTERNAL USE ONLY" return self.HEADER_TEXT def get_title_main_section(self) -> str: self.TITLE_MAIN_SECTION = "THIRD PARTY SOFTWARE LICENSE APPROVAL FORM" return self.TITLE_MAIN_SECTION # meta info section def get_sender_form(self) -> str: self.SENDER_FORM = "From: Christoph Hartleb (Dev)" return self.SENDER_FORM def get_submission_text_property(self) -> str: self.SUBMISSION_TEXT_PROPERTY = "Submitted to Legal by:" return self.SUBMISSION_TEXT_PROPERTY def get_submission_text_name(self) -> str: self.SUBMISSION_TEXT_NAME = "Christoph Hartleb" return self.SUBMISSION_TEXT_NAME def get_submission_to(self) -> str: self.SUBMISSION_TO = "To: Lawyer" return self.SUBMISSION_TO def get_appt_or_rej_text(self) -> str: self.APPT_OR_REJ_TEXT = "Approved/Rejected by Lawyer:" return self.APPT_OR_REJ_TEXT def get_sub_date(self) -> str: self.SUBM_DATE = "Submission Date: " return self.SUBM_DATE def get_date_appr_text(self) -> str: self.DATE_APPR_TEXT = "Date Approved:" return self.DATE_APPR_TEXT def get_date_format(self) -> str: self.DATE_FORMAT = "YYYY-MM-DD" return self.DATE_FORMAT # main section def get_third_party_name_prop(self) -> str: self.THIRD_PARTY_NAME_PROP = "Name of third party software:" return self.THIRD_PARTY_NAME_PROP def get_version_year_prop(self) -> str: self.VERSION_YEAR_PROP = "Version number or year:" return self.VERSION_YEAR_PROP def get_update_prop(self) -> str: self.UPDATE_PROP = """Is this a version update of previously approved software? If Yes, reason for update?""" return self.UPDATE_PROP def get_softw_desc_prop(self) -> str: self.SOFTW_DESC_PROP = "General description of software:" return self.SOFTW_DESC_PROP def get_link_property_prop(self) -> str: self.LINK_PROPERTY_PROP = "Link to software homepage:" return self.LINK_PROPERTY_PROP def get_license_prop(self) -> str: self.LICENSE_PROP = "License type (e.g. MIT, BSD, GPL)" return self.LICENSE_PROP def get_link_lic_prop(self) -> str: self.LINK_LIC_PROP = "Link to website showing license:" return self.LINK_LIC_PROP def get_prod_prop(self) -> str: self.PROD_PROP = """Products that will introduce license?""" return self.PROD_PROP def get_affected_products(self) -> str: self.AFFECTED_PRODUCTS = """List of all products where the software is usesd """ return self.AFFECTED_PRODUCTS def get_time_ver_prop(self) -> str: self.TIME_VER_PROP = "Approximate time/version?" return self.TIME_VER_PROP
0
repos/exploratory-tech-studio/tech-studio-projects/command-line-tools
repos/exploratory-tech-studio/tech-studio-projects/command-line-tools/license-file-creator/README.md
# XBRL Taxonomy License File Creator ## :newspaper: About the project Craft your license file with ease using our sleek command-line tool! Simply generate a customizable template in seconds. Check out our sample in the `lics/` folder for inspiration. ### Content overview . ├── img/ - folder where all the images can be found for the application ├── lics/ - folder where the license files are generated into ├── Constants.py - contains all constants for the program ├── COPYRIGHT - project copyright ├── gen_lic_approval.py main program and code designing and generating the file ├── README.md - relevant information about the project ├── LICENSE - license text └── requirements.txt - requirements to run the project ## :runner: Getting started 0. Clone the project to a location of your choice: ```sh git clone https://github.com/CH6832/license-file-creator.git ``` 1. Install relevant requirements: ```sh pip3 install -r requirements.txt ``` 2. Run the script with parameters of you need to generate a license approval file: ```sh python3 gen_lic_approval.py -family='eba' -version="3.2" ``` 3. If the file has been generated: ```sh Document successfully generated! -------------------------------- Your generated file: filebasename 3.2 XBRL Taxonomy - Third Party Software License Approval Form YYYYMMDD.docx can be found at './YYYY-MM-DD/' ``` 4. The result can be found in the `lics/` folder and looks like this: ![License Approval file](img/output_image.png) ## :books: Resources used to create this project * Python * [Python 3.12 documentation](https://docs.python.org/3/) * [Built-in Functions](https://docs.python.org/3/library/functions.html) * [Python Module Index](https://docs.python.org/3/py-modindex.html) * Markdwon * [Basic syntax](https://www.markdownguide.org/basic-syntax/) * [Complete list of github markdown emofis](https://dev.to/nikolab/complete-list-of-github-markdown-emoji-markup-5aia) * [Awesome template](http://github.com/Human-Activity-Recognition/blob/main/README.md) * [.gitignore file](https://git-scm.com/docs/gitignore) * Editor * [PyCharm Community Edition](https://www.jetbrains.com/pycharm/) ## :bookmark: License This project is licensed under the terms of the [GPL v3](LICENSE). ## :copyright: Copyright See the [COPYRIGHT](COPYRIGHT) file for copyright and licensing details.
0
repos/exploratory-tech-studio/tech-studio-projects/command-line-tools
repos/exploratory-tech-studio/tech-studio-projects/command-line-tools/license-file-creator/gen_lic_approval.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """gen_lic_approval.py Compose the license approval file. The script composes a DOCX file that serves as the license approval for new and updated xbrl taxonomies. """ # pylint settings (https://docs.pylint.org/) # pylint: disable=line-too-long, trailing-whitespace, multiple-statements, fixme, locally-disabled import argparse import datetime import json from typing import Any from docx import Document from docx.enum.dml import MSO_THEME_COLOR_INDEX from docx.enum.text import WD_ALIGN_PARAGRAPH, WD_LINE_SPACING from docx.opc.constants import RELATIONSHIP_TYPE as RT from docx.oxml.shared import OxmlElement, qn from docx.parts.story import StoryPart from docx.shared import Inches, Pt, RGBColor from docx.styles.style import _ParagraphStyle from docx.table import _Cell from docx.text.run import Run from docx.text.paragraph import Paragraph from docx.text.parfmt import ParagraphFormat import os from typing import Tuple import xml.etree.ElementTree as ET from colorama import init import termcolor from Constants import Constants def add_hyperlink(paragraph: Paragraph, url: str, text: str) -> Run: """ Returns an embedded hyperlink in a text string. The source of this code is https://github.com/python-openxml/python-docx/issues/384. The code has been extended with underlining blue text color. Keyword arguments: paragraph -- paragraph where text is shown url -- website text -- text for embedded url """ part: StoryPart = paragraph.part # get access to document.xml.rels file and new relation id value relation_id: str = part.relate_to(url, RT.HYPERLINK, is_external=True) hyperlink: OxmlElement = OxmlElement('w:hyperlink') # create w:hyperlink tag and add new value hyperlink.set(qn('r:id'), str(relation_id)) hyperlink.set(qn('w:history'), '1') new_run: OxmlElement = OxmlElement('w:r') rPr: OxmlElement = OxmlElement('w:rPr') # create w:rPr element rStyle: OxmlElement = OxmlElement('w:rStyle') # does not add hyperlink style rStyle.set(qn('w:val'), 'Hyperlink') # join all the xml elements, add required text to the w:r element rPr.append(rStyle) new_run.append(rPr) new_run.text = text hyperlink.append(new_run) # create new run object and insert hyperlink r: Run = paragraph.add_run() r._r.append(hyperlink) # add the styling r.font.color.theme_color = MSO_THEME_COLOR_INDEX.HYPERLINK r.font.underline = True return r def get_approximate_version(path_to_artifact_database: str) -> str: """ Returns the latest major release version of legacy/server products as a string. The approximate version is the major release version of the legacy/server products. This version is hardcoded in the 'C:/Projects/installer/ArtifactDatabase.xml' file. Keyword arguments path_toartifact_database -- path to the 'ArtifactDatabase.xml' """ try: tree: ET.ElementTree = ET.parse(path_to_artifact_database) root: ET.Element = tree.getroot() for elem in root.iter(): if 'Version' in elem.tag: elem_attribute_map = elem.attrib.items() for elem_name, elem_value in elem_attribute_map: if elem_name == "MajorVersionYear": return elem_value except OSError as e: print("ERROR " + str(e.errno) + ": File 'C:/Projects/installer/ArtifactDatabase.xml' not found!") def get_all_templates() -> list: """Return a list with all template files plus the relative path""" all_templates: list = [] for root, directories, files in os.walk("..\\..\\templates", topdown=False): for name in files: all_templates.append(os.path.join(root, name)) return all_templates def iterate_over_license_section(json_file: str, elem_name: str) -> str: """ Return requested element out of 'license' map in template. The data are retrieved from selected template of get_all_templates(). Keyword arguments: json_file -- path to the json file elem_name -- name of the element to retrieve value """ with open(json_file, "r") as data_file: data: dict = json.load(data_file) if 'license' not in data: print(f"ERROR: Dict '{elem_name}' does not exist in template. Data are not available!") else: for key in data.items(): for i, x in enumerate(key): if i == 0 and x == "license": for property, value in data[x].items(): if elem_name not in data[x]: print(f"ERROR: Key '{elem_name}' does not exist in template!") exit() elif elem_name in data[x] and elem_name == property: return value def set_paragraph(header_table, row_num: int, cell_num: int, para_num: int) -> Paragraph: """Return a paragraph in a table cell Keyword arguments: header_table -- table of header secion row_num -- row in table cell_num -- cell in row para_num -- set paragraph in cell """ table_cell: _Cell = header_table.rows[row_num].cells[cell_num] para_table_cell: Paragraph = table_cell.paragraphs[para_num] return para_table_cell def set_pargraph_meta_section(doc_info_table, row_num: int, cell_num: int, para_num: int, format, text: str, alignment) -> _Cell: """ Return a pargraph for the meta inforation section. This section is the very top of the license approval document. Keyword arguments: doc_info_table -- table of header secion row_num -- row in table cell_num -- cell in row para_num -- set paragraph in cell """ cell: _Cell = doc_info_table.rows[row_num].cells[cell_num] cell_para: Paragraph = cell.paragraphs[para_num] cell_para_format: ParagraphFormat = cell_para.paragraph_format cell_para_format.line_spacing_rule = format cell_para.text = text cell_para.alignment = alignment return cell def set_title(doc: Document, format: ParagraphFormat, text: str, boldness: bool, font_size: int) -> Paragraph: """Return paragraph with main title contained. Keyword arguments: doc -- base class format -- set the format of the pargraph text -- text in pargraph boldness -- set boldness of text font_size -- set font size for the text """ title_main_obj: Paragraph = doc.add_paragraph() title_main_obj.paragraph_format.alignment = format run_main_title: Run = title_main_obj.add_run(text) run_main_title.bold = boldness run_main_title.font.size = Pt(font_size) return title_main_obj def set_meta_section_table_cell_width(doc_info_section, colum_num: int, inche_num: float) -> _Cell: """Returns width of a table cell in meta section. Keyword arguments: doc_info_section -- section with meta informatio column_int -- coumn number in table inche_num -- column width """ cell: _Cell all_cells_info_sec = doc_info_section.columns[colum_num].cells for cell in all_cells_info_sec: cell.width = Inches(inche_num) return cell def set_sep_line(doc: object, line: str, boldness: bool) -> _Cell: """ Returns the separation line. The line crosses the whole document vertically. Keyword arguments: doc -- document object line -- line in the document boldness -- set text bold """ separation_line: str = line sep_line_obj: _Cell = doc.add_paragraph().add_run(separation_line) sep_line_obj.bold = False return sep_line_obj def set_main_section_paragraph(main_table, row_num: int, cell_num: int, text: str) -> Paragraph: """Returns one paragraph for the main section""" para: Paragraph = main_table.rows[row_num].cells[cell_num] text = "" para.text = text return para def set_footer(footer, row_num: int, text: str, font_size: int) -> Paragraph: """Returns footer with text and styling""" footer_para: Paragraph = footer.paragraphs[row_num].add_run(text) footer_para.font.size = Pt(font_size) return footer_para def set_additional_comment(doc: Document, alignment, comment: str, font_size: int, rgb_color_red: int, rgb_color_yellow: int, rgb_color_green: int, italic_value: bool, bold_value: bool) -> Paragraph: """Returns footer with text and styling""" additional_comment_obj: Paragraph = doc.add_paragraph() additional_comment_obj.paragraph_format.alignment = alignment run_main_title: Run = additional_comment_obj.add_run(comment) run_main_title.font.size = Pt(font_size) run_main_title.font.color.rgb = RGBColor(rgb_color_red, rgb_color_yellow, rgb_color_green) run_main_title.italic = italic_value run_main_title.bold = bold_value return additional_comment_obj def compose_docx_file_name(taxonomy_family_name: str, ws_1: str, version, ws_2: str, general_clause: str, ws_3, ph_date: str, file_extension: str) -> str: """Compose final name for the license approval daocument taxonomy_family_name: name of the taxonomy family. E.g.: "EBA ws_1: whitespace version: version of the taxonomy """ composed_file_name: str = taxonomy_family_name + ws_1 + version + ws_2 + general_clause + ws_3 + ph_date + file_extension return composed_file_name def main() -> None: """entry point""" argp: argparse.ArgumentParser = argparse.ArgumentParser( description='Generate license approval file to submit it to David Gast.') argp.add_argument('-family', '--family', help='The taxonomy\'s family name. E.g. EBA, BBK, ...') argp.add_argument('-version', '--version', help='The taxonomy\'s version') args: argparse.Namespace = argp.parse_args() # Initialize class with names of cell description objConsts: Constants = Constants() # Initialize modules for colors init() # set version and family name taxonomy_family_name: str = args.family taxonomy_version: str = args.version # Retrieve template according to family name if taxonomy_family_name: template: str = "" for i in range(len(get_all_templates())): if taxonomy_family_name.lower() in get_all_templates()[i]: template = get_all_templates()[i] # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # <LICENSE APPROVAL DOCUMENT> # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # Customize whole document doc: Document = Document() section_style: _ParagraphStyle = doc.styles['Normal'] section_style.font.name = 'Calibri (Body)' section_style.font.size = Pt(12) # provide access to first section section = doc.sections[0] # ------------------------------------------------------------------------------------------------------------------ # header section: # ------------------------------------------------------------------------------------------------------------------ header: Any = section.header # table contains 1 row and 2 cells header_table = header.add_table(1, 2, Inches(12)) cell: _Cell for cell in header_table.columns[1].cells: cell.width = Inches(1) # left cell displays 'internal usage only' para_l_cell: Paragraph = set_paragraph(header_table, 0, 0, 0) run_l_cell: Run = para_l_cell.add_run(objConsts.get_header_text()) run_l_cell.font.size = Pt(11) # right cell displays logo para_r_cell: Paragraph = set_paragraph(header_table, 0, 1, 0) run_r_cell = para_r_cell.add_run() # run_r_cell.add_picture("img\\logo.png", width=1380000, height=520000) # set title 'THIRD PARTY SOFTWARE LICENSE APPROVAL FORM' set_title(doc, WD_ALIGN_PARAGRAPH.CENTER, objConsts.get_title_main_section(), True, 13) # ------------------------------------------------------------------------------------------------------------------ # meta info section about the document # ------------------------------------------------------------------------------------------------------------------ # create docx.document.Document object doc_info_section = doc.add_table(rows=3, cols=3) # 'From: Christoph Hartleb (Dev)' set_pargraph_meta_section(doc_info_section, 0, 0, 0, WD_LINE_SPACING.SINGLE, objConsts.get_sender_form(), WD_ALIGN_PARAGRAPH.LEFT) # 'Submitted to Legal by:' set_pargraph_meta_section(doc_info_section, 0, 1, 0, WD_LINE_SPACING.SINGLE, objConsts.get_submission_text_property(), WD_ALIGN_PARAGRAPH.RIGHT) # 'Christoph Hartleb' set_pargraph_meta_section(doc_info_section, 0, 2, 0, WD_LINE_SPACING.SINGLE, objConsts.get_submission_text_name(), WD_ALIGN_PARAGRAPH.LEFT) # 'To: David A. Gast' set_pargraph_meta_section(doc_info_section, 1, 0, 0, WD_LINE_SPACING.SINGLE, objConsts.get_submission_to(), WD_ALIGN_PARAGRAPH.LEFT) # 'Approved/Rejected by Legal:' set_pargraph_meta_section(doc_info_section, 1, 1, 0, WD_LINE_SPACING.SINGLE, objConsts.get_appt_or_rej_text(), WD_ALIGN_PARAGRAPH.RIGHT) # justify type in paragraph is left for each cell set_pargraph_meta_section(doc_info_section, 1, 2, 0, WD_LINE_SPACING.SINGLE, "", WD_ALIGN_PARAGRAPH.LEFT) # 'Submission Date:' # american date format set_pargraph_meta_section(doc_info_section, 2, 0, 0, WD_LINE_SPACING.SINGLE, objConsts.get_sub_date() + str(datetime.datetime.now().strftime("%Y-%m-%d")), WD_ALIGN_PARAGRAPH.LEFT) # 'DateApproved:' set_pargraph_meta_section(doc_info_section, 2, 1, 0, WD_LINE_SPACING.SINGLE, objConsts.get_date_appr_text(), WD_ALIGN_PARAGRAPH.RIGHT) # 'YYYY-MM-DD' -> ISO 8601 date format set_pargraph_meta_section(doc_info_section, 2, 2, 0, WD_LINE_SPACING.SINGLE, objConsts.get_date_format(), WD_ALIGN_PARAGRAPH.LEFT) set_meta_section_table_cell_width(doc_info_section, 0, 3.6) set_meta_section_table_cell_width(doc_info_section, 1, 3.0) set_meta_section_table_cell_width(doc_info_section, 2, 2.2) # separate header section and main section in document set_sep_line(doc, "________________________________________________________________________", False) # ------------------------------------------------------------------------------------------------------------------ # main section of the document (deals with meta information about the taxonomy) # ------------------------------------------------------------------------------------------------------------------ main_table = doc.add_table(rows=9, cols=2) set_main_section_paragraph(main_table, 0, 0, objConsts.get_third_party_name_prop()) # Name of third party software # ---------------------------- col_name_h: _Cell = main_table.rows[0].cells[1] col_name_h.text = "xbrl taxonomy" # iterate_over_license_section(template, "swname") # Version number or year # ----------------------- set_main_section_paragraph(main_table, 1, 0, objConsts.get_version_year_prop()) if taxonomy_family_name == "bdp": # two different versions for the taxonomies provided by the Bank of Portugal. # therefore script call : py -3.10 gen_lic_approval.py -family="bdp" -version="2.10.1 5.0.0" set_main_section_paragraph(main_table, 1, 1, taxonomy_version.split(" ")[0] + " bdp v" + taxonomy_version.split(" ")[1]) else: set_main_section_paragraph(main_table, 1, 1, taxonomy_version) # Is this a version update of # previously approved software? If # Yes, reason for update? # -------------------------------- set_main_section_paragraph(main_table, 2, 0, objConsts.get_update_prop()) update_version_values: list[str] = ["Yes", "No", "YES", "Yes, update of the ESMA ESEF Common Recommendation (CR) version"] if taxonomy_family_name == "dnb-dict": set_main_section_paragraph(main_table, 2, 1, update_version_values[1]) elif taxonomy_family_name == "us-gaap" or taxonomy_family_name == "ifrs" or taxonomy_family_name == "xbrlgl": set_main_section_paragraph(main_table, 2, 1, update_version_values[2]) elif taxonomy_family_name == "lei": set_main_section_paragraph(main_table, 2, 1, update_version_values[1]) else: set_main_section_paragraph(main_table, 2, 1, update_version_values[0]) # General description of software # ------------------------------- set_main_section_paragraph(main_table, 3, 0, objConsts.get_softw_desc_prop()) set_main_section_paragraph(main_table, 3, 1, "sw description") # iterate_over_license_section(template, "swdescription")) # Link to software homepage # ------------------------- set_main_section_paragraph(main_table, 4, 0, objConsts.get_link_property_prop()) homepage_hyperlink = set_paragraph(main_table, 4, 1, 0) if taxonomy_family_name == "us-gaap": add_hyperlink(homepage_hyperlink, "https://www.example.website.com", "SEC and US GAAP Taxonomies") elif taxonomy_family_name == "bbk": add_hyperlink(homepage_hyperlink, "https://www.landinpage.example.com", "Reporting - Formats(XML and XBRL)") elif taxonomy_family_name == "boe-banking": add_hyperlink(homepage_hyperlink, "https://www.landinpage.example.com", "Regulatory Reporting for the Banking Sector") elif taxonomy_family_name == "cipc": add_hyperlink(homepage_hyperlink, "https://www.landinpage.example.com", "XBRL Programs") elif taxonomy_family_name == "dnb-ftk": add_hyperlink(homepage_hyperlink, "https://www.landinpage.example.com", "Pensionsfondsen") elif taxonomy_family_name == "eiopa": add_hyperlink(homepage_hyperlink, "https://www.landinpage.example.com", "EIOPA - Tools and Data") elif taxonomy_family_name == "sfrdp": add_hyperlink(homepage_hyperlink, "https://www.example.website.com", "https://www.example.website.com") elif taxonomy_family_name == "acpr-corep" or taxonomy_family_name == "acpr-creditimmo" or taxonomy_family_name == "acpr-lcbft": add_hyperlink(homepage_hyperlink, "https://www.example.website.com", "https://www.example.website.com") else: add_hyperlink(homepage_hyperlink, "https://www.landinpage.example.com", "https://www.landinpage.example.com") # License type (e.g. MIT, BSD, GPL) # --------------------------------- set_main_section_paragraph(main_table, 5, 0, objConsts.get_license_prop()) str_prep_lic_type = "license type" if taxonomy_family_name == "dnb-biscbs" or taxonomy_family_name == "dnb-dict" or taxonomy_family_name == "dnb-ftk": lic_type_hyperlink = set_paragraph(main_table, 5, 1, 0) add_hyperlink(lic_type_hyperlink, "license type", "CC-BY-4.0") else: set_main_section_paragraph(main_table, 5, 1, str_prep_lic_type) # Link to website showing license: # -------------------------------- set_main_section_paragraph(main_table, 6, 0, objConsts.get_link_lic_prop()) licweb_hyperlink = set_paragraph(main_table, 6, 1, 0) if taxonomy_family_name == "us-gaap": add_hyperlink(licweb_hyperlink, "webpage of license", "Terms and Conditions") elif taxonomy_family_name == "bdp": add_hyperlink(licweb_hyperlink, "webpage of license", "Disclaimer and Copyright") elif taxonomy_family_name == "eiopa": add_hyperlink(licweb_hyperlink, "webpage of license", "EIOPA DPM and Taxonomy License") elif taxonomy_family_name == "acpr-corep" or taxonomy_family_name == "acpr-creditimmo" or taxonomy_family_name == "acpr-lcbft" or taxonomy_family_name == "bbk": set_main_section_paragraph(main_table, 6, 1, "webpage of license") else: add_hyperlink(licweb_hyperlink, "webpage of license", "webpage of license") if taxonomy_family_name == "boe-statistics" or taxonomy_family_name == "boe-banking" or taxonomy_family_name == "boe-insurance": add_hyperlink(licweb_hyperlink, iterate_over_license_section(template, "licweb1"), iterate_over_license_section(template, "licweb1")) # Products that will introduce license? # -------------------------------------------- set_main_section_paragraph(main_table, 7, 0, objConsts.get_prod_prop()) set_main_section_paragraph(main_table, 7, 1, objConsts.get_affected_products()) # Approximate time/version? # ------------------------- set_main_section_paragraph(main_table, 8, 0, objConsts.get_time_ver_prop()) set_main_section_paragraph(main_table, 8, 1, (get_approximate_version('C:/Projects/installer/ArtifactDatabase.xml'))) # ADDITIONAL COMMENTS # ------------------------------------------------------------------------------------------------------------------ doc.add_paragraph().add_run("\nADDITIONAL COMMENTS:") if taxonomy_family_name == "dnb-biscbs" or taxonomy_family_name == "us gaap" or taxonomy_family_name == "boe-banking" or taxonomy_family_name == "cmf-cl-ci" or taxonomy_family_name == "eiopa" or taxonomy_family_name == "ifrs" or taxonomy_family_name == "acpr-corep" or taxonomy_family_name == "cipc": set_additional_comment(doc, WD_ALIGN_PARAGRAPH.LEFT, "Aditional comment 0", 10, 82, 82, 82, True, False) elif taxonomy_family_name == "eurofiling": set_additional_comment(doc, WD_ALIGN_PARAGRAPH.LEFT, "Additional comment", 10, 82, 82, 82, True, False) elif taxonomy_family_name == "us-gaap": set_additional_comment(doc, WD_ALIGN_PARAGRAPH.LEFT, "Aditional comment 0", 8, 82, 82, 82, True, False) elif taxonomy_family_name == "bbk": add_hyperlink(set_additional_comment(doc, WD_ALIGN_PARAGRAPH.LEFT, "", 8, 82, 82, 82, True, False), "Aditional comment 0", "Aditional comment 0") elif taxonomy_family_name == "bdp" or taxonomy_family_name == "cbi" or taxonomy_family_name == "cbi-fsp": set_additional_comment(doc, WD_ALIGN_PARAGRAPH.LEFT, "Aditional comment 0", 10, 82, 82, 82, True, False) elif taxonomy_family_name == "edinet": add_hyperlink(set_additional_comment(doc, WD_ALIGN_PARAGRAPH.LEFT, "", 8, 82, 82, 82, True, False), "Aditional comment 0", "Aditional comment 0") set_additional_comment(doc, WD_ALIGN_PARAGRAPH.LEFT, "Additional comment", 11, 82, 82, 82, True, False) else: set_additional_comment(doc, WD_ALIGN_PARAGRAPH.LEFT, "Aditional comment 0", 11, 82, 82, 82, True, False) # ------------------------------------------------------------------------------------------------------------------ # footer section # ------------------------------------------------------------------------------------------------------------------ footer: Any = section.footer set_footer(footer, 0, "Ver: 01/2022", 10) # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # </LICENSE APPROVAL DOCUMENT> # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # Compose total filename of license approval docx_file_name = compose_docx_file_name( "filebasename", " ", taxonomy_version, " ", "XBRL Taxonomy - Third Party Software License Approval Form", " ", "YYYYMMDD", ".docx" ) # write content and save file doc.save(f"lics/{docx_file_name}") print(termcolor.colored("\nDocument successfully generated!", 'green') + "\n" + termcolor.colored("-" * 32, 'green') + "\n" + "Your generated file: " + termcolor.colored( docx_file_name, 'yellow') + " can be found at './YYYY-MM-DD/'") elif not taxonomy_family_name: print(f"ERROR: Taxonomy family {args.family} not found!") if __name__ == "__main__": main()
0
repos/exploratory-tech-studio/tech-studio-projects/data-structures/lock-free-linked-list
repos/exploratory-tech-studio/tech-studio-projects/data-structures/lock-free-linked-list/java/LockFreeLinkedList.java
import java.util.concurrent.atomic.AtomicMarkableReference; public class LockFreeLinkedList { private class Node { int value; AtomicMarkableReference<Node> next; Node(int value, Node next) { this.value = value; this.next = new AtomicMarkableReference<>(next, false); } } private final Node head; public LockFreeLinkedList() { head = new Node(Integer.MIN_VALUE, null); head.next.set(new Node(Integer.MAX_VALUE, null), false); } public boolean insert(int value) { Node pred, curr; while (true) { Node[] nodes = find(value); pred = nodes[0]; curr = nodes[1]; if (curr.value == value) { return false; // Value already present } else { Node newNode = new Node(value, curr); if (pred.next.compareAndSet(curr, newNode, false, false)) { return true; } } } } public boolean remove(int value) { Node pred, curr; while (true) { Node[] nodes = find(value); pred = nodes[0]; curr = nodes[1]; if (curr.value != value) { return false; // Value not present } else { Node succ = curr.next.getReference(); if (!curr.next.attemptMark(succ, true)) { continue; // Retry } pred.next.compareAndSet(curr, succ, false, false); return true; } } } public boolean contains(int value) { Node curr = head; while (curr.value < value) { curr = curr.next.getReference(); } return curr.value == value && !curr.next.isMarked(); } public void display() { Node curr = head.next.getReference(); while (curr.value < Integer.MAX_VALUE) { System.out.print(curr.value + " "); curr = curr.next.getReference(); } System.out.println(); } private Node[] find(int value) { Node pred = null, curr = null, succ = null; boolean[] marked = {false}; boolean snip; retry: while (true) { pred = head; curr = pred.next.getReference(); while (true) { succ = curr.next.get(marked); while (marked[0]) { snip = pred.next.compareAndSet(curr, succ, false, false); if (!snip) continue retry; curr = succ; succ = curr.next.get(marked); } if (curr.value >= value) { return new Node[]{pred, curr}; } pred = curr; curr = succ; } } } }
0
repos/exploratory-tech-studio/tech-studio-projects/data-structures/lock-free-linked-list
repos/exploratory-tech-studio/tech-studio-projects/data-structures/lock-free-linked-list/java/Main.java
public class Main { public static void main(String[] args) { LockFreeLinkedList list = new LockFreeLinkedList(); // Insert elements into the linked list list.insert(10); list.insert(20); list.insert(15); // Display the linked list System.out.print("Linked List after insertion: "); list.display(); // Remove an element from the linked list list.remove(20); // Display the linked list after removal System.out.print("Linked List after removal: "); list.display(); // Check if the linked list contains a value System.out.println("Linked List contains 15: " + list.contains(15)); System.out.println("Linked List contains 25: " + list.contains(25)); } }
0
repos/exploratory-tech-studio/tech-studio-projects/data-structures/lock-free-linked-list
repos/exploratory-tech-studio/tech-studio-projects/data-structures/lock-free-linked-list/cpp/LLFL.h
#ifndef LOCK_FREE_LINKED_LIST_H #define LOCK_FREE_LINKED_LIST_H #include <atomic> /** * @brief Node class representing a node in the lock-free linked list. */ class Node { public: int data; std::atomic<Node*> next; Node(int value); }; /** * @brief LockFreeLinkedList class representing a lock-free linked list. */ class LockFreeLinkedList { private: std::atomic<Node*> head; public: LockFreeLinkedList(); ~LockFreeLinkedList(); void insert(int value); // Insert a value into the linked list bool remove(int value); // Remove a value from the linked list bool contains(int value) const; // Check if the linked list contains a value void display() const; // Display the elements of the linked list }; #endif // LOCK_FREE_LINKED_LIST_H
0
repos/exploratory-tech-studio/tech-studio-projects/data-structures/lock-free-linked-list
repos/exploratory-tech-studio/tech-studio-projects/data-structures/lock-free-linked-list/cpp/LLFL.cpp
#include "LLFL.h" #include <iostream> Node::Node(int value) : data(value), next(nullptr) {} LockFreeLinkedList::LockFreeLinkedList() : head(nullptr) {} LockFreeLinkedList::~LockFreeLinkedList() { Node* curr = head.load(); while (curr != nullptr) { Node* next = curr->next.load(); delete curr; curr = next; } } void LockFreeLinkedList::insert(int value) { Node* newNode = new Node(value); newNode->next = head.load(); while (!head.compare_exchange_weak(newNode->next, newNode)); } bool LockFreeLinkedList::remove(int value) { Node* curr = head.load(); Node* prev = nullptr; while (curr != nullptr && curr->data != value) { prev = curr; curr = curr->next.load(); } if (curr == nullptr) return false; // Value not found if (prev == nullptr) { head = curr->next.load(); } else { prev->next = curr->next.load(); } delete curr; return true; } bool LockFreeLinkedList::contains(int value) const { Node* curr = head.load(); while (curr != nullptr) { if (curr->data == value) return true; curr = curr->next.load(); } return false; } void LockFreeLinkedList::display() const { Node* curr = head.load(); while (curr != nullptr) { std::cout << curr->data << " "; curr = curr->next.load(); } std::cout << std::endl; }
0
repos/exploratory-tech-studio/tech-studio-projects/data-structures/lock-free-linked-list
repos/exploratory-tech-studio/tech-studio-projects/data-structures/lock-free-linked-list/cpp/main.cpp
#include <iostream> #include "LLFL.h" int main() { LockFreeLinkedList list; // Insert elements into the linked list list.insert(10); list.insert(20); list.insert(15); // Display the linked list std::cout << "Linked List after insertion: "; list.display(); // Remove an element from the linked list list.remove(20); // Display the linked list after removal std::cout << "Linked List after removal: "; list.display(); // Check if the linked list contains a value std::cout << "Linked List contains 15: " << std::boolalpha << list.contains(15) << std::endl; std::cout << "Linked List contains 25: " << std::boolalpha << list.contains(25) << std::endl; return 0; }
0
repos/exploratory-tech-studio/tech-studio-projects/data-structures
repos/exploratory-tech-studio/tech-studio-projects/data-structures/disjoint-set/README.md
# Disjoint Set ## Description A data structure that stores non overlapping or disjoint subset of elements is called disjoint set data structure. The disjoint set data structure supports following operations: * Adding new sets to the disjoint set. * Merging disjoint sets to a single disjoint set using Union operation. * Finding representative of a disjoint set using Find operation. * Check if two sets are disjoint or not. Consider a situation with a number of persons and the following tasks to be performed on them: * Add a new friendship relation, i.e. a person x becomes the friend of another person y i.e adding new element to a set. * Find whether individual x is a friend of individual y (direct or indirect friend) [https://www.geeksforgeeks.org/introduction-to-disjoint-set-data-structure-or-union-find-algorithm/](https://www.geeksforgeeks.org/introduction-to-disjoint-set-data-structure-or-union-find-algorithm/) ## Use cases * Connected Components in Graphs * Kruskal's Algorithm for Minimum Spanning Tree * Network Connectivity * Equivalence Classes * Dynamic Connectivity * Image Processing * Clustering
0
repos/exploratory-tech-studio/tech-studio-projects/data-structures/disjoint-set
repos/exploratory-tech-studio/tech-studio-projects/data-structures/disjoint-set/java/DisjointSet.java
public class DisjointSet { private int[] parent; private int[] rank; public DisjointSet(int size) { parent = new int[size]; rank = new int[size]; for (int i = 0; i < size; i++) { makeSet(i); } } public void makeSet(int x) { parent[x] = x; rank[x] = 0; } public int find(int x) { if (parent[x] != x) { parent[x] = find(parent[x]); // Path compression } return parent[x]; } public void unionSets(int x, int y) { int rootX = find(x); int rootY = find(y); if (rootX != rootY) { // Union by rank if (rank[rootX] > rank[rootY]) { parent[rootY] = rootX; } else if (rank[rootX] < rank[rootY]) { parent[rootX] = rootY; } else { parent[rootY] = rootX; rank[rootX]++; } } } }
0
repos/exploratory-tech-studio/tech-studio-projects/data-structures/disjoint-set
repos/exploratory-tech-studio/tech-studio-projects/data-structures/disjoint-set/java/Main.java
public class Main { public static void main(String[] args) { // Example usage of DisjointSet DisjointSet ds = new DisjointSet(5); ds.unionSets(0, 1); ds.unionSets(2, 3); ds.unionSets(0, 4); for (int i = 0; i < 5; ++i) { System.out.println("Parent of " + i + ": " + ds.find(i)); } } }
0
repos/exploratory-tech-studio/tech-studio-projects/data-structures/disjoint-set
repos/exploratory-tech-studio/tech-studio-projects/data-structures/disjoint-set/cpp/DisjointSet.h
#ifndef DISJOINT_SET_H #define DISJOINT_SET_H #include <vector> class DisjointSet { public: DisjointSet(int size); void makeSet(int x); int find(int x); void unionSets(int x, int y); private: std::vector<int> parent; std::vector<int> rank; }; #endif // DISJOINT_SET_H
0
repos/exploratory-tech-studio/tech-studio-projects/data-structures/disjoint-set
repos/exploratory-tech-studio/tech-studio-projects/data-structures/disjoint-set/cpp/disjointSet.cpp
#include "DisjointSet.h" DisjointSet::DisjointSet(int size) : parent(size), rank(size, 0) {} void DisjointSet::makeSet(int x) { parent[x] = x; rank[x] = 0; } int DisjointSet::find(int x) { if (x != parent[x]) { parent[x] = find(parent[x]); } return parent[x]; } void DisjointSet::unionSets(int x, int y) { int rootX = find(x); int rootY = find(y); if (rootX != rootY) { if (rank[rootX] < rank[rootY]) { parent[rootX] = rootY; } else if (rank[rootX] > rank[rootY]) { parent[rootY] = rootX; } else { parent[rootY] = rootX; rank[rootX]++; } } }
0
repos/exploratory-tech-studio/tech-studio-projects/data-structures/disjoint-set
repos/exploratory-tech-studio/tech-studio-projects/data-structures/disjoint-set/cpp/main.cpp
#include <iostream> #include "DisjointSet.h" int main() { // Example usage of DisjointSet DisjointSet ds(5); ds.makeSet(0); ds.makeSet(1); ds.makeSet(2); ds.makeSet(3); ds.makeSet(4); ds.unionSets(0, 1); ds.unionSets(2, 3); ds.unionSets(0, 4); for (int i = 0; i < 5; ++i) { std::cout << "Parent of " << i << ": " << ds.find(i) << std::endl; } return 0; }
0
repos/exploratory-tech-studio/tech-studio-projects/data-structures/hash-map
repos/exploratory-tech-studio/tech-studio-projects/data-structures/hash-map/java/Main.java
import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; public class Main { private static Map<String, HeavenlyBody> solarSystem = new HashMap<>(); private static Set<HeavenlyBody> planets = new HashSet<>(); public static void main(String[] args) { HeavenlyBody temp = new HeavenlyBody("Mercury", 88); solarSystem.put(temp.getName(), temp); planets.add(temp); temp = new HeavenlyBody("Venus", 225); solarSystem.put(temp.getName(), temp); planets.add(temp); temp = new HeavenlyBody("Earth", 365); solarSystem.put(temp.getName(), temp); planets.add(temp); HeavenlyBody tempMoon = new HeavenlyBody("Moon", 27); solarSystem.put(tempMoon.getName(), tempMoon); temp.addMoon(tempMoon); temp = new HeavenlyBody("Mars", 687); solarSystem.put(temp.getName(), temp); planets.add(temp); tempMoon = new HeavenlyBody("Deimos", 1.3); solarSystem.put(tempMoon.getName(), tempMoon); temp.addMoon(tempMoon); // temp is still Mars tempMoon = new HeavenlyBody("Phobos", 0.3); solarSystem.put(tempMoon.getName(), tempMoon); temp.addMoon(tempMoon); // temp is still Mars temp = new HeavenlyBody("Jupiter", 4332); solarSystem.put(temp.getName(), temp); planets.add(temp); tempMoon = new HeavenlyBody("Io", 1.8); solarSystem.put(tempMoon.getName(), tempMoon); temp.addMoon(tempMoon); // temp is still Jupiter tempMoon = new HeavenlyBody("Europa", 3.5); solarSystem.put(tempMoon.getName(), tempMoon); temp.addMoon(tempMoon); // temp is still Jupiter tempMoon = new HeavenlyBody("Ganymede", 7.1); solarSystem.put(tempMoon.getName(), tempMoon); temp.addMoon(tempMoon); // temp is still Jupiter tempMoon = new HeavenlyBody("Callisto", 16.7); solarSystem.put(tempMoon.getName(), tempMoon); temp.addMoon(tempMoon); // temp is still Jupiter temp = new HeavenlyBody("Saturn", 10759); solarSystem.put(temp.getName(), temp); planets.add(temp); temp = new HeavenlyBody("Uranus", 30660); solarSystem.put(temp.getName(), temp); planets.add(temp); temp = new HeavenlyBody("Neptune", 165); solarSystem.put(temp.getName(), temp); planets.add(temp); temp = new HeavenlyBody("Pluto", 248); solarSystem.put(temp.getName(), temp); planets.add(temp); System.out.println("Planets"); for(HeavenlyBody planet : planets) { System.out.println("\t" + planet.getName()); } HeavenlyBody body = solarSystem.get("Mars"); System.out.println("Moons of " + body.getName()); for(HeavenlyBody jupiterMoon: body.getSatellites()) { System.out.println("\t" + jupiterMoon.getName()); } Set<HeavenlyBody> moons = new HashSet<>(); for(HeavenlyBody planet : planets) { moons.addAll(planet.getSatellites()); } System.out.println("All Moons"); for(HeavenlyBody moon : moons) { System.out.println("\t" + moon.getName()); } HeavenlyBody pluto = new HeavenlyBody("Pluto", 842); planets.add(pluto); for(HeavenlyBody planet : planets) { System.out.println(planet.getName() + ": " + planet.getOrbitalPeriod()); } Object o = new Object(); o.equals(o); "pluto".equals(""); } }
0
repos/exploratory-tech-studio/tech-studio-projects/data-structures/hash-map
repos/exploratory-tech-studio/tech-studio-projects/data-structures/hash-map/java/HeavenlyBody.java
import java.util.HashSet; import java.util.Set; public final class HeavenlyBody { private final String name; private final double orbitalPeriod; private final Set<HeavenlyBody> satellites; public HeavenlyBody(String name, double orbitalPeriod) { this.name = name; this.orbitalPeriod = orbitalPeriod; this.satellites = new HashSet<>(); } public String getName() { return name; } public double getOrbitalPeriod() { return orbitalPeriod; } public boolean addMoon(HeavenlyBody moon) { return this.satellites.add(moon); } public Set<HeavenlyBody> getSatellites() { return new HashSet<>(this.satellites); } public boolean equals(Object obj) { if(this == obj) { return true; } System.out.println("obj.getClass() is " + obj.getClass()); System.out.println("this.getClass() is " + this.getClass()); if ((obj == null) || (obj.getClass() != this.getClass())) { return false; } String objName = ((HeavenlyBody) obj).getName(); return this.name.equals(objName); } }
0
repos/exploratory-tech-studio/tech-studio-projects/data-structures/hash-map
repos/exploratory-tech-studio/tech-studio-projects/data-structures/hash-map/cpp/main.cpp
#include <iostream> #include "HM.h" int main() { HashMapList hashMap; // Insert key-value pairs hashMap.insert(1, 10); hashMap.insert(2, 20); hashMap.insert(11, 30); hashMap.insert(12, 40); hashMap.insert(22, 50); // Display the hash map contents std::cout << "Hash Map Contents:" << std::endl; hashMap.display(); // Retrieve values by keys std::cout << "Value corresponding to key 11: " << hashMap.get(11) << std::endl; std::cout << "Value corresponding to key 3: " << hashMap.get(3) << std::endl; // Remove a key-value pair std::cout << "Removing key 11: " << (hashMap.remove(11) ? "Success" : "Failed") << std::endl; // Display the hash map contents after removal std::cout << "Hash Map Contents after removal:" << std::endl; hashMap.display(); return 0; }
0
repos/exploratory-tech-studio/tech-studio-projects/data-structures/hash-map
repos/exploratory-tech-studio/tech-studio-projects/data-structures/hash-map/cpp/HM.h
#ifndef HASH_MAP_LIST_H #define HASH_MAP_LIST_H #include <cstddef> #include <iostream> class HashMapList { private: struct Node { int key; int value; Node* next; Node(int k, int v) : key(k), value(v), next(nullptr) {} }; static const std::size_t TABLE_SIZE = 10; Node* table[TABLE_SIZE]; std::size_t hash(int key) const; public: HashMapList(); ~HashMapList(); void insert(int key, int value); int get(int key) const; bool remove(int key); void display() const; }; #endif // HASH_MAP_LIST_H