1053d81ceSMarshall Clow //===----------------------------------------------------------------------===// 2053d81ceSMarshall Clow // 3053d81ceSMarshall Clow // The LLVM Compiler Infrastructure 4053d81ceSMarshall Clow // 5053d81ceSMarshall Clow // This file is dual licensed under the MIT and the University of Illinois Open 6053d81ceSMarshall Clow // Source Licenses. See LICENSE.TXT for details. 7053d81ceSMarshall Clow // 8053d81ceSMarshall Clow //===----------------------------------------------------------------------===// 9053d81ceSMarshall Clow 10053d81ceSMarshall Clow 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 17053d81ceSMarshall Clow #include <string_view> 18053d81ceSMarshall Clow #include <string> 19053d81ceSMarshall Clow #include <cassert> 20053d81ceSMarshall Clow 21053d81ceSMarshall Clow #include "test_macros.h" 22053d81ceSMarshall Clow 23053d81ceSMarshall Clow struct dummy_char_traits : public std::char_traits<char> {}; 24053d81ceSMarshall Clow 25053d81ceSMarshall Clow template<typename CharT, typename Traits> 26053d81ceSMarshall Clow void test ( const std::basic_string<CharT, Traits> &str ) { 27ac2b3e3aSMarshall Clow typedef std::basic_string_view<CharT, Traits> SV; 28ac2b3e3aSMarshall Clow ASSERT_NOEXCEPT(SV(str)); 29ac2b3e3aSMarshall Clow 30ac2b3e3aSMarshall Clow SV sv1 ( str ); 31053d81ceSMarshall Clow assert ( sv1.size() == str.size()); 32053d81ceSMarshall Clow assert ( sv1.data() == str.data()); 33053d81ceSMarshall Clow } 34053d81ceSMarshall Clow 35053d81ceSMarshall Clow int main () { 36053d81ceSMarshall Clow 37053d81ceSMarshall Clow test ( std::string("QBCDE") ); 38053d81ceSMarshall Clow test ( std::string("") ); 39053d81ceSMarshall Clow test ( std::string() ); 40053d81ceSMarshall Clow 41053d81ceSMarshall Clow test ( std::wstring(L"QBCDE") ); 42053d81ceSMarshall Clow test ( std::wstring(L"") ); 43053d81ceSMarshall Clow test ( std::wstring() ); 44053d81ceSMarshall Clow 45*7dad0bd6SMarshall Clow #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L 46*7dad0bd6SMarshall Clow test ( std::u8string{u8"QBCDE"} ); 47*7dad0bd6SMarshall Clow test ( std::u8string{u8""} ); 48*7dad0bd6SMarshall Clow test ( std::u8string{} ); 49*7dad0bd6SMarshall Clow #endif 50*7dad0bd6SMarshall Clow 51053d81ceSMarshall Clow #if TEST_STD_VER >= 11 52053d81ceSMarshall Clow test ( std::u16string{u"QBCDE"} ); 53053d81ceSMarshall Clow test ( std::u16string{u""} ); 54053d81ceSMarshall Clow test ( std::u16string{} ); 55053d81ceSMarshall Clow 56053d81ceSMarshall Clow test ( std::u32string{U"QBCDE"} ); 57053d81ceSMarshall Clow test ( std::u32string{U""} ); 58053d81ceSMarshall Clow test ( std::u32string{} ); 59053d81ceSMarshall Clow #endif 60053d81ceSMarshall Clow 61053d81ceSMarshall Clow test ( std::basic_string<char, dummy_char_traits>("QBCDE") ); 62053d81ceSMarshall Clow test ( std::basic_string<char, dummy_char_traits>("") ); 63053d81ceSMarshall Clow test ( std::basic_string<char, dummy_char_traits>() ); 64053d81ceSMarshall Clow 65053d81ceSMarshall Clow } 66