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 // <string_view>
10 
11 // constexpr basic_string_view& operator=(const basic_string_view &) noexcept = default;
12 
13 #include <string_view>
14 #include <cassert>
15 
16 #include "test_macros.h"
17 
18 template<typename T>
19 #if TEST_STD_VER > 11
20 constexpr
21 #endif
22 bool test (T sv0)
23     {
24     T sv1;
25     sv1 = sv0;
26 //  We can't just say "sv0 == sv1" here because string_view::compare
27 //  isn't constexpr until C++17, and we want to support back to C++14
28     return sv0.size() == sv1.size() && sv0.data() == sv1.data();
29     }
30 
31 int main(int, char**) {
32 
33     assert( test<std::string_view>    (  "1234"));
34 #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
35     assert( test<std::u8string_view>  (u8"1234"));
36 #endif
37 #if TEST_STD_VER >= 11
38 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
39     assert( test<std::u16string_view> ( u"1234"));
40     assert( test<std::u32string_view> ( U"1234"));
41 #endif
42 #endif
43     assert( test<std::wstring_view>   ( L"1234"));
44 
45 #if TEST_STD_VER > 11
46     static_assert( test<std::string_view>    ({  "abc", 3}), "");
47 #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
48     static_assert( test<std::u8string_view>  ({u8"abc", 3}), "");
49 #endif
50 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
51     static_assert( test<std::u16string_view> ({ u"abc", 3}), "");
52     static_assert( test<std::u32string_view> ({ U"abc", 3}), "");
53 #endif
54     static_assert( test<std::wstring_view>   ({ L"abc", 3}), "");
55 #endif
56 
57   return 0;
58 }
59