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
9c16b13ebSJoe Loser
10c16b13ebSJoe Loser // <string_view>
11c16b13ebSJoe Loser
12c16b13ebSJoe Loser // template <contiguous_iterator _It, sized_sentinel_for<_It> _End>
13c16b13ebSJoe Loser // basic_string_view(_It, _End) -> basic_string_view<iter_value_t<_It>>;
14c16b13ebSJoe Loser
15c16b13ebSJoe Loser #include <string_view>
16c16b13ebSJoe Loser #include <cassert>
17c16b13ebSJoe Loser
18c16b13ebSJoe Loser #include "make_string.h"
19c16b13ebSJoe Loser #include "test_macros.h"
20c16b13ebSJoe Loser #include "test_iterators.h"
21c16b13ebSJoe Loser
22*2d653b7eSCasey Carter template<class It, class Sentinel, class CharT>
test_ctad(std::basic_string_view<CharT> val)23*2d653b7eSCasey Carter constexpr void test_ctad(std::basic_string_view<CharT> val) {
24*2d653b7eSCasey Carter auto sv = std::basic_string_view(It(val.data()), Sentinel(It(val.data() + val.size())));
25c16b13ebSJoe Loser ASSERT_SAME_TYPE(decltype(sv), std::basic_string_view<CharT>);
26c16b13ebSJoe Loser assert(sv.data() == val.data());
27*2d653b7eSCasey Carter assert(sv.size() == val.size());
28*2d653b7eSCasey Carter }
29*2d653b7eSCasey Carter
30*2d653b7eSCasey Carter template<class CharT>
test_with_char()31*2d653b7eSCasey Carter constexpr void test_with_char() {
32*2d653b7eSCasey Carter const auto val = MAKE_STRING_VIEW(CharT, "test");
33*2d653b7eSCasey Carter test_ctad<CharT*, CharT*>(val);
34*2d653b7eSCasey Carter test_ctad<CharT*, const CharT*>(val);
35*2d653b7eSCasey Carter test_ctad<const CharT*, CharT*>(val);
36*2d653b7eSCasey Carter test_ctad<const CharT*, sized_sentinel<const CharT*>>(val);
37*2d653b7eSCasey Carter test_ctad<contiguous_iterator<const CharT*>, contiguous_iterator<const CharT*>>(val);
38*2d653b7eSCasey Carter test_ctad<contiguous_iterator<const CharT*>, sized_sentinel<contiguous_iterator<const CharT*>>>(val);
39c16b13ebSJoe Loser }
40c16b13ebSJoe Loser
test()41c16b13ebSJoe Loser constexpr void test() {
42*2d653b7eSCasey Carter test_with_char<char>();
43c16b13ebSJoe Loser #ifndef TEST_HAS_NO_WIDE_CHARACTERS
44*2d653b7eSCasey Carter test_with_char<wchar_t>();
45c16b13ebSJoe Loser #endif
46*2d653b7eSCasey Carter test_with_char<char8_t>();
47*2d653b7eSCasey Carter test_with_char<char16_t>();
48*2d653b7eSCasey Carter test_with_char<char32_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 }
56