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 
9*4fc50236SJoe Loser // UNSUPPORTED: !stdlib=libc++ && (c++03 || c++11 || c++14)
10*4fc50236SJoe Loser 
11053d81ceSMarshall Clow // <string_view>
12053d81ceSMarshall Clow 
13053d81ceSMarshall Clow // template<class Allocator>
14053d81ceSMarshall Clow // basic_string_view(const basic_string<_CharT, _Traits, Allocator>& _str) noexcept
15053d81ceSMarshall Clow 
16053d81ceSMarshall Clow #include <string_view>
17053d81ceSMarshall Clow #include <string>
18053d81ceSMarshall Clow #include <cassert>
19053d81ceSMarshall Clow 
20053d81ceSMarshall Clow #include "test_macros.h"
21053d81ceSMarshall Clow 
22053d81ceSMarshall Clow struct dummy_char_traits : public std::char_traits<char> {};
23053d81ceSMarshall Clow 
24053d81ceSMarshall Clow template<typename CharT, typename Traits>
test(const std::basic_string<CharT,Traits> & str)25053d81ceSMarshall Clow void test ( const std::basic_string<CharT, Traits> &str ) {
26ac2b3e3aSMarshall Clow     typedef std::basic_string_view<CharT, Traits> SV;
27ac2b3e3aSMarshall Clow     ASSERT_NOEXCEPT(SV(str));
28ac2b3e3aSMarshall Clow 
29ac2b3e3aSMarshall Clow     SV sv1 ( str );
30053d81ceSMarshall Clow     assert ( sv1.size() == str.size());
31053d81ceSMarshall Clow     assert ( sv1.data() == str.data());
32053d81ceSMarshall Clow }
33053d81ceSMarshall Clow 
main(int,char **)342df59c50SJF Bastien int main(int, char**) {
35053d81ceSMarshall Clow 
36053d81ceSMarshall Clow     test ( std::string("QBCDE") );
37053d81ceSMarshall Clow     test ( std::string("") );
38053d81ceSMarshall Clow     test ( std::string() );
39053d81ceSMarshall Clow 
40f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
41053d81ceSMarshall Clow     test ( std::wstring(L"QBCDE") );
42053d81ceSMarshall Clow     test ( std::wstring(L"") );
43053d81ceSMarshall Clow     test ( std::wstring() );
44f4c1258dSLouis Dionne #endif
45053d81ceSMarshall Clow 
467dad0bd6SMarshall Clow #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
477dad0bd6SMarshall Clow     test ( std::u8string{u8"QBCDE"} );
487dad0bd6SMarshall Clow     test ( std::u8string{u8""} );
497dad0bd6SMarshall Clow     test ( std::u8string{} );
507dad0bd6SMarshall Clow #endif
517dad0bd6SMarshall Clow 
52053d81ceSMarshall Clow #if TEST_STD_VER >= 11
53053d81ceSMarshall Clow     test ( std::u16string{u"QBCDE"} );
54053d81ceSMarshall Clow     test ( std::u16string{u""} );
55053d81ceSMarshall Clow     test ( std::u16string{} );
56053d81ceSMarshall Clow 
57053d81ceSMarshall Clow     test ( std::u32string{U"QBCDE"} );
58053d81ceSMarshall Clow     test ( std::u32string{U""} );
59053d81ceSMarshall Clow     test ( std::u32string{} );
60053d81ceSMarshall Clow #endif
61053d81ceSMarshall Clow 
62053d81ceSMarshall Clow     test ( std::basic_string<char, dummy_char_traits>("QBCDE") );
63053d81ceSMarshall Clow     test ( std::basic_string<char, dummy_char_traits>("") );
64053d81ceSMarshall Clow     test ( std::basic_string<char, dummy_char_traits>() );
65053d81ceSMarshall Clow 
662df59c50SJF Bastien 
672df59c50SJF Bastien   return 0;
68053d81ceSMarshall Clow }
69