58 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 explicit basic_istream_view(basic_istream<CharT, Traits>& stream);13 14#include <cassert>15#include <ranges>16#include <sstream>17 18#include "test_macros.h"19#include "utils.h"20 21// test that the constructor is explicit22static_assert(std::constructible_from<std::ranges::istream_view<int>, std::istream&>);23static_assert(!std::convertible_to<std::istream&, std::ranges::istream_view<int>>);24 25#ifndef TEST_HAS_NO_WIDE_CHARACTERS26static_assert(std::constructible_from<std::ranges::wistream_view<int>, std::wistream&>);27static_assert(!std::convertible_to<std::wistream&, std::ranges::wistream_view<int>>);28#endif29 30template <class CharT>31void test() {32 // test constructor init the stream pointer to the passed one33 {34 auto iss = make_string_stream<CharT>("123");35 std::ranges::basic_istream_view<int, CharT> isv{iss};36 auto it = isv.begin();37 assert(*it == 123);38 }39 40 // LWG 3568. basic_istream_view needs to initialize value_41 {42 auto iss = make_string_stream<CharT>("123");43 std::ranges::basic_istream_view<int, CharT> isv{iss};44 using Iter = std::ranges::iterator_t<decltype(isv)>;45 Iter iter{isv};46 assert(*iter == 0);47 }48}49 50int main(int, char**) {51 test<char>();52#ifndef TEST_HAS_NO_WIDE_CHARACTERS53 test<wchar_t>();54#endif55 56 return 0;57}58