1053d81ceSMarshall Clow //===----------------------------------------------------------------------===// 2053d81ceSMarshall Clow // 3053d81ceSMarshall Clow // The LLVM Compiler Infrastructure 4053d81ceSMarshall Clow // 5053d81ceSMarshall Clow // This file is dual licensed under the MIT and the University of Illinois Open 6053d81ceSMarshall Clow // Source Licenses. See LICENSE.TXT for details. 7053d81ceSMarshall Clow // 8053d81ceSMarshall Clow //===----------------------------------------------------------------------===// 9053d81ceSMarshall Clow 10053d81ceSMarshall Clow 11053d81ceSMarshall Clow // <string_view> 12053d81ceSMarshall Clow 13053d81ceSMarshall Clow // void remove_prefix(size_type _n) 14053d81ceSMarshall Clow 15053d81ceSMarshall Clow #include <string_view> 16053d81ceSMarshall Clow #include <cassert> 17053d81ceSMarshall Clow #include <iostream> 18053d81ceSMarshall Clow 19053d81ceSMarshall Clow #include "test_macros.h" 20053d81ceSMarshall Clow 21053d81ceSMarshall Clow template<typename CharT> 22053d81ceSMarshall Clow void test ( const CharT *s, size_t len ) { 23053d81ceSMarshall Clow typedef std::basic_string_view<CharT> SV; 24053d81ceSMarshall Clow { 25053d81ceSMarshall Clow SV sv1 ( s ); 26053d81ceSMarshall Clow assert ( sv1.size() == len ); 27053d81ceSMarshall Clow assert ( sv1.data() == s ); 28053d81ceSMarshall Clow 29053d81ceSMarshall Clow if ( len > 0 ) { 30053d81ceSMarshall Clow sv1.remove_prefix ( 1 ); 31053d81ceSMarshall Clow assert ( sv1.size() == (len - 1)); 32053d81ceSMarshall Clow assert ( sv1.data() == (s + 1)); 33053d81ceSMarshall Clow sv1.remove_prefix ( len - 1 ); 34053d81ceSMarshall Clow } 35053d81ceSMarshall Clow 36053d81ceSMarshall Clow assert ( sv1.size() == 0 ); 37053d81ceSMarshall Clow sv1.remove_prefix ( 0 ); 38053d81ceSMarshall Clow assert ( sv1.size() == 0 ); 39053d81ceSMarshall Clow } 40053d81ceSMarshall Clow } 41053d81ceSMarshall Clow 42*0f901c7eSStephan T. Lavavej #if TEST_STD_VER > 11 43053d81ceSMarshall Clow constexpr size_t test_ce ( size_t n, size_t k ) { 44053d81ceSMarshall Clow typedef std::basic_string_view<char> SV; 45053d81ceSMarshall Clow SV sv1{ "ABCDEFGHIJKL", n }; 46053d81ceSMarshall Clow sv1.remove_prefix ( k ); 47053d81ceSMarshall Clow return sv1.size(); 48053d81ceSMarshall Clow } 49053d81ceSMarshall Clow #endif 50053d81ceSMarshall Clow 51053d81ceSMarshall Clow int main () { 52053d81ceSMarshall Clow test ( "ABCDE", 5 ); 53053d81ceSMarshall Clow test ( "a", 1 ); 54053d81ceSMarshall Clow test ( "", 0 ); 55053d81ceSMarshall Clow 56053d81ceSMarshall Clow test ( L"ABCDE", 5 ); 57053d81ceSMarshall Clow test ( L"a", 1 ); 58053d81ceSMarshall Clow test ( L"", 0 ); 59053d81ceSMarshall Clow 60053d81ceSMarshall Clow #if TEST_STD_VER >= 11 61053d81ceSMarshall Clow test ( u"ABCDE", 5 ); 62053d81ceSMarshall Clow test ( u"a", 1 ); 63053d81ceSMarshall Clow test ( u"", 0 ); 64053d81ceSMarshall Clow 65053d81ceSMarshall Clow test ( U"ABCDE", 5 ); 66053d81ceSMarshall Clow test ( U"a", 1 ); 67053d81ceSMarshall Clow test ( U"", 0 ); 68053d81ceSMarshall Clow #endif 69053d81ceSMarshall Clow 70*0f901c7eSStephan T. Lavavej #if TEST_STD_VER > 11 71053d81ceSMarshall Clow { 72053d81ceSMarshall Clow static_assert ( test_ce ( 5, 0 ) == 5, "" ); 73053d81ceSMarshall Clow static_assert ( test_ce ( 5, 1 ) == 4, "" ); 74053d81ceSMarshall Clow static_assert ( test_ce ( 5, 5 ) == 0, "" ); 75053d81ceSMarshall Clow static_assert ( test_ce ( 9, 3 ) == 6, "" ); 76053d81ceSMarshall Clow } 77053d81ceSMarshall Clow #endif 78053d81ceSMarshall Clow } 79