1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: !stdlib=libc++ && (c++03 || c++11 || c++14)
13 // constexpr basic_string_view(const _CharT* _s, size_type _len)
14 // : __data (_s), __size(_len) {}
16 #include <string_view>
20 #include "test_macros.h"
22 template <typename CharT
>
23 void test(const CharT
* s
, std::size_t sz
) {
25 typedef std::basic_string_view
<CharT
> SV
;
26 LIBCPP_ASSERT_NOEXCEPT(SV(s
, sz
));
29 assert(sv1
.size() == sz
);
30 assert(sv1
.data() == s
);
34 int main(int, char**) {
40 constexpr const char* s
= "QBCDE";
41 constexpr std::basic_string_view
<char> sv1(s
, 2);
42 static_assert(sv1
.size() == 2, "");
43 static_assert(sv1
.data() == s
, "");
47 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
51 # if TEST_STD_VER > 11
53 constexpr const wchar_t* s
= L
"QBCDE";
54 constexpr std::basic_string_view
<wchar_t> sv1(s
, 2);
55 static_assert(sv1
.size() == 2, "");
56 static_assert(sv1
.data() == s
, "");
59 #endif // TEST_HAS_NO_WIDE_CHARACTERS
61 #if TEST_STD_VER >= 11
65 # if TEST_STD_VER > 11
67 constexpr const char16_t
* s
= u
"QBCDE";
68 constexpr std::basic_string_view
<char16_t
> sv1(s
, 2);
69 static_assert(sv1
.size() == 2, "");
70 static_assert(sv1
.data() == s
, "");
77 # if TEST_STD_VER > 11
79 constexpr const char32_t
* s
= U
"QBCDE";
80 constexpr std::basic_string_view
<char32_t
> sv1(s
, 2);
81 static_assert(sv1
.size() == 2, "");
82 static_assert(sv1
.data() == s
, "");