blob: 0024f2defac633856f508b859cdd27466a9fd57f [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
9// <string>
10
11// basic_string(const basic_string<charT,traits,Allocator>& str);
12
13#include <string>
14#include <cassert>
15
Eric Fiselier1f4231f2016-04-28 22:28:23 +000016#include "test_macros.h"
Marshall Clowc3deeb52013-12-03 00:18:10 +000017#include "test_allocator.h"
Marshall Clowe34f6f62013-11-26 20:58:02 +000018#include "min_allocator.h"
Howard Hinnant3e519522010-05-11 19:42:16 +000019
20template <class S>
21void
22test(S s1)
23{
24 S s2 = s1;
Eric Fiselier1f4231f2016-04-28 22:28:23 +000025 LIBCPP_ASSERT(s2.__invariants());
Howard Hinnant3e519522010-05-11 19:42:16 +000026 assert(s2 == s1);
27 assert(s2.capacity() >= s2.size());
28 assert(s2.get_allocator() == s1.get_allocator());
29}
30
JF Bastien2df59c52019-02-04 20:31:13 +000031int main(int, char**)
Howard Hinnant3e519522010-05-11 19:42:16 +000032{
Howard Hinnanteec72182013-06-28 16:59:19 +000033 {
Howard Hinnant3e519522010-05-11 19:42:16 +000034 typedef test_allocator<char> A;
35 typedef std::basic_string<char, std::char_traits<char>, A> S;
36 test(S(A(3)));
37 test(S("1", A(5)));
38 test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)));
Howard Hinnanteec72182013-06-28 16:59:19 +000039 }
Eric Fiselier1f4231f2016-04-28 22:28:23 +000040#if TEST_STD_VER >= 11
Howard Hinnanteec72182013-06-28 16:59:19 +000041 {
42 typedef min_allocator<char> A;
43 typedef std::basic_string<char, std::char_traits<char>, A> S;
44 test(S(A{}));
45 test(S("1", A()));
46 test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()));
47 }
48#endif
JF Bastien2df59c52019-02-04 20:31:13 +000049
50 return 0;
Howard Hinnant3e519522010-05-11 19:42:16 +000051}