Debian Codegraph @

libcxx/test/std/ranges/range.factories/range.istream.view/iterator/increment.pass.cpp

raw
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: no-localization
10 // UNSUPPORTED: c++03, c++11, c++14, c++17
11
12 // iterator& operator++();
13 // void operator++(int);
14
15 #include <cassert>
16 #include <ranges>
17 #include <sstream>
18
19 #include "test_macros.h"
20 #include "../utils.h"
21
22 template <class CharT>
23 void test() {
24 // operator ++()
25 {
26 auto iss = make_string_stream<CharT>("1 2 345 ");
27 std::ranges::basic_istream_view<int, CharT> isv{iss};
28 auto it = isv.begin();
29 assert(*it == 1);
30
31 std::same_as<decltype(it)&> decltype(auto) it2 = ++it;
32 assert(&it2 == &it);
33 assert(*it2 == 2);
34
35 ++it2;
36 assert(*it2 == 345);
37
38 ++it2;
39 assert(it2 == isv.end());
40 }
41
42 // operator ++(int)
43 {
44 auto iss = make_string_stream<CharT>("1 2 345 ");
45 std::ranges::basic_istream_view<int, CharT> isv{iss};
46 auto it = isv.begin();
47 assert(*it == 1);
48
49 static_assert(std::same_as<decltype(it++), void>);
50 it++;
51 assert(*it == 2);
52 }
53 }
54
55 int main(int, char**) {
56 test<char>();
57 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
58 test<wchar_t>();
59 #endif
60
61 return 0;
62 }