1053d81ceSMarshall Clow //===----------------------------------------------------------------------===// 2053d81ceSMarshall Clow // 357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6053d81ceSMarshall Clow // 7053d81ceSMarshall Clow //===----------------------------------------------------------------------===// 8053d81ceSMarshall Clow 9*4fc50236SJoe Loser // UNSUPPORTED: !stdlib=libc++ && (c++03 || c++11 || c++14) 10*4fc50236SJoe Loser 11053d81ceSMarshall Clow // <string_view> 12053d81ceSMarshall Clow 13053d81ceSMarshall Clow // constexpr basic_string_view(const _CharT* _s) 14053d81ceSMarshall Clow // : __data (_s), __size(_Traits::length(_s)) {} 15053d81ceSMarshall Clow 16053d81ceSMarshall Clow #include <string_view> 17053d81ceSMarshall Clow #include <string> 18053d81ceSMarshall Clow #include <cassert> 19053d81ceSMarshall Clow 200f901c7eSStephan T. Lavavej #include "test_macros.h" 21cc89063bSNico Weber #include "constexpr_char_traits.h" 22053d81ceSMarshall Clow 23053d81ceSMarshall Clow template<typename CharT> StrLen(const CharT * s)24053d81ceSMarshall Clowsize_t StrLen ( const CharT *s ) { 25053d81ceSMarshall Clow size_t retVal = 0; 26053d81ceSMarshall Clow while ( *s != 0 ) { ++retVal; ++s; } 27053d81ceSMarshall Clow return retVal; 28053d81ceSMarshall Clow } 29053d81ceSMarshall Clow 30053d81ceSMarshall Clow template<typename CharT> test(const CharT * s)31053d81ceSMarshall Clowvoid test ( const CharT *s ) { 32ac2b3e3aSMarshall Clow typedef std::basic_string_view<CharT> SV; 33ac2b3e3aSMarshall Clow // I'd love to do this, but it would require traits::length() to be noexcept 34ac2b3e3aSMarshall Clow // LIBCPP_ASSERT_NOEXCEPT(SV(s)); 35ac2b3e3aSMarshall Clow 36ac2b3e3aSMarshall Clow SV sv1 ( s ); 37053d81ceSMarshall Clow assert ( sv1.size() == StrLen( s )); 38053d81ceSMarshall Clow assert ( sv1.data() == s ); 39053d81ceSMarshall Clow } 40053d81ceSMarshall Clow 41053d81ceSMarshall Clow main(int,char **)422df59c50SJF Bastienint main(int, char**) { 43053d81ceSMarshall Clow 44053d81ceSMarshall Clow test ( "QBCDE" ); 45053d81ceSMarshall Clow test ( "A" ); 46053d81ceSMarshall Clow test ( "" ); 47053d81ceSMarshall Clow 48053d81ceSMarshall Clow test ( L"QBCDE" ); 49053d81ceSMarshall Clow test ( L"A" ); 50053d81ceSMarshall Clow test ( L"" ); 51053d81ceSMarshall Clow 52053d81ceSMarshall Clow #if TEST_STD_VER >= 11 53053d81ceSMarshall Clow test ( u"QBCDE" ); 54053d81ceSMarshall Clow test ( u"A" ); 55053d81ceSMarshall Clow test ( u"" ); 56053d81ceSMarshall Clow 57053d81ceSMarshall Clow test ( U"QBCDE" ); 58053d81ceSMarshall Clow test ( U"A" ); 59053d81ceSMarshall Clow test ( U"" ); 60053d81ceSMarshall Clow #endif 61053d81ceSMarshall Clow 620f901c7eSStephan T. Lavavej #if TEST_STD_VER > 11 63053d81ceSMarshall Clow { 64053d81ceSMarshall Clow constexpr std::basic_string_view<char, constexpr_char_traits<char>> sv1 ( "ABCDE" ); 65053d81ceSMarshall Clow static_assert ( sv1.size() == 5, ""); 66053d81ceSMarshall Clow } 67053d81ceSMarshall Clow #endif 682df59c50SJF Bastien 692df59c50SJF Bastien return 0; 70053d81ceSMarshall Clow } 71