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 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 9 // UNSUPPORTED: libcpp-has-no-incomplete-ranges 10 11 // <string_view> 12 13 // template<class Range> 14 // basic_string_view(Range&&) -> basic_string_view<ranges::range_value_t<Range>>; // C++23 15 16 #include <string_view> 17 #include <cassert> 18 19 #include "make_string.h" 20 #include "test_iterators.h" 21 #include "test_macros.h" 22 23 template<class CharT> 24 void test() { 25 auto val = MAKE_STRING(CharT, "test"); 26 auto sv = std::basic_string_view(val); 27 ASSERT_SAME_TYPE(decltype(sv), std::basic_string_view<CharT>); 28 assert(sv.size() == val.size()); 29 assert(sv.data() == val.data()); 30 } 31 32 void test() { 33 test<char>(); 34 #ifndef TEST_HAS_NO_WIDE_CHARACTERS 35 test<wchar_t>(); 36 #endif 37 test<char8_t>(); 38 test<char16_t>(); 39 test<char32_t>(); 40 test<char>(); 41 42 struct Widget { 43 const char16_t *data_ = u"foo"; 44 contiguous_iterator<const char16_t*> begin() const { return contiguous_iterator<const char16_t*>(data_); } 45 contiguous_iterator<const char16_t*> end() const { return contiguous_iterator<const char16_t*>(data_ + 3); } 46 }; 47 std::basic_string_view bsv = Widget(); 48 ASSERT_SAME_TYPE(decltype(bsv), std::basic_string_view<char16_t>); 49 } 50 51 int main(int, char**) { 52 test(); 53 54 return 0; 55 } 56 57