1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 11 // <string_view> 12 13 // constexpr basic_string_view(const _CharT* _s) 14 // : __data (_s), __size(_Traits::length(_s)) {} 15 16 17 #include <string_view> 18 #include <string> 19 #include <cassert> 20 21 #include "test_macros.h" 22 #include "constexpr_char_traits.hpp" 23 24 template<typename CharT> StrLen(const CharT * s)25size_t StrLen ( const CharT *s ) { 26 size_t retVal = 0; 27 while ( *s != 0 ) { ++retVal; ++s; } 28 return retVal; 29 } 30 31 template<typename CharT> test(const CharT * s)32void test ( const CharT *s ) { 33 std::basic_string_view<CharT> sv1 ( s ); 34 assert ( sv1.size() == StrLen( s )); 35 assert ( sv1.data() == s ); 36 } 37 38 main()39int main () { 40 41 test ( "QBCDE" ); 42 test ( "A" ); 43 test ( "" ); 44 45 test ( L"QBCDE" ); 46 test ( L"A" ); 47 test ( L"" ); 48 49 #if TEST_STD_VER >= 11 50 test ( u"QBCDE" ); 51 test ( u"A" ); 52 test ( u"" ); 53 54 test ( U"QBCDE" ); 55 test ( U"A" ); 56 test ( U"" ); 57 #endif 58 59 #if TEST_STD_VER > 11 60 { 61 constexpr std::basic_string_view<char, constexpr_char_traits<char>> sv1 ( "ABCDE" ); 62 static_assert ( sv1.size() == 5, ""); 63 } 64 #endif 65 } 66