xref: /llvm-project/libcxx/test/std/ranges/range.adaptors/range.take.while/general.pass.cpp (revision a2c6a1193f41e40840a7ead6c1c0540d3062c13a)
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
10 
11 // Some basic examples of how take_while_view might be used in the wild. This is a general
12 // collection of sample algorithms and functions that try to mock general usage of
13 // this view.
14 
15 #include <algorithm>
16 #include <cassert>
17 #include <ranges>
18 
main(int,char **)19 int main(int, char**) {
20   {
21     auto input      = {0, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 0};
22     auto small      = [](const auto x) noexcept { return x < 5; };
23     auto small_ints = input | std::views::take_while(small);
24     auto expected   = {0, 1, 2, 3, 4};
25     assert(std::ranges::equal(small_ints, expected));
26   }
27   return 0;
28 }
29