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 95a83710eSEric Fiselier // <string> 105a83710eSEric Fiselier 115a83710eSEric Fiselier // template<class InputIterator> 125a83710eSEric Fiselier // basic_string(InputIterator begin, InputIterator end, 135a83710eSEric Fiselier // const Allocator& a = Allocator()); 145a83710eSEric Fiselier 156d9f750dSMarshall Clow 165a83710eSEric Fiselier #include <string> 175a83710eSEric Fiselier #include <iterator> 185a83710eSEric Fiselier #include <cassert> 19fbfb2ab6SStephan T. Lavavej #include <cstddef> 205a83710eSEric Fiselier 211f4231f8SEric Fiselier #include "test_macros.h" 225a83710eSEric Fiselier #include "test_allocator.h" 23*f75f171bSNikolas Klauser #include "test_iterators.h" 245a83710eSEric Fiselier #include "min_allocator.h" 255a83710eSEric Fiselier 265a83710eSEric Fiselier template <class It> 27e85018b7SNikolas Klauser TEST_CONSTEXPR_CXX20 void 285a83710eSEric Fiselier test(It first, It last) 295a83710eSEric Fiselier { 305a83710eSEric Fiselier typedef typename std::iterator_traits<It>::value_type charT; 315a83710eSEric Fiselier typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S; 325a83710eSEric Fiselier typedef typename S::allocator_type A; 335a83710eSEric Fiselier S s2(first, last); 341f4231f8SEric Fiselier LIBCPP_ASSERT(s2.__invariants()); 35fbfb2ab6SStephan T. Lavavej assert(s2.size() == static_cast<std::size_t>(std::distance(first, last))); 365a83710eSEric Fiselier unsigned i = 0; 37*f75f171bSNikolas Klauser for (It it = first; it != last;) { 385a83710eSEric Fiselier assert(s2[i] == *it); 39*f75f171bSNikolas Klauser ++it; 40*f75f171bSNikolas Klauser ++i; 41*f75f171bSNikolas Klauser } 425a83710eSEric Fiselier assert(s2.get_allocator() == A()); 435a83710eSEric Fiselier assert(s2.capacity() >= s2.size()); 445a83710eSEric Fiselier } 455a83710eSEric Fiselier 465a83710eSEric Fiselier template <class It, class A> 47e85018b7SNikolas Klauser TEST_CONSTEXPR_CXX20 void 485a83710eSEric Fiselier test(It first, It last, const A& a) 495a83710eSEric Fiselier { 505a83710eSEric Fiselier typedef typename std::iterator_traits<It>::value_type charT; 515a83710eSEric Fiselier typedef std::basic_string<charT, std::char_traits<charT>, A> S; 525a83710eSEric Fiselier S s2(first, last, a); 531f4231f8SEric Fiselier LIBCPP_ASSERT(s2.__invariants()); 54fbfb2ab6SStephan T. Lavavej assert(s2.size() == static_cast<std::size_t>(std::distance(first, last))); 555a83710eSEric Fiselier unsigned i = 0; 56*f75f171bSNikolas Klauser for (It it = first; it != last;) { 575a83710eSEric Fiselier assert(s2[i] == *it); 58*f75f171bSNikolas Klauser ++it; 59*f75f171bSNikolas Klauser ++i; 60*f75f171bSNikolas Klauser } 615a83710eSEric Fiselier assert(s2.get_allocator() == a); 625a83710eSEric Fiselier assert(s2.capacity() >= s2.size()); 635a83710eSEric Fiselier } 645a83710eSEric Fiselier 65e85018b7SNikolas Klauser bool test() { 665a83710eSEric Fiselier { 675a83710eSEric Fiselier typedef test_allocator<char> A; 685a83710eSEric Fiselier const char* s = "12345678901234567890123456789012345678901234567890"; 695a83710eSEric Fiselier 705a83710eSEric Fiselier test(s, s); 715a83710eSEric Fiselier test(s, s, A(2)); 725a83710eSEric Fiselier 735a83710eSEric Fiselier test(s, s+1); 745a83710eSEric Fiselier test(s, s+1, A(2)); 755a83710eSEric Fiselier 765a83710eSEric Fiselier test(s, s+10); 775a83710eSEric Fiselier test(s, s+10, A(2)); 785a83710eSEric Fiselier 795a83710eSEric Fiselier test(s, s+50); 805a83710eSEric Fiselier test(s, s+50, A(2)); 815a83710eSEric Fiselier 82773ae441SChristopher Di Bella test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s)); 83773ae441SChristopher Di Bella test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s), A(2)); 845a83710eSEric Fiselier 85773ae441SChristopher Di Bella test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1)); 86773ae441SChristopher Di Bella test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1), A(2)); 875a83710eSEric Fiselier 88773ae441SChristopher Di Bella test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10)); 89773ae441SChristopher Di Bella test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10), A(2)); 905a83710eSEric Fiselier 91773ae441SChristopher Di Bella test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+50)); 92773ae441SChristopher Di Bella test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+50), A(2)); 935a83710eSEric Fiselier } 941f4231f8SEric Fiselier #if TEST_STD_VER >= 11 955a83710eSEric Fiselier { 965a83710eSEric Fiselier typedef min_allocator<char> A; 975a83710eSEric Fiselier const char* s = "12345678901234567890123456789012345678901234567890"; 985a83710eSEric Fiselier 995a83710eSEric Fiselier test(s, s); 1005a83710eSEric Fiselier test(s, s, A()); 1015a83710eSEric Fiselier 1025a83710eSEric Fiselier test(s, s+1); 1035a83710eSEric Fiselier test(s, s+1, A()); 1045a83710eSEric Fiselier 1055a83710eSEric Fiselier test(s, s+10); 1065a83710eSEric Fiselier test(s, s+10, A()); 1075a83710eSEric Fiselier 1085a83710eSEric Fiselier test(s, s+50); 1095a83710eSEric Fiselier test(s, s+50, A()); 1105a83710eSEric Fiselier 111773ae441SChristopher Di Bella test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s)); 112773ae441SChristopher Di Bella test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s), A()); 1135a83710eSEric Fiselier 114773ae441SChristopher Di Bella test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1)); 115773ae441SChristopher Di Bella test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1), A()); 1165a83710eSEric Fiselier 117773ae441SChristopher Di Bella test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10)); 118773ae441SChristopher Di Bella test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10), A()); 1195a83710eSEric Fiselier 120773ae441SChristopher Di Bella test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+50)); 121773ae441SChristopher Di Bella test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+50), A()); 1225a83710eSEric Fiselier } 1235a83710eSEric Fiselier #endif 124dfce2dd2SEric Fiselier { 125dfce2dd2SEric Fiselier static_assert((!std::is_constructible<std::string, std::string, 126dfce2dd2SEric Fiselier std::string>::value), 127dfce2dd2SEric Fiselier ""); 128dfce2dd2SEric Fiselier static_assert( 129dfce2dd2SEric Fiselier (!std::is_constructible<std::string, std::string, std::string, 130dfce2dd2SEric Fiselier std::allocator<char> >::value), 131dfce2dd2SEric Fiselier ""); 132dfce2dd2SEric Fiselier } 1332df59c50SJF Bastien 134e85018b7SNikolas Klauser return true; 135e85018b7SNikolas Klauser } 136e85018b7SNikolas Klauser 137e85018b7SNikolas Klauser int main(int, char**) 138e85018b7SNikolas Klauser { 139e85018b7SNikolas Klauser test(); 140e85018b7SNikolas Klauser #if TEST_STD_VER > 17 141e85018b7SNikolas Klauser // static_assert(test()); 142e85018b7SNikolas Klauser #endif 143e85018b7SNikolas Klauser 1442df59c50SJF Bastien return 0; 1455a83710eSEric Fiselier } 146