blob: b2bf8ed7198b3c229f9489d1a6b746fdbec84380 [file] [log] [blame]
Marshall Clowcddeb752017-01-23 19:53:28 +00001//===----------------------------------------------------------------------===//
2//
Chandler Carruth57b08b02019-01-19 10:56:40 +00003// 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 Clowcddeb752017-01-23 19:53:28 +00006//
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
19template<typename T>
20#if TEST_STD_VER > 11
21constexpr
22#endif
23bool 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 Bastien2df59c52019-02-04 20:31:13 +000032int main(int, char**) {
Marshall Clowcddeb752017-01-23 19:53:28 +000033
Marshall Clow7dad0bd2018-12-11 04:35:44 +000034 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 Clow71f1ec72018-07-12 02:55:01 +000038#if TEST_STD_VER >= 11
Marshall Clowb360cbc2018-07-11 21:22:13 +000039#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
Marshall Clow7dad0bd2018-12-11 04:35:44 +000040 assert( test<std::u16string_view> ( u"1234"));
41 assert( test<std::u32string_view> ( U"1234"));
Marshall Clowcddeb752017-01-23 19:53:28 +000042#endif
Marshall Clow71f1ec72018-07-12 02:55:01 +000043#endif
Marshall Clow7dad0bd2018-12-11 04:35:44 +000044 assert( test<std::wstring_view> ( L"1234"));
Marshall Clowcddeb752017-01-23 19:53:28 +000045
46#if TEST_STD_VER > 11
Marshall Clow7dad0bd2018-12-11 04:35:44 +000047 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 Clowcddeb752017-01-23 19:53:28 +000050#endif
Marshall Clow7dad0bd2018-12-11 04:35:44 +000051#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 Clowcddeb752017-01-23 19:53:28 +000056#endif
JF Bastien2df59c52019-02-04 20:31:13 +000057
58 return 0;
Marshall Clowcddeb752017-01-23 19:53:28 +000059}