1*053d81ceSMarshall Clow //===----------------------------------------------------------------------===// 2*053d81ceSMarshall Clow // 3*053d81ceSMarshall Clow // The LLVM Compiler Infrastructure 4*053d81ceSMarshall Clow // 5*053d81ceSMarshall Clow // This file is dual licensed under the MIT and the University of Illinois Open 6*053d81ceSMarshall Clow // Source Licenses. See LICENSE.TXT for details. 7*053d81ceSMarshall Clow // 8*053d81ceSMarshall Clow //===----------------------------------------------------------------------===// 9*053d81ceSMarshall Clow 10*053d81ceSMarshall Clow 11*053d81ceSMarshall Clow // <string_view> 12*053d81ceSMarshall Clow 13*053d81ceSMarshall Clow // constexpr const _CharT* data() const noexcept; 14*053d81ceSMarshall Clow 15*053d81ceSMarshall Clow #include <string_view> 16*053d81ceSMarshall Clow #include <cassert> 17*053d81ceSMarshall Clow 18*053d81ceSMarshall Clow #include "test_macros.h" 19*053d81ceSMarshall Clow 20*053d81ceSMarshall Clow template <typename CharT> 21*053d81ceSMarshall Clow void test ( const CharT *s, size_t len ) { 22*053d81ceSMarshall Clow std::basic_string_view<CharT> sv ( s, len ); 23*053d81ceSMarshall Clow assert ( sv.length() == len ); 24*053d81ceSMarshall Clow assert ( sv.data() == s ); 25*053d81ceSMarshall Clow } 26*053d81ceSMarshall Clow 27*053d81ceSMarshall Clow int main () { 28*053d81ceSMarshall Clow test ( "ABCDE", 5 ); 29*053d81ceSMarshall Clow test ( "a", 1 ); 30*053d81ceSMarshall Clow 31*053d81ceSMarshall Clow test ( L"ABCDE", 5 ); 32*053d81ceSMarshall Clow test ( L"a", 1 ); 33*053d81ceSMarshall Clow 34*053d81ceSMarshall Clow #if TEST_STD_VER >= 11 35*053d81ceSMarshall Clow test ( u"ABCDE", 5 ); 36*053d81ceSMarshall Clow test ( u"a", 1 ); 37*053d81ceSMarshall Clow 38*053d81ceSMarshall Clow test ( U"ABCDE", 5 ); 39*053d81ceSMarshall Clow test ( U"a", 1 ); 40*053d81ceSMarshall Clow #endif 41*053d81ceSMarshall Clow 42*053d81ceSMarshall Clow #if _LIBCPP_STD_VER > 11 43*053d81ceSMarshall Clow { 44*053d81ceSMarshall Clow constexpr const char *s = "ABC"; 45*053d81ceSMarshall Clow constexpr std::basic_string_view<char> sv( s, 2 ); 46*053d81ceSMarshall Clow static_assert( sv.length() == 2, "" ); 47*053d81ceSMarshall Clow static_assert( sv.data() == s, "" ); 48*053d81ceSMarshall Clow } 49*053d81ceSMarshall Clow #endif 50*053d81ceSMarshall Clow } 51