blob: a232a46bd9fbaeff2abe40cb78764f93f7269b56 [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(basic_string&& str, const Allocator& alloc);
13
14#include <string>
15#include <cassert>
16
Dan Albert1d4a1ed2016-05-25 22:36:09 -070017#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
18
Marshall Clow7b193f72015-06-03 19:56:43 +000019#include "test_macros.h"
Marshall Clow1b921882013-12-03 00:18:10 +000020#include "test_allocator.h"
Marshall Clow061d0cc2013-11-26 20:58:02 +000021#include "min_allocator.h"
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000022
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000023
24template <class S>
25void
26test(S s0, const typename S::allocator_type& a)
27{
28 S s1 = s0;
29 S s2(std::move(s0), a);
Dan Albert1d4a1ed2016-05-25 22:36:09 -070030 assert(s2.__invariants());
31 assert(s0.__invariants());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000032 assert(s2 == s1);
33 assert(s2.capacity() >= s2.size());
34 assert(s2.get_allocator() == a);
35}
36
Dan Albert1d4a1ed2016-05-25 22:36:09 -070037#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
38// #if _LIBCPP_STD_VER <= 14
39// _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
40// #else
41// _NOEXCEPT;
42// #endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000043
44int main()
45{
Dan Albert1d4a1ed2016-05-25 22:36:09 -070046#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000047 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000048 typedef test_allocator<char> A;
49 typedef std::basic_string<char, std::char_traits<char>, A> S;
Marshall Clow7b193f72015-06-03 19:56:43 +000050#if TEST_STD_VER > 14
51 static_assert((noexcept(S{})), "" );
52#elif TEST_STD_VER >= 11
53 static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "" );
54#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000055 test(S(), A(3));
56 test(S("1"), A(5));
57 test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A(7));
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000058 }
Marshall Clowd5549cc2014-07-17 15:32:20 +000059
60 int alloc_count = test_alloc_base::alloc_count;
61 {
62 typedef test_allocator<char> A;
63 typedef std::basic_string<char, std::char_traits<char>, A> S;
Marshall Clow7b193f72015-06-03 19:56:43 +000064#if TEST_STD_VER > 14
65 static_assert((noexcept(S{})), "" );
66#elif TEST_STD_VER >= 11
67 static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "" );
68#endif
Marshall Clowd5549cc2014-07-17 15:32:20 +000069 S s1 ( "Twas brillig, and the slivy toves did gyre and gymbal in the wabe" );
70 S s2 (std::move(s1), A(1));
71 }
72 assert ( test_alloc_base::alloc_count == alloc_count );
Dan Albert1d4a1ed2016-05-25 22:36:09 -070073
74#if TEST_STD_VER >= 11
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000075 {
76 typedef min_allocator<char> A;
77 typedef std::basic_string<char, std::char_traits<char>, A> S;
Marshall Clow7b193f72015-06-03 19:56:43 +000078#if TEST_STD_VER > 14
79 static_assert((noexcept(S{})), "" );
80#elif TEST_STD_VER >= 11
81 static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "" );
82#endif
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000083 test(S(), A());
84 test(S("1"), A());
85 test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A());
86 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -070087#endif
88#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000089}