1 // -*- C++ -*- 2 //===----------------------------------------------------------------------===// 3 // 4 // The LLVM Compiler Infrastructure 5 // 6 // This file is dual licensed under the MIT and the University of Illinois Open 7 // Source Licenses. See LICENSE.TXT for details. 8 // 9 //===----------------------------------------------------------------------===// 10 11 // UNSUPPORTED: c++98, c++03, c++11 12 13 #include <string> 14 #include <cassert> 15 16 #include "test_macros.h" 17 18 #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L 19 typedef std::u8string u8string; 20 #else 21 typedef std::string u8string; 22 #endif 23 24 25 int main() 26 { 27 using namespace std::literals::string_literals; 28 29 static_assert ( std::is_same<decltype( "Hi"s), std::string>::value, "" ); 30 static_assert ( std::is_same<decltype( u8"Hi"s), u8string>::value, "" ); 31 static_assert ( std::is_same<decltype( L"Hi"s), std::wstring>::value, "" ); 32 static_assert ( std::is_same<decltype( u"Hi"s), std::u16string>::value, "" ); 33 static_assert ( std::is_same<decltype( U"Hi"s), std::u32string>::value, "" ); 34 35 std::string foo; 36 std::wstring Lfoo; 37 u8string u8foo; 38 std::u16string ufoo; 39 std::u32string Ufoo; 40 41 foo = ""s; assert( foo.size() == 0); 42 u8foo = u8""s; assert(u8foo.size() == 0); 43 Lfoo = L""s; assert( Lfoo.size() == 0); 44 ufoo = u""s; assert( ufoo.size() == 0); 45 Ufoo = U""s; assert( Ufoo.size() == 0); 46 47 foo = " "s; assert( foo.size() == 1); 48 u8foo = u8" "s; assert(u8foo.size() == 1); 49 Lfoo = L" "s; assert( Lfoo.size() == 1); 50 ufoo = u" "s; assert( ufoo.size() == 1); 51 Ufoo = U" "s; assert( Ufoo.size() == 1); 52 53 foo = "ABC"s; assert( foo == "ABC"); assert( foo == std::string ( "ABC")); 54 u8foo = u8"ABC"s; assert(u8foo == u8"ABC"); assert(u8foo == u8string (u8"ABC")); 55 Lfoo = L"ABC"s; assert( Lfoo == L"ABC"); assert( Lfoo == std::wstring ( L"ABC")); 56 ufoo = u"ABC"s; assert( ufoo == u"ABC"); assert( ufoo == std::u16string( u"ABC")); 57 Ufoo = U"ABC"s; assert( Ufoo == U"ABC"); assert( Ufoo == std::u32string( U"ABC")); 58 } 59