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 9 // UNSUPPORTED: libcpp-no-concepts 10 // UNSUPPORTED: libcpp-has-no-incomplete-ranges 11 12 // <string_view> 13 14 // template <class It, class End> 15 // constexpr basic_string_view(It begin, End end) 16 17 #include <string_view> 18 #include <cassert> 19 #include <ranges> 20 21 #include "make_string.h" 22 #include "test_iterators.h" 23 24 template<class CharT, class Sentinel> 25 constexpr void test() { 26 auto val = MAKE_STRING_VIEW(CharT, "test"); 27 auto sv = std::basic_string_view<CharT>(val.begin(), Sentinel(val.end())); 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 constexpr bool test() { 34 test<char, char*>(); 35 test<wchar_t, wchar_t*>(); 36 test<char8_t, char8_t*>(); 37 test<char16_t, char16_t*>(); 38 test<char32_t, char32_t*>(); 39 test<char, const char*>(); 40 test<char, sized_sentinel<const char*>>(); 41 return true; 42 } 43 44 static_assert( std::is_constructible_v<std::string_view, const char*, char*>); 45 static_assert( std::is_constructible_v<std::string_view, char*, const char*>); 46 static_assert(!std::is_constructible_v<std::string_view, char*, void*>); // not a sentinel 47 static_assert(!std::is_constructible_v<std::string_view, signed char*, signed char*>); // wrong char type 48 static_assert(!std::is_constructible_v<std::string_view, random_access_iterator<char*>, random_access_iterator<char*>>); // not contiguous 49 static_assert( std::is_constructible_v<std::string_view, contiguous_iterator<char*>, contiguous_iterator<char*>>); 50 51 int main(int, char**) { 52 test(); 53 static_assert(test()); 54 55 return 0; 56 } 57 58