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 // constexpr const _CharT* data() const noexcept;
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     std::basic_string_view<CharT> sv ( s, len );
21     assert ( sv.length() == len );
22     assert ( sv.data() == s );
23 #if TEST_STD_VER > 14
24 //  make sure we pick up std::data, too!
25     assert ( sv.data() == std::data(sv));
26 #endif
27     }
28 
29 int main(int, char**) {
30     test ( "ABCDE", 5 );
31     test ( "a", 1 );
32 
33     test ( L"ABCDE", 5 );
34     test ( L"a", 1 );
35 
36 #if TEST_STD_VER >= 11
37     test ( u"ABCDE", 5 );
38     test ( u"a", 1 );
39 
40     test ( U"ABCDE", 5 );
41     test ( U"a", 1 );
42 #endif
43 
44 #if TEST_STD_VER > 11
45     {
46     constexpr const char *s = "ABC";
47     constexpr std::basic_string_view<char> sv( s, 2 );
48     static_assert( sv.length() ==  2,  "" );
49     static_assert( sv.data() == s, "" );
50     }
51 #endif
52 
53   return 0;
54 }
55