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