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 | // explicit basic_string(const Allocator& a = Allocator()); |
| 13 | |
| 14 | #include <string> |
| 15 | #include <cassert> |
| 16 | |
Marshall Clow | 7b193f7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 17 | #include "test_macros.h" |
Marshall Clow | 1b92188 | 2013-12-03 00:18:10 +0000 | [diff] [blame] | 18 | #include "test_allocator.h" |
Marshall Clow | 061d0cc | 2013-11-26 20:58:02 +0000 | [diff] [blame] | 19 | #include "min_allocator.h" |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 20 | |
| 21 | template <class S> |
| 22 | void |
| 23 | test() |
| 24 | { |
| 25 | { |
Marshall Clow | 7b193f7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 26 | #if TEST_STD_VER > 14 |
| 27 | static_assert((noexcept(S{})), "" ); |
| 28 | #elif TEST_STD_VER >= 11 |
| 29 | static_assert((noexcept(S()) == noexcept(typename S::allocator_type())), "" ); |
| 30 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 31 | S s; |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 32 | assert(s.__invariants()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 33 | assert(s.data()); |
| 34 | assert(s.size() == 0); |
| 35 | assert(s.capacity() >= s.size()); |
| 36 | assert(s.get_allocator() == typename S::allocator_type()); |
| 37 | } |
| 38 | { |
Marshall Clow | 7b193f7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 39 | #if TEST_STD_VER > 14 |
| 40 | static_assert((noexcept(S{typename S::allocator_type{}})), "" ); |
| 41 | #elif TEST_STD_VER >= 11 |
| 42 | static_assert((noexcept(S(typename S::allocator_type())) == std::is_nothrow_copy_constructible<typename S::allocator_type>::value), "" ); |
| 43 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 44 | S s(typename S::allocator_type(5)); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 45 | assert(s.__invariants()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 46 | assert(s.data()); |
| 47 | assert(s.size() == 0); |
| 48 | assert(s.capacity() >= s.size()); |
| 49 | assert(s.get_allocator() == typename S::allocator_type(5)); |
| 50 | } |
| 51 | } |
| 52 | |
Marshall Clow | 7b193f7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 53 | #if TEST_STD_VER >= 11 |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 54 | |
| 55 | template <class S> |
| 56 | void |
| 57 | test2() |
| 58 | { |
| 59 | { |
Marshall Clow | 7b193f7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 60 | #if TEST_STD_VER > 14 |
| 61 | static_assert((noexcept(S{})), "" ); |
| 62 | #elif TEST_STD_VER >= 11 |
| 63 | static_assert((noexcept(S()) == noexcept(typename S::allocator_type())), "" ); |
| 64 | #endif |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 65 | S s; |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 66 | assert(s.__invariants()); |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 67 | assert(s.data()); |
| 68 | assert(s.size() == 0); |
| 69 | assert(s.capacity() >= s.size()); |
| 70 | assert(s.get_allocator() == typename S::allocator_type()); |
| 71 | } |
| 72 | { |
Marshall Clow | 7b193f7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 73 | #if TEST_STD_VER > 14 |
| 74 | static_assert((noexcept(S{typename S::allocator_type{}})), "" ); |
| 75 | #elif TEST_STD_VER >= 11 |
| 76 | static_assert((noexcept(S(typename S::allocator_type())) == std::is_nothrow_copy_constructible<typename S::allocator_type>::value), "" ); |
| 77 | #endif |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 78 | S s(typename S::allocator_type{}); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 79 | assert(s.__invariants()); |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 80 | assert(s.data()); |
| 81 | assert(s.size() == 0); |
| 82 | assert(s.capacity() >= s.size()); |
| 83 | assert(s.get_allocator() == typename S::allocator_type()); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | #endif |
| 88 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 89 | int main() |
| 90 | { |
| 91 | test<std::basic_string<char, std::char_traits<char>, test_allocator<char> > >(); |
Marshall Clow | 7b193f7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 92 | #if TEST_STD_VER >= 11 |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 93 | test2<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >(); |
| 94 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 95 | } |