1053d81ceSMarshall Clow //===----------------------------------------------------------------------===//
2053d81ceSMarshall Clow //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6053d81ceSMarshall Clow //
7053d81ceSMarshall Clow //===----------------------------------------------------------------------===//
8053d81ceSMarshall Clow 
9053d81ceSMarshall Clow // <string_view>
10053d81ceSMarshall Clow 
11053d81ceSMarshall Clow // template<class Allocator>
12053d81ceSMarshall Clow // basic_string_view(const basic_string<_CharT, _Traits, Allocator>& _str) noexcept
13053d81ceSMarshall Clow 
14053d81ceSMarshall Clow 
15053d81ceSMarshall Clow #include <string_view>
16053d81ceSMarshall Clow #include <string>
17053d81ceSMarshall Clow #include <cassert>
18053d81ceSMarshall Clow 
19053d81ceSMarshall Clow #include "test_macros.h"
20053d81ceSMarshall Clow 
21053d81ceSMarshall Clow struct dummy_char_traits : public std::char_traits<char> {};
22053d81ceSMarshall Clow 
23053d81ceSMarshall Clow template<typename CharT, typename Traits>
24053d81ceSMarshall Clow void test ( const std::basic_string<CharT, Traits> &str ) {
25ac2b3e3aSMarshall Clow     typedef std::basic_string_view<CharT, Traits> SV;
26ac2b3e3aSMarshall Clow     ASSERT_NOEXCEPT(SV(str));
27ac2b3e3aSMarshall Clow 
28ac2b3e3aSMarshall Clow     SV sv1 ( str );
29053d81ceSMarshall Clow     assert ( sv1.size() == str.size());
30053d81ceSMarshall Clow     assert ( sv1.data() == str.data());
31053d81ceSMarshall Clow }
32053d81ceSMarshall Clow 
332df59c50SJF Bastien int main(int, char**) {
34053d81ceSMarshall Clow 
35053d81ceSMarshall Clow     test ( std::string("QBCDE") );
36053d81ceSMarshall Clow     test ( std::string("") );
37053d81ceSMarshall Clow     test ( std::string() );
38053d81ceSMarshall Clow 
39*f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
40053d81ceSMarshall Clow     test ( std::wstring(L"QBCDE") );
41053d81ceSMarshall Clow     test ( std::wstring(L"") );
42053d81ceSMarshall Clow     test ( std::wstring() );
43*f4c1258dSLouis Dionne #endif
44053d81ceSMarshall Clow 
457dad0bd6SMarshall Clow #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
467dad0bd6SMarshall Clow     test ( std::u8string{u8"QBCDE"} );
477dad0bd6SMarshall Clow     test ( std::u8string{u8""} );
487dad0bd6SMarshall Clow     test ( std::u8string{} );
497dad0bd6SMarshall Clow #endif
507dad0bd6SMarshall Clow 
51053d81ceSMarshall Clow #if TEST_STD_VER >= 11
52053d81ceSMarshall Clow     test ( std::u16string{u"QBCDE"} );
53053d81ceSMarshall Clow     test ( std::u16string{u""} );
54053d81ceSMarshall Clow     test ( std::u16string{} );
55053d81ceSMarshall Clow 
56053d81ceSMarshall Clow     test ( std::u32string{U"QBCDE"} );
57053d81ceSMarshall Clow     test ( std::u32string{U""} );
58053d81ceSMarshall Clow     test ( std::u32string{} );
59053d81ceSMarshall Clow #endif
60053d81ceSMarshall Clow 
61053d81ceSMarshall Clow     test ( std::basic_string<char, dummy_char_traits>("QBCDE") );
62053d81ceSMarshall Clow     test ( std::basic_string<char, dummy_char_traits>("") );
63053d81ceSMarshall Clow     test ( std::basic_string<char, dummy_char_traits>() );
64053d81ceSMarshall Clow 
652df59c50SJF Bastien 
662df59c50SJF Bastien   return 0;
67053d81ceSMarshall Clow }
68