blob: cf8021019a2ed2ff0dd51b47e678aed779e6f89a [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10// <string>
11
12// basic_string(const basic_string& str, const Allocator& alloc);
13
14#include <string>
15#include <cassert>
16
Marshall Clow1b921882013-12-03 00:18:10 +000017#include "test_allocator.h"
Marshall Clow061d0cc2013-11-26 20:58:02 +000018#include "min_allocator.h"
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000019
20template <class S>
21void
22test(S s1, const typename S::allocator_type& a)
23{
24 S s2(s1, a);
Dan Albert1d4a1ed2016-05-25 22:36:09 -070025 assert(s2.__invariants());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000026 assert(s2 == s1);
27 assert(s2.capacity() >= s2.size());
28 assert(s2.get_allocator() == a);
29}
30
31int main()
32{
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000033 {
Howard Hinnantbc8d3f92010-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 Hinnant9dcdcde2013-06-28 16:59:19 +000039 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -070040#if __cplusplus >= 201103L
Howard Hinnant9dcdcde2013-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
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000049}