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 // [string.view.capacity], capacity
14 // constexpr size_type size() const noexcept;
15 // constexpr size_type length() const noexcept;
16 // constexpr size_type max_size() const noexcept;
17 // constexpr bool empty() const noexcept;
18
19 #include <experimental/string_view>
20 #include <cassert>
21
22 template<typename SV>
test1()23 void test1 () {
24 #if _LIBCPP_STD_VER > 11
25 {
26 constexpr SV sv1;
27 static_assert ( sv1.size() == 0, "" );
28 static_assert ( sv1.empty(), "");
29 static_assert ( sv1.size() == sv1.length(), "" );
30 static_assert ( sv1.max_size() > sv1.size(), "");
31 }
32 #endif
33
34 {
35 SV sv1;
36 assert ( sv1.size() == 0 );
37 assert ( sv1.empty());
38 assert ( sv1.size() == sv1.length());
39 assert ( sv1.max_size() > sv1.size());
40 }
41 }
42
43 template<typename CharT>
test2(const CharT * s,size_t len)44 void test2 ( const CharT *s, size_t len ) {
45 {
46 std::experimental::basic_string_view<CharT> sv1 ( s );
47 assert ( sv1.size() == len );
48 assert ( sv1.data() == s );
49 assert ( sv1.empty() == (len == 0));
50 assert ( sv1.size() == sv1.length());
51 assert ( sv1.max_size() > sv1.size());
52 }
53 }
54
main()55 int main () {
56 typedef std::experimental::string_view string_view;
57 typedef std::experimental::u16string_view u16string_view;
58 typedef std::experimental::u32string_view u32string_view;
59 typedef std::experimental::wstring_view wstring_view;
60
61 test1<string_view> ();
62 test1<u16string_view> ();
63 test1<u32string_view> ();
64 test1<wstring_view> ();
65
66 test2 ( "ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE", 105 );
67 test2 ( "ABCDE", 5 );
68 test2 ( "a", 1 );
69 test2 ( "", 0 );
70
71 test2 ( L"ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE", 105 );
72 test2 ( L"ABCDE", 5 );
73 test2 ( L"a", 1 );
74 test2 ( L"", 0 );
75
76 #if __cplusplus >= 201103L
77 test2 ( u"ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE", 105 );
78 test2 ( u"ABCDE", 5 );
79 test2 ( u"a", 1 );
80 test2 ( u"", 0 );
81
82 test2 ( U"ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE", 105 );
83 test2 ( U"ABCDE", 5 );
84 test2 ( U"a", 1 );
85 test2 ( U"", 0 );
86 #endif
87 }
88