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 auto begin(); 13 14 #include <cassert> 15 #include <ranges> 16 #include <sstream> 17 18 #include "test_macros.h" 19 #include "utils.h" 20 21 template <class T> 22 concept HasBegin = requires(T t) { t.begin(); }; 23 24 static_assert(HasBegin<std::ranges::istream_view<int>>); 25 static_assert(!HasBegin<const std::ranges::istream_view<int>>); 26 27 #ifndef TEST_HAS_NO_WIDE_CHARACTERS 28 static_assert(HasBegin<std::ranges::wistream_view<int>>); 29 static_assert(!HasBegin<const std::ranges::wistream_view<int>>); 30 #endif 31 32 template <class CharT> test()33void test() { 34 // begin should read the first element 35 { 36 auto iss = make_string_stream<CharT>("12 3"); 37 std::ranges::basic_istream_view<int, CharT> isv{iss}; 38 auto it = isv.begin(); 39 assert(*it == 12); 40 } 41 42 // empty stream 43 { 44 auto iss = make_string_stream<CharT>(""); 45 std::ranges::basic_istream_view<int, CharT> isv{iss}; 46 auto it = isv.begin(); 47 assert(it == isv.end()); 48 } 49 } 50 main(int,char **)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