Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 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 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // <string> |
| 10 | |
| 11 | // basic_string(const basic_string<charT,traits,Allocator>& str); |
| 12 | |
| 13 | #include <string> |
| 14 | #include <cassert> |
| 15 | |
Eric Fiselier | 1f4231f | 2016-04-28 22:28:23 +0000 | [diff] [blame] | 16 | #include "test_macros.h" |
Marshall Clow | c3deeb5 | 2013-12-03 00:18:10 +0000 | [diff] [blame] | 17 | #include "test_allocator.h" |
Marshall Clow | e34f6f6 | 2013-11-26 20:58:02 +0000 | [diff] [blame] | 18 | #include "min_allocator.h" |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 19 | |
| 20 | template <class S> |
| 21 | void |
| 22 | test(S s1) |
| 23 | { |
| 24 | S s2 = s1; |
Eric Fiselier | 1f4231f | 2016-04-28 22:28:23 +0000 | [diff] [blame] | 25 | LIBCPP_ASSERT(s2.__invariants()); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 26 | assert(s2 == s1); |
| 27 | assert(s2.capacity() >= s2.size()); |
| 28 | assert(s2.get_allocator() == s1.get_allocator()); |
| 29 | } |
| 30 | |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame^] | 31 | int main(int, char**) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 32 | { |
Howard Hinnant | eec7218 | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 33 | { |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 34 | 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 Hinnant | eec7218 | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 39 | } |
Eric Fiselier | 1f4231f | 2016-04-28 22:28:23 +0000 | [diff] [blame] | 40 | #if TEST_STD_VER >= 11 |
Howard Hinnant | eec7218 | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 41 | { |
| 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 Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame^] | 49 | |
| 50 | return 0; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 51 | } |