blob: 1c4f2044834e5b9a2165cccb0efa0f28c673c15a [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// explicit basic_string(const Allocator& a = Allocator());
13
14#include <string>
15#include <cassert>
16
Marshall Clow7b193f72015-06-03 19:56:43 +000017#include "test_macros.h"
Marshall Clow1b921882013-12-03 00:18:10 +000018#include "test_allocator.h"
Marshall Clow061d0cc2013-11-26 20:58:02 +000019#include "min_allocator.h"
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000020
21template <class S>
22void
23test()
24{
25 {
Marshall Clow7b193f72015-06-03 19:56:43 +000026#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 Hinnantbc8d3f92010-05-11 19:42:16 +000031 S s;
Dan Albert1d4a1ed2016-05-25 22:36:09 -070032 assert(s.__invariants());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000033 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 Clow7b193f72015-06-03 19:56:43 +000039#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 Hinnantbc8d3f92010-05-11 19:42:16 +000044 S s(typename S::allocator_type(5));
Dan Albert1d4a1ed2016-05-25 22:36:09 -070045 assert(s.__invariants());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000046 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 Clow7b193f72015-06-03 19:56:43 +000053#if TEST_STD_VER >= 11
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000054
55template <class S>
56void
57test2()
58{
59 {
Marshall Clow7b193f72015-06-03 19:56:43 +000060#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 Hinnant9dcdcde2013-06-28 16:59:19 +000065 S s;
Dan Albert1d4a1ed2016-05-25 22:36:09 -070066 assert(s.__invariants());
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000067 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 Clow7b193f72015-06-03 19:56:43 +000073#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 Hinnant9dcdcde2013-06-28 16:59:19 +000078 S s(typename S::allocator_type{});
Dan Albert1d4a1ed2016-05-25 22:36:09 -070079 assert(s.__invariants());
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000080 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 Hinnantbc8d3f92010-05-11 19:42:16 +000089int main()
90{
91 test<std::basic_string<char, std::char_traits<char>, test_allocator<char> > >();
Marshall Clow7b193f72015-06-03 19:56:43 +000092#if TEST_STD_VER >= 11
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000093 test2<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >();
94#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000095}