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// constexpr explicit iterator(basic_istream_view& parent) noexcept;
13
14#include <cassert>
15#include <ranges>
16#include <sstream>
17#include <type_traits>
18
19#include "test_macros.h"
20#include "../utils.h"
21
22// test that the constructor is explicit
23template <class CharT>
24using IstreamView = std::ranges::basic_istream_view<int, CharT>;
25template <class CharT>
26using Iter = std::ranges::iterator_t<IstreamView<CharT>>;
27
28static_assert(std::constructible_from<Iter<char>, IstreamView<char>&>);
29static_assert(!std::convertible_to<IstreamView<char>&, Iter<char>>);
30
31#ifndef TEST_HAS_NO_WIDE_CHARACTERS
32static_assert(std::constructible_from<Iter<wchar_t>, IstreamView<wchar_t>&>);
33static_assert(!std::convertible_to<IstreamView<wchar_t>&, Iter<wchar_t>>);
34#endif
35
36// test that the constructor is noexcept
37static_assert(std::is_nothrow_constructible_v<Iter<char>, IstreamView<char>&>);
38#ifndef TEST_HAS_NO_WIDE_CHARACTERS
39static_assert(std::is_nothrow_constructible_v<Iter<wchar_t>, IstreamView<wchar_t>&>);
40#endif
41
42template <class CharT>
43void test() {
44 auto iss = make_string_stream<CharT>("123");
45 std::ranges::basic_istream_view<int, CharT> isv{iss};
46 Iter<CharT> it{isv};
47 ++it;
48 assert(*it == 123);
49}
50
51int main(int, char**) {
52 test<char>();
53#ifndef TEST_HAS_NO_WIDE_CHARACTERS
54 test<wchar_t>();
55#endif
56
57 return 0;
58}
59

source code of libcxx/test/std/ranges/range.factories/range.istream.view/iterator/ctor.pass.cpp