brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · c65f10c Raw
43 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: no-localization10// UNSUPPORTED: c++03, c++11, c++14, c++1711 12// Some basic examples of how istream_view might be used in the wild. This is a general13// collection of sample algorithms and functions that try to mock general usage of14// 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 24template <class CharT>25void 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 35int main(int, char**) {36  test<char>();37#ifndef TEST_HAS_NO_WIDE_CHARACTERS38  test<wchar_t>();39#endif40 41  return 0;42}43