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 CharT, class Sentinel>
24 constexpr void test() {
25   auto val = MAKE_STRING_VIEW(CharT, "test");
26   auto sv = std::basic_string_view(val.begin(), Sentinel(val.end()));
27   ASSERT_SAME_TYPE(decltype(sv), std::basic_string_view<CharT>);
28   assert(sv.size() == val.size());
29   assert(sv.data() == val.data());
30 }
31 
32 constexpr void test() {
33   test<char, char*>();
34 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
35   test<wchar_t, wchar_t*>();
36 #endif
37   test<char8_t, char8_t*>();
38   test<char16_t, char16_t*>();
39   test<char32_t, char32_t*>();
40   test<char, const char*>();
41   test<char, sized_sentinel<const char*>>();
42 }
43 
44 int main(int, char**) {
45   test();
46 
47   return 0;
48 }
49 
50