1c16b13ebSJoe Loser //===----------------------------------------------------------------------===//
2c16b13ebSJoe Loser //
3c16b13ebSJoe Loser // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4c16b13ebSJoe Loser // See https://llvm.org/LICENSE.txt for license information.
5c16b13ebSJoe Loser // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6c16b13ebSJoe Loser //
7c16b13ebSJoe Loser //===----------------------------------------------------------------------===//
8c16b13ebSJoe Loser // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
9*53406fb6SArthur O'Dwyer // UNSUPPORTED: libcpp-has-no-incomplete-ranges
10c16b13ebSJoe Loser
11c16b13ebSJoe Loser // <string_view>
12c16b13ebSJoe Loser
13c16b13ebSJoe Loser // template<class Range>
14c16b13ebSJoe Loser // basic_string_view(Range&&) -> basic_string_view<ranges::range_value_t<Range>>; // C++23
15c16b13ebSJoe Loser
16c16b13ebSJoe Loser #include <string_view>
17c16b13ebSJoe Loser #include <cassert>
18c16b13ebSJoe Loser
19c16b13ebSJoe Loser #include "make_string.h"
20c16b13ebSJoe Loser #include "test_iterators.h"
21c16b13ebSJoe Loser #include "test_macros.h"
22c16b13ebSJoe Loser
23c16b13ebSJoe Loser template<class CharT>
test()24c16b13ebSJoe Loser void test() {
25c16b13ebSJoe Loser auto val = MAKE_STRING(CharT, "test");
26c16b13ebSJoe Loser auto sv = std::basic_string_view(val);
27c16b13ebSJoe Loser ASSERT_SAME_TYPE(decltype(sv), std::basic_string_view<CharT>);
28c16b13ebSJoe Loser assert(sv.size() == val.size());
29c16b13ebSJoe Loser assert(sv.data() == val.data());
30c16b13ebSJoe Loser }
31c16b13ebSJoe Loser
test()32c16b13ebSJoe Loser void test() {
33c16b13ebSJoe Loser test<char>();
34c16b13ebSJoe Loser #ifndef TEST_HAS_NO_WIDE_CHARACTERS
35c16b13ebSJoe Loser test<wchar_t>();
36c16b13ebSJoe Loser #endif
37c16b13ebSJoe Loser test<char8_t>();
38c16b13ebSJoe Loser test<char16_t>();
39c16b13ebSJoe Loser test<char32_t>();
40c16b13ebSJoe Loser test<char>();
41c16b13ebSJoe Loser
42c16b13ebSJoe Loser struct Widget {
43c16b13ebSJoe Loser const char16_t *data_ = u"foo";
44c16b13ebSJoe Loser contiguous_iterator<const char16_t*> begin() const { return contiguous_iterator<const char16_t*>(data_); }
45c16b13ebSJoe Loser contiguous_iterator<const char16_t*> end() const { return contiguous_iterator<const char16_t*>(data_ + 3); }
46c16b13ebSJoe Loser };
47c16b13ebSJoe Loser std::basic_string_view bsv = Widget();
48c16b13ebSJoe Loser ASSERT_SAME_TYPE(decltype(bsv), std::basic_string_view<char16_t>);
49c16b13ebSJoe Loser }
50c16b13ebSJoe Loser
main(int,char **)51c16b13ebSJoe Loser int main(int, char**) {
52c16b13ebSJoe Loser test();
53c16b13ebSJoe Loser
54c16b13ebSJoe Loser return 0;
55c16b13ebSJoe Loser }
56c16b13ebSJoe Loser
57