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 10053d81ceSMarshall Clow // <string_view> 11053d81ceSMarshall Clow 12053d81ceSMarshall Clow // template<class Allocator> 13053d81ceSMarshall Clow // basic_string_view(const basic_string<_CharT, _Traits, Allocator>& _str) noexcept 14053d81ceSMarshall Clow 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> 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 34*2df59c50SJF 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 40053d81ceSMarshall Clow test ( std::wstring(L"QBCDE") ); 41053d81ceSMarshall Clow test ( std::wstring(L"") ); 42053d81ceSMarshall Clow test ( std::wstring() ); 43053d81ceSMarshall Clow 447dad0bd6SMarshall Clow #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L 457dad0bd6SMarshall Clow test ( std::u8string{u8"QBCDE"} ); 467dad0bd6SMarshall Clow test ( std::u8string{u8""} ); 477dad0bd6SMarshall Clow test ( std::u8string{} ); 487dad0bd6SMarshall Clow #endif 497dad0bd6SMarshall Clow 50053d81ceSMarshall Clow #if TEST_STD_VER >= 11 51053d81ceSMarshall Clow test ( std::u16string{u"QBCDE"} ); 52053d81ceSMarshall Clow test ( std::u16string{u""} ); 53053d81ceSMarshall Clow test ( std::u16string{} ); 54053d81ceSMarshall Clow 55053d81ceSMarshall Clow test ( std::u32string{U"QBCDE"} ); 56053d81ceSMarshall Clow test ( std::u32string{U""} ); 57053d81ceSMarshall Clow test ( std::u32string{} ); 58053d81ceSMarshall Clow #endif 59053d81ceSMarshall Clow 60053d81ceSMarshall Clow test ( std::basic_string<char, dummy_char_traits>("QBCDE") ); 61053d81ceSMarshall Clow test ( std::basic_string<char, dummy_char_traits>("") ); 62053d81ceSMarshall Clow test ( std::basic_string<char, dummy_char_traits>() ); 63053d81ceSMarshall Clow 64*2df59c50SJF Bastien 65*2df59c50SJF Bastien return 0; 66053d81ceSMarshall Clow } 67