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