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 
9*4fc50236SJoe Loser // UNSUPPORTED: !stdlib=libc++ && (c++03 || c++11 || c++14)
10*4fc50236SJoe Loser 
11053d81ceSMarshall Clow // <string_view>
12053d81ceSMarshall Clow 
13053d81ceSMarshall Clow //  constexpr basic_string_view(const _CharT* _s, size_type _len)
14053d81ceSMarshall Clow //      : __data (_s), __size(_len) {}
15053d81ceSMarshall Clow 
16053d81ceSMarshall Clow #include <string_view>
17053d81ceSMarshall Clow #include <string>
18053d81ceSMarshall Clow #include <cassert>
19053d81ceSMarshall Clow 
20053d81ceSMarshall Clow #include "test_macros.h"
21053d81ceSMarshall Clow 
22053d81ceSMarshall Clow template<typename CharT>
test(const CharT * s,size_t sz)23053d81ceSMarshall Clow void test ( const CharT *s, size_t sz ) {
24053d81ceSMarshall Clow     {
25ac2b3e3aSMarshall Clow     typedef std::basic_string_view<CharT> SV;
26ac2b3e3aSMarshall Clow     LIBCPP_ASSERT_NOEXCEPT(SV(s, sz));
27ac2b3e3aSMarshall Clow 
28ac2b3e3aSMarshall Clow     SV sv1 ( s, sz );
29053d81ceSMarshall Clow     assert ( sv1.size() == sz );
30053d81ceSMarshall Clow     assert ( sv1.data() == s );
31053d81ceSMarshall Clow     }
32053d81ceSMarshall Clow }
33053d81ceSMarshall Clow 
main(int,char **)342df59c50SJF Bastien int main(int, char**) {
35053d81ceSMarshall Clow 
36053d81ceSMarshall Clow     test ( "QBCDE", 5 );
37053d81ceSMarshall Clow     test ( "QBCDE", 2 );
38053d81ceSMarshall Clow     test ( "", 0 );
390f901c7eSStephan T. Lavavej #if TEST_STD_VER > 11
40053d81ceSMarshall Clow     {
41053d81ceSMarshall Clow     constexpr const char *s = "QBCDE";
42053d81ceSMarshall Clow     constexpr std::basic_string_view<char> sv1 ( s, 2 );
43053d81ceSMarshall Clow     static_assert ( sv1.size() == 2, "" );
44053d81ceSMarshall Clow     static_assert ( sv1.data() == s, "" );
45053d81ceSMarshall Clow     }
46053d81ceSMarshall Clow #endif
47053d81ceSMarshall Clow 
48053d81ceSMarshall Clow     test ( L"QBCDE", 5 );
49053d81ceSMarshall Clow     test ( L"QBCDE", 2 );
50053d81ceSMarshall Clow     test ( L"", 0 );
510f901c7eSStephan T. Lavavej #if TEST_STD_VER > 11
52053d81ceSMarshall Clow     {
53053d81ceSMarshall Clow     constexpr const wchar_t *s = L"QBCDE";
54053d81ceSMarshall Clow     constexpr std::basic_string_view<wchar_t> sv1 ( s, 2 );
55053d81ceSMarshall Clow     static_assert ( sv1.size() == 2, "" );
56053d81ceSMarshall Clow     static_assert ( sv1.data() == s, "" );
57053d81ceSMarshall Clow     }
58053d81ceSMarshall Clow #endif
59053d81ceSMarshall Clow 
60053d81ceSMarshall Clow #if TEST_STD_VER >= 11
61053d81ceSMarshall Clow     test ( u"QBCDE", 5 );
62053d81ceSMarshall Clow     test ( u"QBCDE", 2 );
63053d81ceSMarshall Clow     test ( u"", 0 );
640f901c7eSStephan T. Lavavej #if TEST_STD_VER > 11
65053d81ceSMarshall Clow     {
66053d81ceSMarshall Clow     constexpr const char16_t *s = u"QBCDE";
67053d81ceSMarshall Clow     constexpr std::basic_string_view<char16_t> sv1 ( s, 2 );
68053d81ceSMarshall Clow     static_assert ( sv1.size() == 2, "" );
69053d81ceSMarshall Clow     static_assert ( sv1.data() == s, "" );
70053d81ceSMarshall Clow     }
71053d81ceSMarshall Clow #endif
72053d81ceSMarshall Clow 
73053d81ceSMarshall Clow     test ( U"QBCDE", 5 );
74053d81ceSMarshall Clow     test ( U"QBCDE", 2 );
75053d81ceSMarshall Clow     test ( U"", 0 );
760f901c7eSStephan T. Lavavej #if TEST_STD_VER > 11
77053d81ceSMarshall Clow     {
78053d81ceSMarshall Clow     constexpr const char32_t *s = U"QBCDE";
79053d81ceSMarshall Clow     constexpr std::basic_string_view<char32_t> sv1 ( s, 2 );
80053d81ceSMarshall Clow     static_assert ( sv1.size() == 2, "" );
81053d81ceSMarshall Clow     static_assert ( sv1.data() == s, "" );
82053d81ceSMarshall Clow     }
83053d81ceSMarshall Clow #endif
84053d81ceSMarshall Clow #endif
852df59c50SJF Bastien 
862df59c50SJF Bastien   return 0;
87053d81ceSMarshall Clow }
88