1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: no-localization
10 // UNSUPPORTED: c++03, c++11, c++14, c++17
12 // concept checking istream_view
17 #include "test_macros.h"
19 template <class Val
, class CharT
, class Traits
= std::char_traits
<CharT
>>
20 concept HasIstreamView
= requires
{ typename
std::ranges::basic_istream_view
<Val
, CharT
, Traits
>; };
22 static_assert(HasIstreamView
<int, char>);
24 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
25 static_assert(HasIstreamView
<int, wchar_t>);
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
&) {
37 static_assert(!HasIstreamView
<Unmovable
, char>);
39 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
40 static_assert(!HasIstreamView
<Unmovable
, wchar_t>);
43 // !default_initializable<Val>
44 struct NoDefaultCtor
{
46 friend std::istream
& operator>>(std::istream
& x
, const NoDefaultCtor
&) { return x
; }
48 static_assert(!HasIstreamView
<NoDefaultCtor
, char>);
49 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
50 static_assert(!HasIstreamView
<NoDefaultCtor
, wchar_t>);
53 // !stream-extractable<Val, CharT, Traits>
55 static_assert(!HasIstreamView
<Foo
, char>);
56 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
57 static_assert(!HasIstreamView
<Foo
, wchar_t>);
61 concept OnlyInputRange
= std::ranges::input_range
<T
> && !std::ranges::forward_range
<T
>;
63 static_assert(OnlyInputRange
<std::ranges::istream_view
<int>>);
64 static_assert(OnlyInputRange
<std::ranges::istream_view
<long>>);
65 static_assert(OnlyInputRange
<std::ranges::istream_view
<double>>);
66 static_assert(OnlyInputRange
<std::ranges::istream_view
<char>>);
68 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
69 static_assert(OnlyInputRange
<std::ranges::wistream_view
<int>>);
70 static_assert(OnlyInputRange
<std::ranges::wistream_view
<long>>);
71 static_assert(OnlyInputRange
<std::ranges::wistream_view
<double>>);
72 static_assert(OnlyInputRange
<std::ranges::wistream_view
<wchar_t>>);