• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
main()16 int main()
17 {
18     using namespace std::literals::string_literals;
19 
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, "" );
25 
26     std::string foo;
27     std::wstring Lfoo;
28     std::u16string ufoo;
29     std::u32string Ufoo;
30 
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);
36 
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);
42 
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"));
48 }
49