f90e600a4e
2004-03-04 Benjamin Kosnik <bkoz@redhat.com> * testsuite/20_util/allocator/1.cc: Provide explicit instantiations for non-weak systems. * testsuite/20_util/binders.cc: Same. * testsuite/20_util/allocator/8230.cc: Same. * testsuite/20_util/allocator/10378.cc: Same. * testsuite/22_locale/ctype/is/wchar_t/2.cc: Same. * testsuite/22_locale/ctype/is/char/2.cc: Same. * testsuite/thread/pthread7-rope.cc: Same. * testsuite/thread/pthread6.cc: Same. * testsuite/thread/pthread5.cc: Same. * testsuite/thread/pthread4.cc: Same. * testsuite/thread/pthread1.cc: Same. * testsuite/ext/rope.cc: Same. * testsuite/ext/hash_set.cc: Same. * testsuite/ext/hash_map.cc: Same. * testsuite/ext/concept_checks.cc: Same. * testsuite/27_io/basic_filebuf/seekpos/wchar_t/9874.cc: Same. * testsuite/25_algorithms/unique/2.cc: Same. * testsuite/25_algorithms/unique/1.cc: Same. * testsuite/25_algorithms/rotate.cc: Same. * testsuite/25_algorithms/min_max.cc: Same. * testsuite/25_algorithms/equal.cc: Same. * testsuite/24_iterators/rel_ops.cc: Same. * testsuite/24_iterators/iterator.cc: Same. * testsuite/24_iterators/insert_iterator.cc: Same. * testsuite/24_iterators/front_insert_iterator.cc: Same. * testsuite/24_iterators/back_insert_iterator.cc: Same. * testsuite/23_containers/vector/resize/1.cc: Same. * testsuite/23_containers/vector/modifiers/2.cc: Same. * testsuite/23_containers/vector/modifiers/1.cc: Same. * testsuite/23_containers/vector/invalidation/4.cc: Same. * testsuite/23_containers/vector/invalidation/3.cc: Same. * testsuite/23_containers/vector/invalidation/2.cc: Same. * testsuite/23_containers/vector/invalidation/1.cc: Same. * testsuite/23_containers/vector/element_access/1.cc: Same. * testsuite/23_containers/vector/cons/6513.cc: Same. * testsuite/23_containers/vector/cons/3.cc: Same. * testsuite/23_containers/vector/cons/2.cc: Same. * testsuite/23_containers/vector/cons/1.cc: Same. * testsuite/23_containers/vector/capacity/8230.cc: Same. * testsuite/23_containers/vector/capacity/1.cc: Same. * testsuite/23_containers/vector/bool/6886.cc: Same. * testsuite/23_containers/stack/members/7158.cc: Same. * testsuite/23_containers/set/invalidation/2.cc: Same. * testsuite/23_containers/set/invalidation/1.cc: Same. * testsuite/23_containers/queue/members/7157.cc: Same. * testsuite/23_containers/priority_queue/members/7161.cc: Same. * testsuite/23_containers/multiset/invalidation/2.cc: Same. * testsuite/23_containers/multiset/invalidation/2.cc: Same. * testsuite/23_containers/multiset/insert/1.cc: Same. * testsuite/23_containers/multimap/invalidation/2.cc: Same. * testsuite/23_containers/multimap/invalidation/2.cc: Same. * testsuite/23_containers/map/operators/1.cc: Same. * testsuite/23_containers/map/invalidation/2.cc: Same. * testsuite/23_containers/map/invalidation/1.cc: Same. * testsuite/23_containers/map/insert/1.cc: Same. * testsuite/23_containers/list/operators/4.cc: Same. * testsuite/23_containers/list/operators/3.cc: Same. * testsuite/23_containers/list/operators/2.cc: Same. * testsuite/23_containers/list/operators/1.cc: Same. * testsuite/23_containers/list/modifiers/3.cc: Same. * testsuite/23_containers/list/modifiers/2.cc: Same. * testsuite/23_containers/list/modifiers/1.cc: Same. * testsuite/23_containers/list/invalidation/4.cc: Same. * testsuite/23_containers/list/invalidation/3.cc: Same. * testsuite/23_containers/list/invalidation/2.cc: Same. * testsuite/23_containers/list/invalidation/1.cc: Same. * testsuite/23_containers/list/cons/9.cc: Same. * testsuite/23_containers/list/cons/8.cc: Same. * testsuite/23_containers/list/cons/7.cc: Same. * testsuite/23_containers/list/cons/6.cc: Same. * testsuite/23_containers/list/cons/5.cc: Same. * testsuite/23_containers/list/cons/4.cc: Same. * testsuite/23_containers/list/cons/3.cc: Same. * testsuite/23_containers/list/cons/2.cc: Same. * testsuite/23_containers/list/cons/1.cc: Same. * testsuite/23_containers/list/capacity/1.cc: Same. * testsuite/23_containers/deque/operators/1.cc: Same. * testsuite/23_containers/deque/invalidation/4.cc: Same. * testsuite/23_containers/deque/invalidation/3.cc: Same. * testsuite/23_containers/deque/invalidation/2.cc: Same. * testsuite/23_containers/deque/invalidation/1.cc: Same. * testsuite/23_containers/deque/cons/2.cc: Same. * testsuite/23_containers/deque/cons/1.cc: Same. * src/allocator.cc: Add char, wchar_t instantiations to match extern template declarations in memory.h. From-SVN: r78922
615 lines
12 KiB
C++
615 lines
12 KiB
C++
// 24.1.5 Random access iterators
|
|
// 24.3.1 Iterator traits
|
|
// (basic_string and vector implementations)
|
|
//
|
|
// Copyright (C) 1999, 2003, 2004 Free Software Foundation, Inc.
|
|
// This program is free software; you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program; if not, write to the Free Software
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
// USA
|
|
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
#include <testsuite_hooks.h>
|
|
|
|
int
|
|
string_stuff()
|
|
{
|
|
int failures(0);
|
|
|
|
std::string s("abcde");
|
|
|
|
std::string::iterator i1(s.begin());
|
|
if (*i1 != 'a')
|
|
++failures;
|
|
|
|
++i1;
|
|
if (*i1 != 'b')
|
|
++failures;
|
|
|
|
if (*i1++ != 'b')
|
|
++failures;
|
|
if (*i1 != 'c')
|
|
++failures;
|
|
|
|
++ ++i1;
|
|
if (*i1 != 'e')
|
|
++failures;
|
|
|
|
--i1;
|
|
if (*i1 != 'd')
|
|
++failures;
|
|
|
|
if (*i1-- != 'd')
|
|
++failures;
|
|
if (*i1 != 'c')
|
|
++failures;
|
|
|
|
-- --i1;
|
|
if (*i1 != 'a')
|
|
++failures;
|
|
|
|
std::string::iterator i2;
|
|
i2 = s.end();
|
|
std::iterator_traits<std::string::iterator>::difference_type d1;
|
|
d1 = i2 - i1;
|
|
if (d1 != 5)
|
|
++failures;
|
|
|
|
std::iterator_traits<std::string::iterator>::value_type v1;
|
|
v1 = i1[0];
|
|
if (v1 != 'a')
|
|
++failures;
|
|
|
|
std::iterator_traits<std::string::iterator>::reference r1(i1[0]);
|
|
if (r1 != 'a')
|
|
++failures;
|
|
r1 = 'x';
|
|
if (r1 != 'x')
|
|
++failures;
|
|
r1 = 'a';
|
|
|
|
if ((i1 != i2) != true)
|
|
++failures;
|
|
if ((i1 == i2) != false)
|
|
++failures;
|
|
if ((i1 < i2) != true)
|
|
++failures;
|
|
if ((i1 > i2) != false)
|
|
++failures;
|
|
if ((i1 <= i2) != true)
|
|
++failures;
|
|
if ((i1 >= i2) != false)
|
|
++failures;
|
|
|
|
std::string::iterator i3;
|
|
i3 = i1;
|
|
if ((i3 == i1) != true)
|
|
++failures;
|
|
|
|
i3 += 5;
|
|
if ((i3 == i2) != true)
|
|
++failures;
|
|
|
|
i3 -= 5;
|
|
if ((i3 == i1) != true)
|
|
++failures;
|
|
|
|
if (i3 + 5 != i2)
|
|
++failures;
|
|
|
|
if (5 + i3 != i2)
|
|
++failures;
|
|
|
|
if (i2 - 5 != i3)
|
|
++failures;
|
|
|
|
if (i1[0] != 'a')
|
|
++failures;
|
|
|
|
i1[4] = 'x';
|
|
if (i2[-1] != 'x')
|
|
++failures;
|
|
i1[4] = 'e';
|
|
|
|
i1[2] = 'x';
|
|
if (i2[-3] != 'x')
|
|
++failures;
|
|
i1[2] = 'c';
|
|
|
|
std::string::const_iterator ci1(s.begin());
|
|
if (*ci1 != 'a')
|
|
++failures;
|
|
|
|
++ci1;
|
|
if (*ci1 != 'b')
|
|
++failures;
|
|
|
|
if (*ci1++ != 'b')
|
|
++failures;
|
|
if (*ci1 != 'c')
|
|
++failures;
|
|
|
|
++ ++ci1;
|
|
if (*ci1 != 'e')
|
|
++failures;
|
|
|
|
--ci1;
|
|
if (*ci1 != 'd')
|
|
++failures;
|
|
|
|
if (*ci1-- != 'd')
|
|
++failures;
|
|
if (*ci1 != 'c')
|
|
++failures;
|
|
|
|
-- --ci1;
|
|
if (*ci1 != 'a')
|
|
++failures;
|
|
|
|
std::string::const_iterator ci2;
|
|
ci2 = s.end();
|
|
std::iterator_traits<std::string::const_iterator>::difference_type d2;
|
|
d2 = ci2 - ci1;
|
|
if (d2 != 5)
|
|
++failures;
|
|
|
|
std::iterator_traits<std::string::const_iterator>::value_type v2;
|
|
v2 = ci1[0];
|
|
if (v2 != 'a')
|
|
++failures;
|
|
|
|
std::iterator_traits<std::string::const_iterator>::reference r2(ci1[0]);
|
|
if (r2 != 'a')
|
|
++failures;
|
|
|
|
if ((ci1 != ci2) != true)
|
|
++failures;
|
|
if ((ci1 == ci2) != false)
|
|
++failures;
|
|
if ((ci1 < ci2) != true)
|
|
++failures;
|
|
if ((ci1 > ci2) != false)
|
|
++failures;
|
|
if ((ci1 <= ci2) != true)
|
|
++failures;
|
|
if ((ci1 >= ci2) != false)
|
|
++failures;
|
|
|
|
std::string::const_iterator ci3;
|
|
ci3 = ci1;
|
|
if ((ci3 == ci1) != true)
|
|
++failures;
|
|
|
|
ci3 += 5;
|
|
if ((ci3 == ci2) != true)
|
|
++failures;
|
|
|
|
ci3 -= 5;
|
|
if ((ci3 == ci1) != true)
|
|
++failures;
|
|
|
|
if (ci3 + 5 != ci2)
|
|
++failures;
|
|
|
|
if (5 + ci3 != ci2)
|
|
++failures;
|
|
|
|
if (ci2 - 5 != ci3)
|
|
++failures;
|
|
|
|
if (ci1[2] != 'c')
|
|
++failures;
|
|
|
|
if (ci2[-1] != 'e')
|
|
++failures;
|
|
|
|
// iterator and const_iterator
|
|
std::string::const_iterator ci4(i1);
|
|
if ((ci4 == i1) != true)
|
|
++failures;
|
|
if ((ci4 != i1) != false)
|
|
++failures;
|
|
if ((ci4 < i1) != false)
|
|
++failures;
|
|
if ((ci4 > i1) != false)
|
|
++failures;
|
|
if ((ci4 <= i1) != true)
|
|
++failures;
|
|
if ((ci4 >= i1) != true)
|
|
++failures;
|
|
ci4 = i2;
|
|
if ((i2 == ci4) != true)
|
|
++failures;
|
|
if ((i2 < ci4) != false)
|
|
++failures;
|
|
if ((i2 > ci4) != false)
|
|
++failures;
|
|
if ((i2 <= ci4) != true)
|
|
++failures;
|
|
if ((i2 >= ci4) != true)
|
|
++failures;
|
|
|
|
const std::string cs("ABCDE");
|
|
std::string::const_iterator ci5(cs.begin());
|
|
if (ci5[0] != 'A')
|
|
++failures;
|
|
|
|
return failures;
|
|
}
|
|
|
|
int
|
|
vector_stuff()
|
|
{
|
|
int failures(0);
|
|
|
|
std::vector<int> v;
|
|
v.push_back(int(1));
|
|
v.push_back(int(2));
|
|
v.push_back(int(3));
|
|
v.push_back(int(4));
|
|
v.push_back(int(5));
|
|
|
|
std::vector<int>::iterator i1(v.begin());
|
|
if (*i1 != 1)
|
|
++failures;
|
|
|
|
++i1;
|
|
if (*i1 != 2)
|
|
++failures;
|
|
|
|
if (*i1++ != 2)
|
|
++failures;
|
|
if (*i1 != 3)
|
|
++failures;
|
|
|
|
++ ++i1;
|
|
if (*i1 != 5)
|
|
++failures;
|
|
|
|
--i1;
|
|
if (*i1 != 4)
|
|
++failures;
|
|
|
|
if (*i1-- != 4)
|
|
++failures;
|
|
if (*i1 != 3)
|
|
++failures;
|
|
|
|
-- --i1;
|
|
if (*i1 != 1)
|
|
++failures;
|
|
|
|
std::vector<int>::iterator i2;
|
|
i2 = v.end();
|
|
std::iterator_traits<std::vector<int>::iterator>::difference_type d1;
|
|
d1 = i2 - i1;
|
|
if (d1 != 5)
|
|
++failures;
|
|
|
|
std::iterator_traits<std::vector<int>::iterator>::value_type v1;
|
|
v1 = i1[0];
|
|
if (v1 != 1)
|
|
++failures;
|
|
|
|
std::iterator_traits<std::vector<int>::iterator>::reference r1(i1[0]);
|
|
if (r1 != 1)
|
|
++failures;
|
|
r1 = 9;
|
|
if (r1 != 9)
|
|
++failures;
|
|
r1 = 1;
|
|
|
|
if ((i1 != i2) != true)
|
|
++failures;
|
|
if ((i1 == i2) != false)
|
|
++failures;
|
|
if ((i1 < i2) != true)
|
|
++failures;
|
|
if ((i1 > i2) != false)
|
|
++failures;
|
|
if ((i1 <= i2) != true)
|
|
++failures;
|
|
if ((i1 >= i2) != false)
|
|
++failures;
|
|
|
|
std::vector<int>::iterator i3;
|
|
i3 = i1;
|
|
if ((i3 == i1) != true)
|
|
++failures;
|
|
|
|
i3 += 5;
|
|
if ((i3 == i2) != true)
|
|
++failures;
|
|
|
|
i3 -= 5;
|
|
if ((i3 == i1) != true)
|
|
++failures;
|
|
|
|
if (i3 + 5 != i2)
|
|
++failures;
|
|
|
|
if (5 + i3 != i2)
|
|
++failures;
|
|
|
|
if (i2 - 5 != i3)
|
|
++failures;
|
|
|
|
if (i1[0] != 1)
|
|
++failures;
|
|
|
|
i1[4] = 9;
|
|
if (i2[-1] != 9)
|
|
++failures;
|
|
i1[4] = 5;
|
|
|
|
i1[2] = 9;
|
|
if (i2[-3] != 9)
|
|
++failures;
|
|
i1[2] = 3;
|
|
|
|
std::vector<int>::const_iterator ci1(v.begin());
|
|
if (*ci1 != 1)
|
|
++failures;
|
|
|
|
++ci1;
|
|
if (*ci1 != 2)
|
|
++failures;
|
|
|
|
if (*ci1++ != 2)
|
|
++failures;
|
|
if (*ci1 != 3)
|
|
++failures;
|
|
|
|
++ ++ci1;
|
|
if (*ci1 != 5)
|
|
++failures;
|
|
|
|
--ci1;
|
|
if (*ci1 != 4)
|
|
++failures;
|
|
|
|
if (*ci1-- != 4)
|
|
++failures;
|
|
if (*ci1 != 3)
|
|
++failures;
|
|
|
|
-- --ci1;
|
|
if (*ci1 != 1)
|
|
++failures;
|
|
|
|
std::vector<int>::const_iterator ci2;
|
|
ci2 = v.end();
|
|
std::iterator_traits<std::vector<int>::const_iterator>::difference_type d2;
|
|
d2 = ci2 - ci1;
|
|
if (d2 != 5)
|
|
++failures;
|
|
|
|
std::iterator_traits<std::vector<int>::const_iterator>::value_type v2;
|
|
v2 = ci1[0];
|
|
if (v2 != 1)
|
|
++failures;
|
|
|
|
std::iterator_traits<std::vector<int>::const_iterator>::reference
|
|
r2(ci1[0]);
|
|
if (r2 != 1)
|
|
++failures;
|
|
|
|
if ((ci1 != ci2) != true)
|
|
++failures;
|
|
if ((ci1 == ci2) != false)
|
|
++failures;
|
|
if ((ci1 < ci2) != true)
|
|
++failures;
|
|
if ((ci1 > ci2) != false)
|
|
++failures;
|
|
if ((ci1 <= ci2) != true)
|
|
++failures;
|
|
if ((ci1 >= ci2) != false)
|
|
++failures;
|
|
|
|
std::vector<int>::const_iterator ci3;
|
|
ci3 = ci1;
|
|
if ((ci3 == ci1) != true)
|
|
++failures;
|
|
|
|
ci3 += 5;
|
|
if ((ci3 == ci2) != true)
|
|
++failures;
|
|
|
|
ci3 -= 5;
|
|
if ((ci3 == ci1) != true)
|
|
++failures;
|
|
|
|
if (ci3 + 5 != ci2)
|
|
++failures;
|
|
|
|
if (5 + ci3 != ci2)
|
|
++failures;
|
|
|
|
if (ci2 - 5 != ci3)
|
|
++failures;
|
|
|
|
if (ci1[2] != 3)
|
|
++failures;
|
|
|
|
if (ci2[-1] != 5)
|
|
++failures;
|
|
|
|
// iterator to const_iterator
|
|
std::vector<int>::const_iterator ci4(i1);
|
|
if ((ci4 == i1) != true)
|
|
++failures;
|
|
if ((ci4 != i1) != false)
|
|
++failures;
|
|
if ((ci4 < i1) != false)
|
|
++failures;
|
|
if ((ci4 > i1) != false)
|
|
++failures;
|
|
if ((ci4 <= i1) != true)
|
|
++failures;
|
|
if ((ci4 >= i1) != true)
|
|
++failures;
|
|
ci4 = i2;
|
|
if ((i2 == ci4) != true)
|
|
++failures;
|
|
if ((i2 < ci4) != false)
|
|
++failures;
|
|
if ((i2 > ci4) != false)
|
|
++failures;
|
|
if ((i2 <= ci4) != true)
|
|
++failures;
|
|
if ((i2 >= ci4) != true)
|
|
++failures;
|
|
|
|
const std::vector<int> cv(v);
|
|
std::vector<int>::const_iterator ci5(cv.begin());
|
|
if (ci5[0] != 1)
|
|
++failures;
|
|
|
|
std::vector<std::string> vs;
|
|
vs.push_back(std::string("abc"));
|
|
std::vector<std::string>::iterator ivs(vs.begin());
|
|
if (ivs->c_str()[1] != 'b')
|
|
++failures;
|
|
|
|
return failures;
|
|
}
|
|
|
|
int
|
|
reverse_stuff()
|
|
{
|
|
int failures(0);
|
|
|
|
std::string s("abcde");
|
|
|
|
std::string::reverse_iterator ri(s.rbegin());
|
|
if (*ri != 'e')
|
|
++failures;
|
|
|
|
std::iterator_traits<std::string::reverse_iterator>::difference_type d;
|
|
d = s.rend() - ri;
|
|
if (d != 5)
|
|
++failures;
|
|
|
|
const std::string cs("abcde");
|
|
std::string::const_reverse_iterator cri(cs.rend());
|
|
if (cri - 5 != cs.rbegin())
|
|
++failures;
|
|
|
|
return failures;
|
|
}
|
|
|
|
// the following should be compiler errors
|
|
// flag runtime errors in case they slip through the compiler
|
|
int
|
|
wrong_stuff()
|
|
{
|
|
int failures(0);
|
|
|
|
#ifdef ITER24_F1
|
|
extern void f(std::vector<std::string*>::iterator);
|
|
std::vector<std::string*> vs[2];
|
|
f(vs); // address of array is not an iterator
|
|
failures++;
|
|
#endif
|
|
|
|
#ifdef ITER24_F2
|
|
std::string s;
|
|
char *i = s.begin(); // begin() doesn't return a pointer
|
|
failures++;
|
|
#endif
|
|
|
|
#ifdef ITER24_F3
|
|
std::string::const_iterator ci;
|
|
std::string::iterator i;
|
|
if (i - ci) // remove const_ is a warning
|
|
i++;
|
|
// failures++; only a warning
|
|
#endif
|
|
|
|
#ifdef ITER24_F4
|
|
std::vector<char>::iterator iv;
|
|
std::string::iterator is(iv);// vector<char> is not string
|
|
failures++;
|
|
#endif
|
|
|
|
#ifdef ITER24_F5
|
|
std::vector<char>::iterator iv;
|
|
std::string::iterator is;
|
|
if (iv == is) // vector<char> is not string
|
|
++iv;
|
|
failures++;
|
|
#endif
|
|
|
|
#ifdef ITER24_F6
|
|
std::vector<char>::const_iterator ci;
|
|
std::vector<char>::iterator i = ci; // remove const_ is a warning
|
|
++i;
|
|
// failures++; only a warning
|
|
#endif
|
|
|
|
#ifdef ITER24_F7
|
|
std::vector<int> v(1);
|
|
std::vector<int>::const_iterator ci(v.begin());
|
|
*ci = 1; // cannot assign through const_iterator
|
|
failures++;
|
|
#endif
|
|
|
|
#ifdef ITER24_F8
|
|
std::vector<const int> v(1);
|
|
std::vector<const int>::reference r(v.begin()[0]);
|
|
r = 1; // cannot assign through reference to const
|
|
failures++;
|
|
#endif
|
|
|
|
return failures;
|
|
}
|
|
|
|
// libstdc++/6642
|
|
int
|
|
test6642()
|
|
{
|
|
std::string s;
|
|
std::string::iterator it = s.begin();
|
|
std::string::const_iterator cit = s.begin();
|
|
|
|
return it - cit;
|
|
}
|
|
|
|
#if !__GXX_WEAK__ && _MT_ALLOCATOR_H
|
|
// Explicitly instantiate for systems with no COMDAT or weak support.
|
|
template class __gnu_cxx::__mt_alloc<int>;
|
|
template class __gnu_cxx::__mt_alloc<std::string>;
|
|
#endif
|
|
|
|
int
|
|
main()
|
|
{
|
|
int failures(0);
|
|
|
|
failures += string_stuff();
|
|
|
|
failures += vector_stuff();
|
|
|
|
failures += reverse_stuff();
|
|
|
|
failures += wrong_stuff();
|
|
|
|
failures += test6642();
|
|
|
|
VERIFY(failures == 0);
|
|
return 0;
|
|
}
|