//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 // // Check constraints on the type itself. // // template , iterator_t> Pred> // requires view && is_object_v // class chunk_by_view; #include #include #include #include #include #include "almost_satisfies_types.h" #include "test_iterators.h" template concept CanFormChunkByView = requires { typename std::ranges::chunk_by_view; }; // chunk_by_view is not valid when the view is not a forward_range namespace test_when_view_is_not_a_forward_range { struct View : std::ranges::view_base { ForwardIteratorNotDerivedFrom begin() const; ForwardIteratorNotDerivedFrom end() const; }; struct Pred { bool operator()(int, int) const; }; static_assert(!std::ranges::forward_range); static_assert(std::indirect_binary_predicate); static_assert(std::ranges::view); static_assert(std::is_object_v); static_assert(!CanFormChunkByView); } // namespace test_when_view_is_not_a_forward_range // chunk_by_view is not valid when the predicate is not indirect_binary_predicate namespace test_when_the_predicate_is_not_indirect_binary_predicate { struct View : std::ranges::view_base { int* begin() const; int* end() const; }; struct Pred {}; static_assert(std::ranges::forward_range); static_assert(!std::indirect_binary_predicate); static_assert(std::ranges::view); static_assert(std::is_object_v); static_assert(!CanFormChunkByView); } // namespace test_when_the_predicate_is_not_indirect_binary_predicate // chunk_by_view is not valid when the view is not a view namespace test_when_the_view_param_is_not_a_view { struct View { int* begin() const; int* end() const; }; struct Pred { bool operator()(int, int) const; }; static_assert(std::ranges::input_range); static_assert(std::indirect_binary_predicate); static_assert(!std::ranges::view); static_assert(std::is_object_v); static_assert(!CanFormChunkByView); } // namespace test_when_the_view_param_is_not_a_view // chunk_by_view is not valid when the predicate is not an object type namespace test_when_the_predicate_is_not_an_object_type { struct View : std::ranges::view_base { int* begin() const; int* end() const; }; using Pred = bool (&)(int, int); static_assert(std::ranges::input_range); static_assert(std::indirect_binary_predicate); static_assert(std::ranges::view); static_assert(!std::is_object_v); static_assert(!CanFormChunkByView); } // namespace test_when_the_predicate_is_not_an_object_type // chunk_by_view is valid when all the constraints are satisfied (test the test) namespace test_when_all_the_constraints_are_satisfied { struct View : std::ranges::view_base { int* begin() const; int* end() const; }; struct Pred { bool operator()(int, int) const; }; static_assert(std::ranges::input_range); static_assert(std::indirect_binary_predicate); static_assert(std::ranges::view); static_assert(std::is_object_v); static_assert(CanFormChunkByView); } // namespace test_when_all_the_constraints_are_satisfied