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 | |
Howard Hinnant | 6e0a1f4 | 2010-08-22 00:47:54 +0000 | [diff] [blame] | 12 | // template<class InputIterator> |
| 13 | // basic_string(InputIterator begin, InputIterator end, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 14 | // const Allocator& a = Allocator()); |
| 15 | |
| 16 | #include <string> |
| 17 | #include <iterator> |
| 18 | #include <cassert> |
| 19 | |
Marshall Clow | 1b92188 | 2013-12-03 00:18:10 +0000 | [diff] [blame] | 20 | #include "test_allocator.h" |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 21 | #include "../input_iterator.h" |
Marshall Clow | 061d0cc | 2013-11-26 20:58:02 +0000 | [diff] [blame] | 22 | #include "min_allocator.h" |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 23 | |
| 24 | template <class It> |
| 25 | void |
| 26 | test(It first, It last) |
| 27 | { |
| 28 | typedef typename std::iterator_traits<It>::value_type charT; |
| 29 | typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S; |
| 30 | typedef typename S::traits_type T; |
| 31 | typedef typename S::allocator_type A; |
| 32 | S s2(first, last); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 33 | assert(s2.__invariants()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 34 | assert(s2.size() == std::distance(first, last)); |
| 35 | unsigned i = 0; |
| 36 | for (It it = first; it != last; ++it, ++i) |
| 37 | assert(s2[i] == *it); |
| 38 | assert(s2.get_allocator() == A()); |
| 39 | assert(s2.capacity() >= s2.size()); |
| 40 | } |
| 41 | |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 42 | template <class It, class A> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 43 | void |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 44 | test(It first, It last, const A& a) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 45 | { |
| 46 | typedef typename std::iterator_traits<It>::value_type charT; |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 47 | typedef std::basic_string<charT, std::char_traits<charT>, A> S; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 48 | typedef typename S::traits_type T; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 49 | S s2(first, last, a); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 50 | assert(s2.__invariants()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 51 | assert(s2.size() == std::distance(first, last)); |
| 52 | unsigned i = 0; |
| 53 | for (It it = first; it != last; ++it, ++i) |
| 54 | assert(s2[i] == *it); |
| 55 | assert(s2.get_allocator() == a); |
| 56 | assert(s2.capacity() >= s2.size()); |
| 57 | } |
| 58 | |
| 59 | int main() |
| 60 | { |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 61 | { |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 62 | typedef test_allocator<char> A; |
| 63 | const char* s = "12345678901234567890123456789012345678901234567890"; |
| 64 | |
| 65 | test(s, s); |
| 66 | test(s, s, A(2)); |
| 67 | |
| 68 | test(s, s+1); |
| 69 | test(s, s+1, A(2)); |
| 70 | |
| 71 | test(s, s+10); |
| 72 | test(s, s+10, A(2)); |
| 73 | |
| 74 | test(s, s+50); |
| 75 | test(s, s+50, A(2)); |
| 76 | |
| 77 | test(input_iterator<const char*>(s), input_iterator<const char*>(s)); |
| 78 | test(input_iterator<const char*>(s), input_iterator<const char*>(s), A(2)); |
| 79 | |
| 80 | test(input_iterator<const char*>(s), input_iterator<const char*>(s+1)); |
| 81 | test(input_iterator<const char*>(s), input_iterator<const char*>(s+1), A(2)); |
| 82 | |
| 83 | test(input_iterator<const char*>(s), input_iterator<const char*>(s+10)); |
| 84 | test(input_iterator<const char*>(s), input_iterator<const char*>(s+10), A(2)); |
| 85 | |
| 86 | test(input_iterator<const char*>(s), input_iterator<const char*>(s+50)); |
| 87 | test(input_iterator<const char*>(s), input_iterator<const char*>(s+50), A(2)); |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 88 | } |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 89 | #if __cplusplus >= 201103L |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 90 | { |
| 91 | typedef min_allocator<char> A; |
| 92 | const char* s = "12345678901234567890123456789012345678901234567890"; |
| 93 | |
| 94 | test(s, s); |
| 95 | test(s, s, A()); |
| 96 | |
| 97 | test(s, s+1); |
| 98 | test(s, s+1, A()); |
| 99 | |
| 100 | test(s, s+10); |
| 101 | test(s, s+10, A()); |
| 102 | |
| 103 | test(s, s+50); |
| 104 | test(s, s+50, A()); |
| 105 | |
| 106 | test(input_iterator<const char*>(s), input_iterator<const char*>(s)); |
| 107 | test(input_iterator<const char*>(s), input_iterator<const char*>(s), A()); |
| 108 | |
| 109 | test(input_iterator<const char*>(s), input_iterator<const char*>(s+1)); |
| 110 | test(input_iterator<const char*>(s), input_iterator<const char*>(s+1), A()); |
| 111 | |
| 112 | test(input_iterator<const char*>(s), input_iterator<const char*>(s+10)); |
| 113 | test(input_iterator<const char*>(s), input_iterator<const char*>(s+10), A()); |
| 114 | |
| 115 | test(input_iterator<const char*>(s), input_iterator<const char*>(s+50)); |
| 116 | test(input_iterator<const char*>(s), input_iterator<const char*>(s+50), A()); |
| 117 | } |
| 118 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 119 | } |