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 10 // <string_view> 11 12 // constexpr const _CharT* data() const noexcept; 13 14 #include <string_view> 15 #include <cassert> 16 17 #include "test_macros.h" 18 19 template <typename CharT> 20 void test ( const CharT *s, size_t len ) { 21 std::basic_string_view<CharT> sv ( s, len ); 22 assert ( sv.length() == len ); 23 assert ( sv.data() == s ); 24 #if TEST_STD_VER > 14 25 // make sure we pick up std::data, too! 26 assert ( sv.data() == std::data(sv)); 27 #endif 28 } 29 30 int main(int, char**) { 31 test ( "ABCDE", 5 ); 32 test ( "a", 1 ); 33 34 test ( L"ABCDE", 5 ); 35 test ( L"a", 1 ); 36 37 #if TEST_STD_VER >= 11 38 test ( u"ABCDE", 5 ); 39 test ( u"a", 1 ); 40 41 test ( U"ABCDE", 5 ); 42 test ( U"a", 1 ); 43 #endif 44 45 #if TEST_STD_VER > 11 46 { 47 constexpr const char *s = "ABC"; 48 constexpr std::basic_string_view<char> sv( s, 2 ); 49 static_assert( sv.length() == 2, "" ); 50 static_assert( sv.data() == s, "" ); 51 } 52 #endif 53 54 return 0; 55 } 56