xref: /llvm-project/libcxx/test/std/strings/basic.string/string.cons/brace_assignment.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<charT,traits,Allocator>&
14 //   operator=(basic_string<charT,traits,Allocator>&& str);
15 
16 #include <string>
17 #include <cassert>
18 
19 #include "test_macros.h"
20 
21 int main(int, char**)
22 {
23   // Test that assignment from {} and {ptr, len} are allowed and are not
24   // ambiguous.
25   {
26     std::string s = "hello world";
27     s = {};
28     assert(s.empty());
29   }
30   {
31     std::string s = "hello world";
32     s = {"abc", 2};
33     assert(s == "ab");
34   }
35 
36   return 0;
37 }
38