brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · 99891bc Raw
59 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// constexpr auto begin();13 14#include <cassert>15#include <ranges>16#include <sstream>17 18#include "test_macros.h"19#include "utils.h"20 21template <class T>22concept HasBegin = requires(T t) { t.begin(); };23 24static_assert(HasBegin<std::ranges::istream_view<int>>);25static_assert(!HasBegin<const std::ranges::istream_view<int>>);26 27#ifndef TEST_HAS_NO_WIDE_CHARACTERS28static_assert(HasBegin<std::ranges::wistream_view<int>>);29static_assert(!HasBegin<const std::ranges::wistream_view<int>>);30#endif31 32template <class CharT>33void test() {34  // begin should read the first element35  {36    auto iss = make_string_stream<CharT>("12    3");37    std::ranges::basic_istream_view<int, CharT> isv{iss};38    auto it = isv.begin();39    assert(*it == 12);40  }41 42  // empty stream43  {44    auto iss = make_string_stream<CharT>("");45    std::ranges::basic_istream_view<int, CharT> isv{iss};46    auto it = isv.begin();47    assert(it == isv.end());48  }49}50 51int main(int, char**) {52  test<char>();53#ifndef TEST_HAS_NO_WIDE_CHARACTERS54  test<wchar_t>();55#endif56 57  return 0;58}59