1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 11 // <string_view> 12 13 // template<class Allocator> 14 // basic_string_view(const basic_string<_CharT, _Traits, Allocator>& _str) noexcept 15 16 17 #include <string_view> 18 #include <string> 19 #include <cassert> 20 21 #include "test_macros.h" 22 23 struct dummy_char_traits : public std::char_traits<char> {}; 24 25 template<typename CharT, typename Traits> test(const std::basic_string<CharT,Traits> & str)26void test ( const std::basic_string<CharT, Traits> &str ) { 27 typedef std::basic_string_view<CharT, Traits> SV; 28 ASSERT_NOEXCEPT(SV(str)); 29 30 SV sv1 ( str ); 31 assert ( sv1.size() == str.size()); 32 assert ( sv1.data() == str.data()); 33 } 34 main()35int main () { 36 37 test ( std::string("QBCDE") ); 38 test ( std::string("") ); 39 test ( std::string() ); 40 41 test ( std::wstring(L"QBCDE") ); 42 test ( std::wstring(L"") ); 43 test ( std::wstring() ); 44 45 #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L 46 test ( std::u8string{u8"QBCDE"} ); 47 test ( std::u8string{u8""} ); 48 test ( std::u8string{} ); 49 #endif 50 51 #if TEST_STD_VER >= 11 52 test ( std::u16string{u"QBCDE"} ); 53 test ( std::u16string{u""} ); 54 test ( std::u16string{} ); 55 56 test ( std::u32string{U"QBCDE"} ); 57 test ( std::u32string{U""} ); 58 test ( std::u32string{} ); 59 #endif 60 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>() ); 64 65 } 66