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 // UNSUPPORTED: !stdlib=libc++ && (c++03 || c++11 || c++14)
10
11 // <string_view>
12
13 // template<class Allocator>
14 // basic_string_view(const basic_string<_CharT, _Traits, Allocator>& _str) noexcept
15
16 #include <string_view>
17 #include <string>
18 #include <cassert>
19
20 #include "test_macros.h"
21
22 struct dummy_char_traits : public std::char_traits<char> {};
23
24 template<typename CharT, typename Traits>
test(const std::basic_string<CharT,Traits> & str)25 void test ( const std::basic_string<CharT, Traits> &str ) {
26 typedef std::basic_string_view<CharT, Traits> SV;
27 ASSERT_NOEXCEPT(SV(str));
28
29 SV sv1 ( str );
30 assert ( sv1.size() == str.size());
31 assert ( sv1.data() == str.data());
32 }
33
main(int,char **)34 int main(int, char**) {
35
36 test ( std::string("QBCDE") );
37 test ( std::string("") );
38 test ( std::string() );
39
40 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
41 test ( std::wstring(L"QBCDE") );
42 test ( std::wstring(L"") );
43 test ( std::wstring() );
44 #endif
45
46 #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
47 test ( std::u8string{u8"QBCDE"} );
48 test ( std::u8string{u8""} );
49 test ( std::u8string{} );
50 #endif
51
52 #if TEST_STD_VER >= 11
53 test ( std::u16string{u"QBCDE"} );
54 test ( std::u16string{u""} );
55 test ( std::u16string{} );
56
57 test ( std::u32string{U"QBCDE"} );
58 test ( std::u32string{U""} );
59 test ( std::u32string{} );
60 #endif
61
62 test ( std::basic_string<char, dummy_char_traits>("QBCDE") );
63 test ( std::basic_string<char, dummy_char_traits>("") );
64 test ( std::basic_string<char, dummy_char_traits>() );
65
66
67 return 0;
68 }
69