blob: 1f9631449ee7b95f370351ac5fe855a0f61356ce [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnant5b08a8a2010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnant3e519522010-05-11 19:42:16 +00004//
Howard Hinnant412dbeb2010-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 Hinnant3e519522010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10// <string>
11
12// basic_string(basic_string&& str, const Allocator& alloc);
13
14#include <string>
15#include <cassert>
16
Howard Hinnant7609c9b2010-09-04 23:28:19 +000017#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +000018
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 Hinnanteec72182013-06-28 16:59:19 +000021
Howard Hinnant3e519522010-05-11 19:42:16 +000022
23template <class S>
24void
25test(S s0, const typename S::allocator_type& a)
26{
27 S s1 = s0;
28 S s2(std::move(s0), a);
29 assert(s2.__invariants());
30 assert(s0.__invariants());
31 assert(s2 == s1);
32 assert(s2.capacity() >= s2.size());
33 assert(s2.get_allocator() == a);
34}
35
Howard Hinnant7609c9b2010-09-04 23:28:19 +000036#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +000037
38int main()
39{
Howard Hinnant7609c9b2010-09-04 23:28:19 +000040#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnanteec72182013-06-28 16:59:19 +000041 {
Howard Hinnant3e519522010-05-11 19:42:16 +000042 typedef test_allocator<char> A;
43 typedef std::basic_string<char, std::char_traits<char>, A> S;
44 test(S(), A(3));
45 test(S("1"), A(5));
46 test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A(7));
Howard Hinnanteec72182013-06-28 16:59:19 +000047 }
Marshall Clow3dd88462014-07-17 15:32:20 +000048
49 int alloc_count = test_alloc_base::alloc_count;
50 {
51 typedef test_allocator<char> A;
52 typedef std::basic_string<char, std::char_traits<char>, A> S;
53 S s1 ( "Twas brillig, and the slivy toves did gyre and gymbal in the wabe" );
54 S s2 (std::move(s1), A(1));
55 }
56 assert ( test_alloc_base::alloc_count == alloc_count );
57
Howard Hinnanteec72182013-06-28 16:59:19 +000058#if __cplusplus >= 201103L
59 {
60 typedef min_allocator<char> A;
61 typedef std::basic_string<char, std::char_traits<char>, A> S;
62 test(S(), A());
63 test(S("1"), A());
64 test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A());
65 }
66#endif
Howard Hinnant7609c9b2010-09-04 23:28:19 +000067#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +000068}