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