15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a83710eSEric Fiselier //
75a83710eSEric Fiselier //===----------------------------------------------------------------------===//
85a83710eSEric Fiselier 
9*425620ccSNikolas Klauser // XFAIL: LIBCXX-AIX-FIXME
10*425620ccSNikolas Klauser 
115a83710eSEric Fiselier // <string>
125a83710eSEric Fiselier 
135a83710eSEric Fiselier // template<class InputIterator>
145a83710eSEric Fiselier //   basic_string(InputIterator begin, InputIterator end,
15*425620ccSNikolas Klauser //   const Allocator& a = Allocator()); // constexpr since C++20
165a83710eSEric Fiselier 
176d9f750dSMarshall Clow 
185a83710eSEric Fiselier #include <string>
195a83710eSEric Fiselier #include <iterator>
205a83710eSEric Fiselier #include <cassert>
21fbfb2ab6SStephan T. Lavavej #include <cstddef>
225a83710eSEric Fiselier 
231f4231f8SEric Fiselier #include "test_macros.h"
245a83710eSEric Fiselier #include "test_allocator.h"
25f75f171bSNikolas Klauser #include "test_iterators.h"
265a83710eSEric Fiselier #include "min_allocator.h"
275a83710eSEric Fiselier 
285a83710eSEric Fiselier template <class It>
29e85018b7SNikolas Klauser TEST_CONSTEXPR_CXX20 void
305a83710eSEric Fiselier test(It first, It last)
315a83710eSEric Fiselier {
325a83710eSEric Fiselier     typedef typename std::iterator_traits<It>::value_type charT;
335a83710eSEric Fiselier     typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
345a83710eSEric Fiselier     typedef typename S::allocator_type A;
355a83710eSEric Fiselier     S s2(first, last);
361f4231f8SEric Fiselier     LIBCPP_ASSERT(s2.__invariants());
37fbfb2ab6SStephan T. Lavavej     assert(s2.size() == static_cast<std::size_t>(std::distance(first, last)));
385a83710eSEric Fiselier     unsigned i = 0;
39f75f171bSNikolas Klauser     for (It it = first; it != last;) {
405a83710eSEric Fiselier         assert(s2[i] == *it);
41f75f171bSNikolas Klauser         ++it;
42f75f171bSNikolas Klauser         ++i;
43f75f171bSNikolas Klauser     }
445a83710eSEric Fiselier     assert(s2.get_allocator() == A());
455a83710eSEric Fiselier     assert(s2.capacity() >= s2.size());
465a83710eSEric Fiselier }
475a83710eSEric Fiselier 
485a83710eSEric Fiselier template <class It, class A>
49e85018b7SNikolas Klauser TEST_CONSTEXPR_CXX20 void
505a83710eSEric Fiselier test(It first, It last, const A& a)
515a83710eSEric Fiselier {
525a83710eSEric Fiselier     typedef typename std::iterator_traits<It>::value_type charT;
535a83710eSEric Fiselier     typedef std::basic_string<charT, std::char_traits<charT>, A> S;
545a83710eSEric Fiselier     S s2(first, last, a);
551f4231f8SEric Fiselier     LIBCPP_ASSERT(s2.__invariants());
56fbfb2ab6SStephan T. Lavavej     assert(s2.size() == static_cast<std::size_t>(std::distance(first, last)));
575a83710eSEric Fiselier     unsigned i = 0;
58f75f171bSNikolas Klauser     for (It it = first; it != last;) {
595a83710eSEric Fiselier         assert(s2[i] == *it);
60f75f171bSNikolas Klauser         ++it;
61f75f171bSNikolas Klauser         ++i;
62f75f171bSNikolas Klauser     }
635a83710eSEric Fiselier     assert(s2.get_allocator() == a);
645a83710eSEric Fiselier     assert(s2.capacity() >= s2.size());
655a83710eSEric Fiselier }
665a83710eSEric Fiselier 
67*425620ccSNikolas Klauser TEST_CONSTEXPR_CXX20 bool test() {
685a83710eSEric Fiselier   {
695a83710eSEric Fiselier     typedef test_allocator<char> A;
705a83710eSEric Fiselier     const char* s = "12345678901234567890123456789012345678901234567890";
715a83710eSEric Fiselier 
725a83710eSEric Fiselier     test(s, s);
735a83710eSEric Fiselier     test(s, s, A(2));
745a83710eSEric Fiselier 
755a83710eSEric Fiselier     test(s, s+1);
765a83710eSEric Fiselier     test(s, s+1, A(2));
775a83710eSEric Fiselier 
785a83710eSEric Fiselier     test(s, s+10);
795a83710eSEric Fiselier     test(s, s+10, A(2));
805a83710eSEric Fiselier 
815a83710eSEric Fiselier     test(s, s+50);
825a83710eSEric Fiselier     test(s, s+50, A(2));
835a83710eSEric Fiselier 
84773ae441SChristopher Di Bella     test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s));
85773ae441SChristopher Di Bella     test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s), A(2));
865a83710eSEric Fiselier 
87773ae441SChristopher Di Bella     test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1));
88773ae441SChristopher Di Bella     test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1), A(2));
895a83710eSEric Fiselier 
90773ae441SChristopher Di Bella     test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10));
91773ae441SChristopher Di Bella     test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10), A(2));
925a83710eSEric Fiselier 
93773ae441SChristopher Di Bella     test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+50));
94773ae441SChristopher Di Bella     test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+50), A(2));
955a83710eSEric Fiselier   }
961f4231f8SEric Fiselier #if TEST_STD_VER >= 11
975a83710eSEric Fiselier   {
985a83710eSEric Fiselier     typedef min_allocator<char> A;
995a83710eSEric Fiselier     const char* s = "12345678901234567890123456789012345678901234567890";
1005a83710eSEric Fiselier 
1015a83710eSEric Fiselier     test(s, s);
1025a83710eSEric Fiselier     test(s, s, A());
1035a83710eSEric Fiselier 
1045a83710eSEric Fiselier     test(s, s+1);
1055a83710eSEric Fiselier     test(s, s+1, A());
1065a83710eSEric Fiselier 
1075a83710eSEric Fiselier     test(s, s+10);
1085a83710eSEric Fiselier     test(s, s+10, A());
1095a83710eSEric Fiselier 
1105a83710eSEric Fiselier     test(s, s+50);
1115a83710eSEric Fiselier     test(s, s+50, A());
1125a83710eSEric Fiselier 
113773ae441SChristopher Di Bella     test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s));
114773ae441SChristopher Di Bella     test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s), A());
1155a83710eSEric Fiselier 
116773ae441SChristopher Di Bella     test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1));
117773ae441SChristopher Di Bella     test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1), A());
1185a83710eSEric Fiselier 
119773ae441SChristopher Di Bella     test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10));
120773ae441SChristopher Di Bella     test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10), A());
1215a83710eSEric Fiselier 
122773ae441SChristopher Di Bella     test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+50));
123773ae441SChristopher Di Bella     test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+50), A());
1245a83710eSEric Fiselier   }
1255a83710eSEric Fiselier #endif
126dfce2dd2SEric Fiselier   {
127dfce2dd2SEric Fiselier       static_assert((!std::is_constructible<std::string, std::string,
128dfce2dd2SEric Fiselier                                             std::string>::value),
129dfce2dd2SEric Fiselier                     "");
130dfce2dd2SEric Fiselier       static_assert(
131dfce2dd2SEric Fiselier           (!std::is_constructible<std::string, std::string, std::string,
132dfce2dd2SEric Fiselier                                   std::allocator<char> >::value),
133dfce2dd2SEric Fiselier           "");
134dfce2dd2SEric Fiselier   }
1352df59c50SJF Bastien 
136e85018b7SNikolas Klauser   return true;
137e85018b7SNikolas Klauser }
138e85018b7SNikolas Klauser 
139e85018b7SNikolas Klauser int main(int, char**)
140e85018b7SNikolas Klauser {
141e85018b7SNikolas Klauser   test();
142e85018b7SNikolas Klauser #if TEST_STD_VER > 17
143*425620ccSNikolas Klauser   static_assert(test());
144e85018b7SNikolas Klauser #endif
145e85018b7SNikolas Klauser 
1462df59c50SJF Bastien   return 0;
1475a83710eSEric Fiselier }
148