xref: /llvm-project/libcxx/test/std/strings/basic.string/string.cons/initializer_list.pass.cpp (revision 31cbe0f240f660f15602c96b787c58a26f17e179)
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     {
29         std::wstring s;
30         s = {L'a', L'b', L'c'};
31         assert(s == L"abc");
32     }
33     {
34         typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
35         S s = {'a', 'b', 'c'};
36         assert(s == "abc");
37     }
38     {
39         typedef std::basic_string<wchar_t, std::char_traits<wchar_t>, min_allocator<wchar_t>> S;
40         S s;
41         s = {L'a', L'b', L'c'};
42         assert(s == L"abc");
43     }
44 
45   return 0;
46 }
47