xref: /llvm-project/libcxx/test/std/ranges/range.factories/range.istream.view/iterator/deref.pass.cpp (revision 96a509bca28b8668c3c2c68aae4116cc0d8c2952)
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 // Val& operator*() const;
13 
14 #include <cassert>
15 #include <ranges>
16 #include <sstream>
17 
18 #include "test_macros.h"
19 #include "../utils.h"
20 
21 template <class CharT>
test()22 void test() {
23   // operator* should return correct value
24   {
25     auto iss = make_string_stream<CharT>("1 2 345 ");
26     std::ranges::basic_istream_view<int, CharT> isv{iss};
27     auto it                              = isv.begin();
28     std::same_as<int&> decltype(auto) v1 = *it;
29     assert(v1 == 1);
30   }
31 
32   // operator* should return the same reference to the value stored in the view
33   {
34     auto iss = make_string_stream<CharT>("1 2 345 ");
35     std::ranges::basic_istream_view<int, CharT> isv{iss};
36     using Iter = std::ranges::iterator_t<decltype(isv)>;
37 
38     Iter it1{isv};
39     Iter it2{isv};
40     assert(&*it1 == &*it2);
41   }
42 }
43 
main(int,char **)44 int main(int, char**) {
45   test<char>();
46 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
47   test<wchar_t>();
48 #endif
49 
50   return 0;
51 }
52