1053d81ceSMarshall Clow //===----------------------------------------------------------------------===//
2053d81ceSMarshall Clow //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6053d81ceSMarshall Clow //
7053d81ceSMarshall Clow //===----------------------------------------------------------------------===//
8053d81ceSMarshall Clow 
94fc50236SJoe Loser // UNSUPPORTED: !stdlib=libc++ && (c++03 || c++11 || c++14)
104fc50236SJoe Loser 
11053d81ceSMarshall Clow // <string_view>
12053d81ceSMarshall Clow 
13053d81ceSMarshall Clow // constexpr const _CharT* data() const noexcept;
14053d81ceSMarshall Clow 
15053d81ceSMarshall Clow #include <string_view>
16053d81ceSMarshall Clow #include <cassert>
17*3cd4531bSNikolas Klauser #include <iterator>
18053d81ceSMarshall Clow 
19053d81ceSMarshall Clow #include "test_macros.h"
20053d81ceSMarshall Clow 
21053d81ceSMarshall Clow template <typename CharT>
test(const CharT * s,size_t len)22053d81ceSMarshall Clow void test ( const CharT *s, size_t len ) {
23053d81ceSMarshall Clow     std::basic_string_view<CharT> sv ( s, len );
24053d81ceSMarshall Clow     assert ( sv.length() == len );
25053d81ceSMarshall Clow     assert ( sv.data() == s );
26aafb3151SMarshall Clow #if TEST_STD_VER > 14
27aafb3151SMarshall Clow //  make sure we pick up std::data, too!
28aafb3151SMarshall Clow     assert ( sv.data() == std::data(sv));
29aafb3151SMarshall Clow #endif
30053d81ceSMarshall Clow     }
31053d81ceSMarshall Clow 
main(int,char **)322df59c50SJF Bastien int main(int, char**) {
33053d81ceSMarshall Clow     test ( "ABCDE", 5 );
34053d81ceSMarshall Clow     test ( "a", 1 );
35053d81ceSMarshall Clow 
36053d81ceSMarshall Clow     test ( L"ABCDE", 5 );
37053d81ceSMarshall Clow     test ( L"a", 1 );
38053d81ceSMarshall Clow 
39053d81ceSMarshall Clow #if TEST_STD_VER >= 11
40053d81ceSMarshall Clow     test ( u"ABCDE", 5 );
41053d81ceSMarshall Clow     test ( u"a", 1 );
42053d81ceSMarshall Clow 
43053d81ceSMarshall Clow     test ( U"ABCDE", 5 );
44053d81ceSMarshall Clow     test ( U"a", 1 );
45053d81ceSMarshall Clow #endif
46053d81ceSMarshall Clow 
470f901c7eSStephan T. Lavavej #if TEST_STD_VER > 11
48053d81ceSMarshall Clow     {
49053d81ceSMarshall Clow     constexpr const char *s = "ABC";
50053d81ceSMarshall Clow     constexpr std::basic_string_view<char> sv( s, 2 );
51053d81ceSMarshall Clow     static_assert( sv.length() ==  2,  "" );
52053d81ceSMarshall Clow     static_assert( sv.data() == s, "" );
53053d81ceSMarshall Clow     }
54053d81ceSMarshall Clow #endif
552df59c50SJF Bastien 
562df59c50SJF Bastien   return 0;
57053d81ceSMarshall Clow }
58