blob: 729c8e806906cf56a13642bc1cdcff33e3151c1a [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Chandler Carruth57b08b02019-01-19 10:56:40 +00003// 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
Howard Hinnant3e519522010-05-11 19:42:16 +00006//
7//===----------------------------------------------------------------------===//
8
Eric Fiselier1f4231f2016-04-28 22:28:23 +00009// UNSUPPORTED: c++98, c++03
10
Howard Hinnant3e519522010-05-11 19:42:16 +000011// <string>
12
13// basic_string(basic_string<charT,traits,Allocator>&& str);
14
15#include <string>
16#include <cassert>
17
Eric Fiselier1f4231f2016-04-28 22:28:23 +000018#include "test_macros.h"
Marshall Clowc3deeb52013-12-03 00:18:10 +000019#include "test_allocator.h"
Marshall Clowe34f6f62013-11-26 20:58:02 +000020#include "min_allocator.h"
Howard Hinnant3e519522010-05-11 19:42:16 +000021
22template <class S>
23void
24test(S s0)
25{
26 S s1 = s0;
27 S s2 = std::move(s0);
Eric Fiselier1f4231f2016-04-28 22:28:23 +000028 LIBCPP_ASSERT(s2.__invariants());
29 LIBCPP_ASSERT(s0.__invariants());
Howard Hinnant3e519522010-05-11 19:42:16 +000030 assert(s2 == s1);
31 assert(s2.capacity() >= s2.size());
32 assert(s2.get_allocator() == s1.get_allocator());
33}
34
JF Bastien2df59c52019-02-04 20:31:13 +000035int main(int, char**)
Howard Hinnant3e519522010-05-11 19:42:16 +000036{
Howard Hinnanteec72182013-06-28 16:59:19 +000037 {
Howard Hinnant3e519522010-05-11 19:42:16 +000038 typedef test_allocator<char> A;
39 typedef std::basic_string<char, std::char_traits<char>, A> S;
40 test(S(A(3)));
41 test(S("1", A(5)));
42 test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)));
Howard Hinnanteec72182013-06-28 16:59:19 +000043 }
Howard Hinnanteec72182013-06-28 16:59:19 +000044 {
45 typedef min_allocator<char> A;
46 typedef std::basic_string<char, std::char_traits<char>, A> S;
47 test(S(A{}));
48 test(S("1", A()));
49 test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()));
50 }
JF Bastien2df59c52019-02-04 20:31:13 +000051
52 return 0;
Howard Hinnant3e519522010-05-11 19:42:16 +000053}