3 // Copyright (C) 1999, 2002, 2003, 2004 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21 // 21.3.3 string capacity
24 #include <testsuite_hooks.h>
31 operator==(const A<T>&, const A<T>&) { return true; }
35 operator<(const A<T>&, const A<T>&) { return true; }
39 // char_traits specialization
43 struct char_traits<A<B> >
45 typedef A<B> char_type;
46 // Unsigned as wint_t in unsigned.
47 typedef unsigned long int_type;
48 typedef streampos pos_type;
49 typedef streamoff off_type;
50 typedef mbstate_t state_type;
53 assign(char_type& __c1, const char_type& __c2)
57 eq(const char_type& __c1, const char_type& __c2)
58 { return __c1 == __c2; }
61 lt(const char_type& __c1, const char_type& __c2)
62 { return __c1 < __c2; }
65 compare(const char_type* __s1, const char_type* __s2, size_t __n)
67 for (size_t __i = 0; __i < __n; ++__i)
68 if (!eq(__s1[__i], __s2[__i]))
69 return lt(__s1[__i], __s2[__i]) ? -1 : 1;
74 length(const char_type* __s)
76 const char_type* __p = __s;
82 static const char_type*
83 find(const char_type* __s, size_t __n, const char_type& __a)
85 for (const char_type* __p = __s; size_t(__p - __s) < __n; ++__p)
86 if (*__p == __a) return __p;
91 move(char_type* __s1, const char_type* __s2, size_t __n)
92 { return (char_type*) memmove(__s1, __s2, __n * sizeof(char_type)); }
95 copy(char_type* __s1, const char_type* __s2, size_t __n)
96 { return (char_type*) memcpy(__s1, __s2, __n * sizeof(char_type)); }
99 assign(char_type* __s, size_t __n, char_type __a)
101 for (char_type* __p = __s; __p < __s + __n; ++__p)
107 to_char_type(const int_type&)
108 { return char_type(); }
111 to_int_type(const char_type&) { return int_type(); }
114 eq_int_type(const int_type& __c1, const int_type& __c2)
115 { return __c1 == __c2; }
118 eof() { return static_cast<int_type>(-1); }
121 not_eof(const int_type& __c)
122 { return eq_int_type(__c, eof()) ? int_type(0) : __c; }
128 bool test __attribute__((unused)) = true;
130 // non POD types : resize, capacity, reserve
131 std::basic_string< A<B> > str02;
132 typedef std::basic_string< A<B> >::size_type size_type_o;
136 sz03 = str02.capacity();
138 sz04 = str02.capacity();
139 VERIFY( sz04 >= sz03 );
140 VERIFY( sz04 >= 100 );
142 sz03 = str02.capacity();
145 sz03 = str02.size() + 5;
148 VERIFY( sz03 == sz04 );
150 sz03 = str02.size() - 5;
153 VERIFY( sz03 == sz04 );
156 std::basic_string<A<B> > str07(30, inst_obj);
157 std::basic_string<A<B> > str08 = str07;
158 str07 = str08 + str07;
159 VERIFY( str07.capacity() >= str07.size() );
160 VERIFY( str08.capacity() >= str08.size() );
162 // non-POD types: size, length, max_size, clear(), empty()
163 bool b01 = str02.empty();
164 VERIFY( b01 == true );
166 sz04 = str02.length();
167 VERIFY( sz03 == sz04 );
170 sz04 = str02.length();
171 VERIFY( sz03 == sz04 );
173 sz03 = str02.max_size();
174 VERIFY( sz03 >= sz04 );
179 VERIFY( b01 == true );
181 VERIFY( sz03 >= sz04 );
185 // Explicitly instantiate for systems with no COMDAT or weak support.
187 std::basic_string< A<B> >::size_type
188 std::basic_string< A<B> >::_Rep::_S_max_size;
192 std::basic_string< A<B> >::_Rep::_S_terminal;