Marshall Clow | ca0be23 | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 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 | //===----------------------------------------------------------------------===// |
Asiri Rathnayake | 6edc12c | 2016-05-28 08:57:35 +0000 | [diff] [blame] | 10 | |
| 11 | // UNSUPPORTED: c++98, c++03, c++11 |
| 12 | |
Marshall Clow | ca0be23 | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 13 | #include <string> |
| 14 | #include <cassert> |
| 15 | |
| 16 | int main() |
| 17 | { |
Marshall Clow | ca0be23 | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 18 | using namespace std::literals::string_literals; |
| 19 | |
Howard Hinnant | d098713 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 20 | static_assert ( std::is_same<decltype( "Hi"s), std::string>::value, "" ); |
| 21 | static_assert ( std::is_same<decltype( u8"Hi"s), std::string>::value, "" ); |
| 22 | static_assert ( std::is_same<decltype( L"Hi"s), std::wstring>::value, "" ); |
| 23 | static_assert ( std::is_same<decltype( u"Hi"s), std::u16string>::value, "" ); |
| 24 | static_assert ( std::is_same<decltype( U"Hi"s), std::u32string>::value, "" ); |
Eric Fiselier | d04c685 | 2016-06-01 21:35:39 +0000 | [diff] [blame] | 25 | |
Howard Hinnant | d098713 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 26 | std::string foo; |
| 27 | std::wstring Lfoo; |
| 28 | std::u16string ufoo; |
| 29 | std::u32string Ufoo; |
Eric Fiselier | d04c685 | 2016-06-01 21:35:39 +0000 | [diff] [blame] | 30 | |
Howard Hinnant | d098713 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 31 | foo = ""s; assert( foo.size() == 0); |
| 32 | foo = u8""s; assert( foo.size() == 0); |
| 33 | Lfoo = L""s; assert(Lfoo.size() == 0); |
| 34 | ufoo = u""s; assert(ufoo.size() == 0); |
| 35 | Ufoo = U""s; assert(Ufoo.size() == 0); |
Eric Fiselier | d04c685 | 2016-06-01 21:35:39 +0000 | [diff] [blame] | 36 | |
Howard Hinnant | d098713 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 37 | foo = " "s; assert( foo.size() == 1); |
| 38 | foo = u8" "s; assert( foo.size() == 1); |
| 39 | Lfoo = L" "s; assert(Lfoo.size() == 1); |
| 40 | ufoo = u" "s; assert(ufoo.size() == 1); |
| 41 | Ufoo = U" "s; assert(Ufoo.size() == 1); |
Eric Fiselier | d04c685 | 2016-06-01 21:35:39 +0000 | [diff] [blame] | 42 | |
Howard Hinnant | d098713 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 43 | foo = "ABC"s; assert( foo == "ABC"); assert( foo == std::string ( "ABC")); |
| 44 | foo = u8"ABC"s; assert( foo == u8"ABC"); assert( foo == std::string (u8"ABC")); |
| 45 | Lfoo = L"ABC"s; assert(Lfoo == L"ABC"); assert(Lfoo == std::wstring ( L"ABC")); |
| 46 | ufoo = u"ABC"s; assert(ufoo == u"ABC"); assert(ufoo == std::u16string( u"ABC")); |
| 47 | Ufoo = U"ABC"s; assert(Ufoo == U"ABC"); assert(Ufoo == std::u32string( U"ABC")); |
Marshall Clow | ca0be23 | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 48 | } |