//===----------------------------------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // // template // basic_string(InputIterator begin, InputIterator end, // const Allocator& a = Allocator()); #include #include #include #include #include "test_macros.h" #include "test_allocator.h" #include "../input_iterator.h" #include "min_allocator.h" template void test(It first, It last) { typedef typename std::iterator_traits::value_type charT; typedef std::basic_string, test_allocator > S; typedef typename S::allocator_type A; S s2(first, last); LIBCPP_ASSERT(s2.__invariants()); assert(s2.size() == static_cast(std::distance(first, last))); unsigned i = 0; for (It it = first; it != last; ++it, ++i) assert(s2[i] == *it); assert(s2.get_allocator() == A()); assert(s2.capacity() >= s2.size()); } template void test(It first, It last, const A& a) { typedef typename std::iterator_traits::value_type charT; typedef std::basic_string, A> S; S s2(first, last, a); LIBCPP_ASSERT(s2.__invariants()); assert(s2.size() == static_cast(std::distance(first, last))); unsigned i = 0; for (It it = first; it != last; ++it, ++i) assert(s2[i] == *it); assert(s2.get_allocator() == a); assert(s2.capacity() >= s2.size()); } int main() { { typedef test_allocator A; const char* s = "12345678901234567890123456789012345678901234567890"; test(s, s); test(s, s, A(2)); test(s, s+1); test(s, s+1, A(2)); test(s, s+10); test(s, s+10, A(2)); test(s, s+50); test(s, s+50, A(2)); test(input_iterator(s), input_iterator(s)); test(input_iterator(s), input_iterator(s), A(2)); test(input_iterator(s), input_iterator(s+1)); test(input_iterator(s), input_iterator(s+1), A(2)); test(input_iterator(s), input_iterator(s+10)); test(input_iterator(s), input_iterator(s+10), A(2)); test(input_iterator(s), input_iterator(s+50)); test(input_iterator(s), input_iterator(s+50), A(2)); } #if TEST_STD_VER >= 11 { typedef min_allocator A; const char* s = "12345678901234567890123456789012345678901234567890"; test(s, s); test(s, s, A()); test(s, s+1); test(s, s+1, A()); test(s, s+10); test(s, s+10, A()); test(s, s+50); test(s, s+50, A()); test(input_iterator(s), input_iterator(s)); test(input_iterator(s), input_iterator(s), A()); test(input_iterator(s), input_iterator(s+1)); test(input_iterator(s), input_iterator(s+1), A()); test(input_iterator(s), input_iterator(s+10)); test(input_iterator(s), input_iterator(s+10), A()); test(input_iterator(s), input_iterator(s+50)); test(input_iterator(s), input_iterator(s+50), A()); } #endif }