//===----------------------------------------------------------------------===// // // 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 // std::views::drop_while #include #include #include #include #include #include "test_range.h" struct Pred { constexpr bool operator()(int i) const { return i < 3; } }; struct Foo {}; template struct BufferView : std::ranges::view_base { T* buffer_; std::size_t size_; template constexpr BufferView(T (&b)[N]) : buffer_(b), size_(N) {} }; using IntBufferView = BufferView; struct MoveOnlyView : IntBufferView { using IntBufferView::IntBufferView; MoveOnlyView(const MoveOnlyView&) = delete; MoveOnlyView& operator=(const MoveOnlyView&) = delete; MoveOnlyView(MoveOnlyView&&) = default; MoveOnlyView& operator=(MoveOnlyView&&) = default; constexpr const int* begin() const { return buffer_; } constexpr const int* end() const { return buffer_ + size_; } }; static_assert(!std::is_invocable_v); static_assert(std::is_invocable_v); static_assert(std::is_invocable_v); static_assert(!std::is_invocable_v); static_assert(std::is_invocable_v); static_assert(!std::is_invocable_v); static_assert(std::is_invocable_v); static_assert(!CanBePiped); static_assert(CanBePiped); static_assert(!CanBePiped); static_assert(CanBePiped); static_assert(!CanBePiped); constexpr bool test() { int buff[] = {1, 2, 3, 4, 3, 2, 1}; // Test `views::drop_while(p)(v)` { using Result = std::ranges::drop_while_view; std::same_as auto result = std::views::drop_while(Pred{})(MoveOnlyView{buff}); auto expected = {3, 4, 3, 2, 1}; assert(std::ranges::equal(result, expected)); } { auto const partial = std::views::drop_while(Pred{}); using Result = std::ranges::drop_while_view; std::same_as auto result = partial(MoveOnlyView{buff}); auto expected = {3, 4, 3, 2, 1}; assert(std::ranges::equal(result, expected)); } // Test `v | views::drop_while(p)` { using Result = std::ranges::drop_while_view; std::same_as auto result = MoveOnlyView{buff} | std::views::drop_while(Pred{}); auto expected = {3, 4, 3, 2, 1}; assert(std::ranges::equal(result, expected)); } { auto const partial = std::views::drop_while(Pred{}); using Result = std::ranges::drop_while_view; std::same_as auto result = MoveOnlyView{buff} | partial; auto expected = {3, 4, 3, 2, 1}; assert(std::ranges::equal(result, expected)); } // Test `views::drop_while(v, p)` { using Result = std::ranges::drop_while_view; std::same_as auto result = std::views::drop_while(MoveOnlyView{buff}, Pred{}); auto expected = {3, 4, 3, 2, 1}; assert(std::ranges::equal(result, expected)); } // Test adaptor | adaptor { struct Pred2 { constexpr bool operator()(int i) const { return i < 4; } }; auto const partial = std::views::drop_while(Pred{}) | std::views::drop_while(Pred2{}); using Result = std::ranges::drop_while_view, Pred2>; std::same_as auto result = MoveOnlyView{buff} | partial; auto expected = {4, 3, 2, 1}; assert(std::ranges::equal(result, expected)); } return true; } int main(int, char**) { test(); static_assert(test()); return 0; }