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 // <string_view> 10 11 // constexpr basic_string_view(const _CharT* _s, size_type _len) 12 // : __data (_s), __size(_len) {} 13 14 15 #include <string_view> 16 #include <string> 17 #include <cassert> 18 19 #include "test_macros.h" 20 21 template<typename CharT> 22 void test ( const CharT *s, size_t sz ) { 23 { 24 typedef std::basic_string_view<CharT> SV; 25 LIBCPP_ASSERT_NOEXCEPT(SV(s, sz)); 26 27 SV sv1 ( s, sz ); 28 assert ( sv1.size() == sz ); 29 assert ( sv1.data() == s ); 30 } 31 } 32 33 int main(int, char**) { 34 35 test ( "QBCDE", 5 ); 36 test ( "QBCDE", 2 ); 37 test ( "", 0 ); 38 #if TEST_STD_VER > 11 39 { 40 constexpr const char *s = "QBCDE"; 41 constexpr std::basic_string_view<char> sv1 ( s, 2 ); 42 static_assert ( sv1.size() == 2, "" ); 43 static_assert ( sv1.data() == s, "" ); 44 } 45 #endif 46 47 test ( L"QBCDE", 5 ); 48 test ( L"QBCDE", 2 ); 49 test ( L"", 0 ); 50 #if TEST_STD_VER > 11 51 { 52 constexpr const wchar_t *s = L"QBCDE"; 53 constexpr std::basic_string_view<wchar_t> sv1 ( s, 2 ); 54 static_assert ( sv1.size() == 2, "" ); 55 static_assert ( sv1.data() == s, "" ); 56 } 57 #endif 58 59 #if TEST_STD_VER >= 11 60 test ( u"QBCDE", 5 ); 61 test ( u"QBCDE", 2 ); 62 test ( u"", 0 ); 63 #if TEST_STD_VER > 11 64 { 65 constexpr const char16_t *s = u"QBCDE"; 66 constexpr std::basic_string_view<char16_t> sv1 ( s, 2 ); 67 static_assert ( sv1.size() == 2, "" ); 68 static_assert ( sv1.data() == s, "" ); 69 } 70 #endif 71 72 test ( U"QBCDE", 5 ); 73 test ( U"QBCDE", 2 ); 74 test ( U"", 0 ); 75 #if TEST_STD_VER > 11 76 { 77 constexpr const char32_t *s = U"QBCDE"; 78 constexpr std::basic_string_view<char32_t> sv1 ( s, 2 ); 79 static_assert ( sv1.size() == 2, "" ); 80 static_assert ( sv1.data() == s, "" ); 81 } 82 #endif 83 #endif 84 85 return 0; 86 } 87