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 // iterator(const iterator&) = delete;
13 // iterator(iterator&&) = default;
14 // iterator& operator=(const iterator&) = delete;
15 // iterator& operator=(iterator&&) = default;
16
17 #include <cassert>
18 #include <ranges>
19 #include <sstream>
20 #include <type_traits>
21
22 #include "test_macros.h"
23 #include "../utils.h"
24
25 template <class CharT>
26 using Iter = std::ranges::iterator_t<std::ranges::basic_istream_view<int, CharT>>;
27 static_assert(!std::copy_constructible<Iter<char>>);
28 static_assert(!std::is_copy_assignable_v<Iter<char>>);
29 static_assert(std::move_constructible<Iter<char>>);
30 static_assert(std::is_move_assignable_v<Iter<char>>);
31
32 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
33 static_assert(!std::copy_constructible<Iter<wchar_t>>);
34 static_assert(!std::is_copy_assignable_v<Iter<wchar_t>>);
35 static_assert(std::move_constructible<Iter<wchar_t>>);
36 static_assert(std::is_move_assignable_v<Iter<wchar_t>>);
37 #endif
38
39 template <class CharT>
test()40 void test() {
41 // test move constructor
42 {
43 auto iss = make_string_stream<CharT>("12 3");
44 std::ranges::basic_istream_view<int, CharT> isv{iss};
45 auto it = isv.begin();
46 auto it2 = std::move(it);
47 assert(*it2 == 12);
48 }
49
50 // test move assignment
51 {
52 auto iss1 = make_string_stream<CharT>("12 3");
53 std::ranges::basic_istream_view<int, CharT> isv1{iss1};
54 auto iss2 = make_string_stream<CharT>("45 6");
55 std::ranges::basic_istream_view<int, CharT> isv2{iss2};
56
57 auto it1 = isv1.begin();
58 assert(*it1 == 12);
59 it1 = isv2.begin();
60 assert(*it1 == 45);
61 }
62 }
63
main(int,char **)64 int main(int, char**) {
65 test<char>();
66 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
67 test<wchar_t>();
68 #endif
69
70 return 0;
71 }
72