• 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 #include <string>
11 #include <cassert>
12 
main()13 int main()
14 {
15 #if _LIBCPP_STD_VER > 11
16     using namespace std::literals::string_literals;
17 
18     static_assert ( std::is_same<decltype(   "Hi"s), std::string>::value, "" );
19     static_assert ( std::is_same<decltype( u8"Hi"s), std::string>::value, "" );
20     static_assert ( std::is_same<decltype(  L"Hi"s), std::wstring>::value, "" );
21     static_assert ( std::is_same<decltype(  u"Hi"s), std::u16string>::value, "" );
22     static_assert ( std::is_same<decltype(  U"Hi"s), std::u32string>::value, "" );
23 
24     std::string foo;
25     std::wstring Lfoo;
26     std::u16string ufoo;
27     std::u32string Ufoo;
28 
29     foo  =   ""s;     assert( foo.size() == 0);
30     foo  = u8""s;     assert( foo.size() == 0);
31     Lfoo =  L""s;     assert(Lfoo.size() == 0);
32     ufoo =  u""s;     assert(ufoo.size() == 0);
33     Ufoo =  U""s;     assert(Ufoo.size() == 0);
34 
35     foo  =   " "s;     assert( foo.size() == 1);
36     foo  = u8" "s;     assert( foo.size() == 1);
37     Lfoo =  L" "s;     assert(Lfoo.size() == 1);
38     ufoo =  u" "s;     assert(ufoo.size() == 1);
39     Ufoo =  U" "s;     assert(Ufoo.size() == 1);
40 
41     foo  =   "ABC"s;     assert( foo ==   "ABC");   assert( foo == std::string   (  "ABC"));
42     foo  = u8"ABC"s;     assert( foo == u8"ABC");   assert( foo == std::string   (u8"ABC"));
43     Lfoo =  L"ABC"s;     assert(Lfoo ==  L"ABC");   assert(Lfoo == std::wstring  ( L"ABC"));
44     ufoo =  u"ABC"s;     assert(ufoo ==  u"ABC");   assert(ufoo == std::u16string( u"ABC"));
45     Ufoo =  U"ABC"s;     assert(Ufoo ==  U"ABC");   assert(Ufoo == std::u32string( U"ABC"));
46 #endif
47 }
48