Marshall Clow | cddeb75 | 2017-01-23 19:53:28 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 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 |
Marshall Clow | cddeb75 | 2017-01-23 19:53:28 +0000 | [diff] [blame] | 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 | |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 32 | int main(int, char**) { |
Marshall Clow | cddeb75 | 2017-01-23 19:53:28 +0000 | [diff] [blame] | 33 | |
Marshall Clow | 7dad0bd | 2018-12-11 04:35:44 +0000 | [diff] [blame] | 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 |
Marshall Clow | 71f1ec7 | 2018-07-12 02:55:01 +0000 | [diff] [blame] | 38 | #if TEST_STD_VER >= 11 |
Marshall Clow | b360cbc | 2018-07-11 21:22:13 +0000 | [diff] [blame] | 39 | #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS |
Marshall Clow | 7dad0bd | 2018-12-11 04:35:44 +0000 | [diff] [blame] | 40 | assert( test<std::u16string_view> ( u"1234")); |
| 41 | assert( test<std::u32string_view> ( U"1234")); |
Marshall Clow | cddeb75 | 2017-01-23 19:53:28 +0000 | [diff] [blame] | 42 | #endif |
Marshall Clow | 71f1ec7 | 2018-07-12 02:55:01 +0000 | [diff] [blame] | 43 | #endif |
Marshall Clow | 7dad0bd | 2018-12-11 04:35:44 +0000 | [diff] [blame] | 44 | assert( test<std::wstring_view> ( L"1234")); |
Marshall Clow | cddeb75 | 2017-01-23 19:53:28 +0000 | [diff] [blame] | 45 | |
| 46 | #if TEST_STD_VER > 11 |
Marshall Clow | 7dad0bd | 2018-12-11 04:35:44 +0000 | [diff] [blame] | 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}), ""); |
Marshall Clow | cddeb75 | 2017-01-23 19:53:28 +0000 | [diff] [blame] | 50 | #endif |
Marshall Clow | 7dad0bd | 2018-12-11 04:35:44 +0000 | [diff] [blame] | 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}), ""); |
Marshall Clow | cddeb75 | 2017-01-23 19:53:28 +0000 | [diff] [blame] | 56 | #endif |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 57 | |
| 58 | return 0; |
Marshall Clow | cddeb75 | 2017-01-23 19:53:28 +0000 | [diff] [blame] | 59 | } |