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