Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <string> |
| 11 | |
| 12 | // basic_string(basic_string&& str, const Allocator& alloc); |
| 13 | |
| 14 | #include <string> |
| 15 | #include <cassert> |
| 16 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 17 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 18 | |
Marshall Clow | 7b193f7 | 2015-06-03 19:56:43 +0000 | [diff] [blame^] | 19 | #include "test_macros.h" |
Marshall Clow | 1b92188 | 2013-12-03 00:18:10 +0000 | [diff] [blame] | 20 | #include "test_allocator.h" |
Marshall Clow | 061d0cc | 2013-11-26 20:58:02 +0000 | [diff] [blame] | 21 | #include "min_allocator.h" |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 22 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 23 | |
| 24 | template <class S> |
| 25 | void |
| 26 | test(S s0, const typename S::allocator_type& a) |
| 27 | { |
| 28 | S s1 = s0; |
| 29 | S s2(std::move(s0), a); |
| 30 | assert(s2.__invariants()); |
| 31 | assert(s0.__invariants()); |
| 32 | assert(s2 == s1); |
| 33 | assert(s2.capacity() >= s2.size()); |
| 34 | assert(s2.get_allocator() == a); |
| 35 | } |
| 36 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 37 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Marshall Clow | 7b193f7 | 2015-06-03 19:56:43 +0000 | [diff] [blame^] | 38 | // #if _LIBCPP_STD_VER <= 14 |
| 39 | // _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); |
| 40 | // #else |
| 41 | // _NOEXCEPT; |
| 42 | // #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 43 | |
| 44 | int main() |
| 45 | { |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 46 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 47 | { |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 48 | typedef test_allocator<char> A; |
| 49 | typedef std::basic_string<char, std::char_traits<char>, A> S; |
Marshall Clow | 7b193f7 | 2015-06-03 19:56:43 +0000 | [diff] [blame^] | 50 | #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 Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 55 | test(S(), A(3)); |
| 56 | test(S("1"), A(5)); |
| 57 | test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A(7)); |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 58 | } |
Marshall Clow | d5549cc | 2014-07-17 15:32:20 +0000 | [diff] [blame] | 59 | |
| 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 Clow | 7b193f7 | 2015-06-03 19:56:43 +0000 | [diff] [blame^] | 64 | #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 Clow | d5549cc | 2014-07-17 15:32:20 +0000 | [diff] [blame] | 69 | 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 ); |
| 73 | |
Marshall Clow | 7b193f7 | 2015-06-03 19:56:43 +0000 | [diff] [blame^] | 74 | #if TEST_STD_VER >= 11 |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 75 | { |
| 76 | typedef min_allocator<char> A; |
| 77 | typedef std::basic_string<char, std::char_traits<char>, A> S; |
Marshall Clow | 7b193f7 | 2015-06-03 19:56:43 +0000 | [diff] [blame^] | 78 | #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 Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 83 | test(S(), A()); |
| 84 | test(S("1"), A()); |
| 85 | test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A()); |
| 86 | } |
| 87 | #endif |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 88 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 89 | } |