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