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 //  constexpr basic_string_view(const _CharT* _s, size_type _len)
14 //      : __data (_s), __size(_len) {}
15 
16 
17 #include <string_view>
18 #include <string>
19 #include <cassert>
20 
21 #include "test_macros.h"
22 
23 template<typename CharT>
test(const CharT * s,size_t sz)24 void test ( const CharT *s, size_t sz ) {
25     {
26     std::basic_string_view<CharT> sv1 ( s, sz );
27     assert ( sv1.size() == sz );
28     assert ( sv1.data() == s );
29     }
30 }
31 
main()32 int main () {
33 
34     test ( "QBCDE", 5 );
35     test ( "QBCDE", 2 );
36     test ( "", 0 );
37 #if TEST_STD_VER > 11
38     {
39     constexpr const char *s = "QBCDE";
40     constexpr std::basic_string_view<char> sv1 ( s, 2 );
41     static_assert ( sv1.size() == 2, "" );
42     static_assert ( sv1.data() == s, "" );
43     }
44 #endif
45 
46     test ( L"QBCDE", 5 );
47     test ( L"QBCDE", 2 );
48     test ( L"", 0 );
49 #if TEST_STD_VER > 11
50     {
51     constexpr const wchar_t *s = L"QBCDE";
52     constexpr std::basic_string_view<wchar_t> sv1 ( s, 2 );
53     static_assert ( sv1.size() == 2, "" );
54     static_assert ( sv1.data() == s, "" );
55     }
56 #endif
57 
58 #if TEST_STD_VER >= 11
59     test ( u"QBCDE", 5 );
60     test ( u"QBCDE", 2 );
61     test ( u"", 0 );
62 #if TEST_STD_VER > 11
63     {
64     constexpr const char16_t *s = u"QBCDE";
65     constexpr std::basic_string_view<char16_t> sv1 ( s, 2 );
66     static_assert ( sv1.size() == 2, "" );
67     static_assert ( sv1.data() == s, "" );
68     }
69 #endif
70 
71     test ( U"QBCDE", 5 );
72     test ( U"QBCDE", 2 );
73     test ( U"", 0 );
74 #if TEST_STD_VER > 11
75     {
76     constexpr const char32_t *s = U"QBCDE";
77     constexpr std::basic_string_view<char32_t> sv1 ( s, 2 );
78     static_assert ( sv1.size() == 2, "" );
79     static_assert ( sv1.data() == s, "" );
80     }
81 #endif
82 #endif
83 }
84