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 // UNSUPPORTED: !stdlib=libc++ && (c++03 || c++11 || c++14)
10 
11 // <string_view>
12 
13 // constexpr const _CharT* data() const noexcept;
14 
15 #include <string_view>
16 #include <cassert>
17 
18 #include "test_macros.h"
19 
20 template <typename CharT>
21 void test ( const CharT *s, size_t len ) {
22     std::basic_string_view<CharT> sv ( s, len );
23     assert ( sv.length() == len );
24     assert ( sv.data() == s );
25 #if TEST_STD_VER > 14
26 //  make sure we pick up std::data, too!
27     assert ( sv.data() == std::data(sv));
28 #endif
29     }
30 
31 int main(int, char**) {
32     test ( "ABCDE", 5 );
33     test ( "a", 1 );
34 
35     test ( L"ABCDE", 5 );
36     test ( L"a", 1 );
37 
38 #if TEST_STD_VER >= 11
39     test ( u"ABCDE", 5 );
40     test ( u"a", 1 );
41 
42     test ( U"ABCDE", 5 );
43     test ( U"a", 1 );
44 #endif
45 
46 #if TEST_STD_VER > 11
47     {
48     constexpr const char *s = "ABC";
49     constexpr std::basic_string_view<char> sv( s, 2 );
50     static_assert( sv.length() ==  2,  "" );
51     static_assert( sv.data() == s, "" );
52     }
53 #endif
54 
55   return 0;
56 }
57