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