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 // <string_view> 10 11 // void remove_prefix(size_type _n) 12 13 #include <string_view> 14 #include <cassert> 15 16 #include "test_macros.h" 17 18 template<typename CharT> 19 void test ( const CharT *s, size_t len ) { 20 typedef std::basic_string_view<CharT> SV; 21 { 22 SV sv1 ( s ); 23 assert ( sv1.size() == len ); 24 assert ( sv1.data() == s ); 25 26 if ( len > 0 ) { 27 sv1.remove_prefix ( 1 ); 28 assert ( sv1.size() == (len - 1)); 29 assert ( sv1.data() == (s + 1)); 30 sv1.remove_prefix ( len - 1 ); 31 } 32 33 assert ( sv1.size() == 0 ); 34 sv1.remove_prefix ( 0 ); 35 assert ( sv1.size() == 0 ); 36 } 37 } 38 39 #if TEST_STD_VER > 11 40 constexpr size_t test_ce ( size_t n, size_t k ) { 41 typedef std::basic_string_view<char> SV; 42 SV sv1{ "ABCDEFGHIJKL", n }; 43 sv1.remove_prefix ( k ); 44 return sv1.size(); 45 } 46 #endif 47 48 int main(int, char**) { 49 test ( "ABCDE", 5 ); 50 test ( "a", 1 ); 51 test ( "", 0 ); 52 53 test ( L"ABCDE", 5 ); 54 test ( L"a", 1 ); 55 test ( L"", 0 ); 56 57 #if TEST_STD_VER >= 11 58 test ( u"ABCDE", 5 ); 59 test ( u"a", 1 ); 60 test ( u"", 0 ); 61 62 test ( U"ABCDE", 5 ); 63 test ( U"a", 1 ); 64 test ( U"", 0 ); 65 #endif 66 67 #if TEST_STD_VER > 11 68 { 69 static_assert ( test_ce ( 5, 0 ) == 5, "" ); 70 static_assert ( test_ce ( 5, 1 ) == 4, "" ); 71 static_assert ( test_ce ( 5, 5 ) == 0, "" ); 72 static_assert ( test_ce ( 9, 3 ) == 6, "" ); 73 } 74 #endif 75 76 return 0; 77 } 78