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 | // Some basic examples of how istream_view might be used in the wild. This is a general |
13 | // collection of sample algorithms and functions that try to mock general usage of |
14 | // this view. |
15 | |
16 | #include <algorithm> |
17 | #include <cassert> |
18 | #include <ranges> |
19 | #include <sstream> |
20 | |
21 | #include "test_macros.h" |
22 | #include "utils.h" |
23 | |
24 | template <class CharT> |
25 | void test() { |
26 | auto ints = make_string_stream<CharT>("0 1 2 3 4" ); |
27 | auto oss = std::basic_ostringstream<CharT>{}; |
28 | auto delimiter = make_string<CharT>("-" ); |
29 | std::ranges::copy( |
30 | std::ranges::basic_istream_view<int, CharT>(ints), std::ostream_iterator<int, CharT>{oss, delimiter.c_str()}); |
31 | auto expected = make_string<CharT>("0-1-2-3-4-" ); |
32 | assert(oss.str() == expected); |
33 | } |
34 | |
35 | int main(int, char**) { |
36 | test<char>(); |
37 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
38 | test<wchar_t>(); |
39 | #endif |
40 | |
41 | return 0; |
42 | } |
43 | |