1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: !stdlib=libc++ && (c++03 || c++11 || c++14)
13 // template<class Allocator>
14 // basic_string_view(const basic_string<_CharT, _Traits, Allocator>& _str) noexcept
16 #include <string_view>
20 #include "test_macros.h"
22 struct dummy_char_traits
: public std::char_traits
<char> {};
24 template <typename CharT
, typename Traits
>
25 void test(const std::basic_string
<CharT
, Traits
>& str
) {
26 typedef std::basic_string_view
<CharT
, Traits
> SV
;
27 ASSERT_NOEXCEPT(SV(str
));
30 assert(sv1
.size() == str
.size());
31 assert(sv1
.data() == str
.data());
34 int main(int, char**) {
35 test(std::string("QBCDE"));
36 test(std::string(""));
39 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
40 test(std::wstring(L
"QBCDE"));
41 test(std::wstring(L
""));
45 #ifndef TEST_HAS_NO_CHAR8_T
46 test(std::u8string
{u8
"QBCDE"});
47 test(std::u8string
{u8
""});
48 test(std::u8string
{});
51 #if TEST_STD_VER >= 11
52 test(std::u16string
{u
"QBCDE"});
53 test(std::u16string
{u
""});
54 test(std::u16string
{});
56 test(std::u32string
{U
"QBCDE"});
57 test(std::u32string
{U
""});
58 test(std::u32string
{});
61 test(std::basic_string
<char, dummy_char_traits
>("QBCDE"));
62 test(std::basic_string
<char, dummy_char_traits
>(""));
63 test(std::basic_string
<char, dummy_char_traits
>());