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