xref: /minix3/external/bsd/libc++/dist/libcxx/test/strings/basic.string.literals/literal.pass.cpp (revision 4684ddb6aab0b36791c8099bc705d6140b3d05d0)
1*4684ddb6SLionel Sambuc // -*- C++ -*-
2*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
3*4684ddb6SLionel Sambuc //
4*4684ddb6SLionel Sambuc //                     The LLVM Compiler Infrastructure
5*4684ddb6SLionel Sambuc //
6*4684ddb6SLionel Sambuc // This file is dual licensed under the MIT and the University of Illinois Open
7*4684ddb6SLionel Sambuc // Source Licenses. See LICENSE.TXT for details.
8*4684ddb6SLionel Sambuc //
9*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
10*4684ddb6SLionel Sambuc #include <string>
11*4684ddb6SLionel Sambuc #include <cassert>
12*4684ddb6SLionel Sambuc 
main()13*4684ddb6SLionel Sambuc int main()
14*4684ddb6SLionel Sambuc {
15*4684ddb6SLionel Sambuc #if _LIBCPP_STD_VER > 11
16*4684ddb6SLionel Sambuc     using namespace std::literals::string_literals;
17*4684ddb6SLionel Sambuc 
18*4684ddb6SLionel Sambuc     static_assert ( std::is_same<decltype(   "Hi"s), std::string>::value, "" );
19*4684ddb6SLionel Sambuc     static_assert ( std::is_same<decltype( u8"Hi"s), std::string>::value, "" );
20*4684ddb6SLionel Sambuc     static_assert ( std::is_same<decltype(  L"Hi"s), std::wstring>::value, "" );
21*4684ddb6SLionel Sambuc     static_assert ( std::is_same<decltype(  u"Hi"s), std::u16string>::value, "" );
22*4684ddb6SLionel Sambuc     static_assert ( std::is_same<decltype(  U"Hi"s), std::u32string>::value, "" );
23*4684ddb6SLionel Sambuc 
24*4684ddb6SLionel Sambuc     std::string foo;
25*4684ddb6SLionel Sambuc     std::wstring Lfoo;
26*4684ddb6SLionel Sambuc     std::u16string ufoo;
27*4684ddb6SLionel Sambuc     std::u32string Ufoo;
28*4684ddb6SLionel Sambuc 
29*4684ddb6SLionel Sambuc     foo  =   ""s;     assert( foo.size() == 0);
30*4684ddb6SLionel Sambuc     foo  = u8""s;     assert( foo.size() == 0);
31*4684ddb6SLionel Sambuc     Lfoo =  L""s;     assert(Lfoo.size() == 0);
32*4684ddb6SLionel Sambuc     ufoo =  u""s;     assert(ufoo.size() == 0);
33*4684ddb6SLionel Sambuc     Ufoo =  U""s;     assert(Ufoo.size() == 0);
34*4684ddb6SLionel Sambuc 
35*4684ddb6SLionel Sambuc     foo  =   " "s;     assert( foo.size() == 1);
36*4684ddb6SLionel Sambuc     foo  = u8" "s;     assert( foo.size() == 1);
37*4684ddb6SLionel Sambuc     Lfoo =  L" "s;     assert(Lfoo.size() == 1);
38*4684ddb6SLionel Sambuc     ufoo =  u" "s;     assert(ufoo.size() == 1);
39*4684ddb6SLionel Sambuc     Ufoo =  U" "s;     assert(Ufoo.size() == 1);
40*4684ddb6SLionel Sambuc 
41*4684ddb6SLionel Sambuc     foo  =   "ABC"s;     assert( foo ==   "ABC");   assert( foo == std::string   (  "ABC"));
42*4684ddb6SLionel Sambuc     foo  = u8"ABC"s;     assert( foo == u8"ABC");   assert( foo == std::string   (u8"ABC"));
43*4684ddb6SLionel Sambuc     Lfoo =  L"ABC"s;     assert(Lfoo ==  L"ABC");   assert(Lfoo == std::wstring  ( L"ABC"));
44*4684ddb6SLionel Sambuc     ufoo =  u"ABC"s;     assert(ufoo ==  u"ABC");   assert(ufoo == std::u16string( u"ABC"));
45*4684ddb6SLionel Sambuc     Ufoo =  U"ABC"s;     assert(Ufoo ==  U"ABC");   assert(Ufoo == std::u32string( U"ABC"));
46*4684ddb6SLionel Sambuc #endif
47*4684ddb6SLionel Sambuc }
48