xref: /llvm-project/libcxx/test/std/strings/basic.string/string.cons/initializer_list.pass.cpp (revision f4c1258d5633fcf06385ff3fd1f4bf57ab971964)
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++03
10 
11 // <string>
12 
13 // basic_string(initializer_list<charT> il, const Allocator& a = Allocator());
14 
15 #include <string>
16 #include <cassert>
17 
18 #include "test_macros.h"
19 #include "test_allocator.h"
20 #include "min_allocator.h"
21 
22 int main(int, char**)
23 {
24     {
25         std::string s = {'a', 'b', 'c'};
26         assert(s == "abc");
27     }
28 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
29     {
30         std::wstring s;
31         s = {L'a', L'b', L'c'};
32         assert(s == L"abc");
33     }
34 #endif
35     {
36         typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
37         S s = {'a', 'b', 'c'};
38         assert(s == "abc");
39     }
40 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
41     {
42         typedef std::basic_string<wchar_t, std::char_traits<wchar_t>, min_allocator<wchar_t>> S;
43         S s;
44         s = {L'a', L'b', L'c'};
45         assert(s == L"abc");
46     }
47 #endif
48 
49   return 0;
50 }
51