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// concept checking istream_view
13
14#include <istream>
15#include <ranges>
16
17#include "test_macros.h"
18
19template <class Val, class CharT, class Traits = std::char_traits<CharT>>
20concept HasIstreamView = requires { typename std::ranges::basic_istream_view<Val, CharT, Traits>; };
21
22static_assert(HasIstreamView<int, char>);
23
24#ifndef TEST_HAS_NO_WIDE_CHARACTERS
25static_assert(HasIstreamView<int, wchar_t>);
26#endif
27
28// Unmovable Val
29struct Unmovable {
30 Unmovable() = default;
31 Unmovable(Unmovable&&) = delete;
32 template <class CharT>
33 friend std::basic_istream<CharT>& operator>>(std::basic_istream<CharT>& x, const Unmovable&) {
34 return x;
35 }
36};
37static_assert(!HasIstreamView<Unmovable, char>);
38
39#ifndef TEST_HAS_NO_WIDE_CHARACTERS
40static_assert(!HasIstreamView<Unmovable, wchar_t>);
41#endif
42
43// !default_initializable<Val>
44struct NoDefaultCtor {
45 NoDefaultCtor(int) {}
46 friend std::istream& operator>>(std::istream& x, const NoDefaultCtor&) { return x; }
47};
48static_assert(!HasIstreamView<NoDefaultCtor, char>);
49#ifndef TEST_HAS_NO_WIDE_CHARACTERS
50static_assert(!HasIstreamView<NoDefaultCtor, wchar_t>);
51#endif
52
53// !stream-extractable<Val, CharT, Traits>
54struct Foo {};
55static_assert(!HasIstreamView<Foo, char>);
56#ifndef TEST_HAS_NO_WIDE_CHARACTERS
57static_assert(!HasIstreamView<Foo, wchar_t>);
58#endif
59
60template <class T>
61concept OnlyInputRange = std::ranges::input_range<T> && !std::ranges::forward_range<T>;
62
63static_assert(OnlyInputRange<std::ranges::istream_view<int>>);
64static_assert(OnlyInputRange<std::ranges::istream_view<long>>);
65static_assert(OnlyInputRange<std::ranges::istream_view<double>>);
66static_assert(OnlyInputRange<std::ranges::istream_view<char>>);
67
68#ifndef TEST_HAS_NO_WIDE_CHARACTERS
69static_assert(OnlyInputRange<std::ranges::wistream_view<int>>);
70static_assert(OnlyInputRange<std::ranges::wistream_view<long>>);
71static_assert(OnlyInputRange<std::ranges::wistream_view<double>>);
72static_assert(OnlyInputRange<std::ranges::wistream_view<wchar_t>>);
73#endif
74

source code of libcxx/test/std/ranges/range.factories/range.istream.view/range.concept.compile.pass.cpp