2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libstdc++-v3 / testsuite / 23_containers / multiset / insert / 1.cc
blobb82612f5c7fffc1851578405209f31e8917bc094
1 // 1999-06-24 bkoz
3 // Copyright (C) 1999 Free Software Foundation, Inc.
4 //
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)
9 // any later version.
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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
21 // 23.3.4 template class multiset
23 #include <iostream>
24 #include <iterator>
25 #include <set>
26 #include <algorithm>
28 namespace std
30 std::ostream&
31 operator<<(std::ostream& os, std::pair<int, int> const& p)
32 { return os << p.first << ' ' << p.second; }
35 bool
36 operator<(std::pair<int, int> const& lhs, std::pair<int, int> const& rhs)
37 { return lhs.first < rhs.first; }
39 int main ()
41 typedef std::multiset<std::pair<int, int> >::iterator iterator;
42 std::pair<int, int> p(69, 0);
43 std::multiset<std::pair<int, int> > s;
45 for (p.second = 0; p.second < 5; ++p.second)
46 s.insert(p);
47 for (iterator it = s.begin(); it != s.end(); ++it)
48 if (it->second < 5)
50 s.insert(it, p);
51 ++p.second;
54 // XXX need to use debug-assert here and get this working with an
55 // ostrinsrtream, that way we can just check the strings for
56 // equivalance.
57 std::copy(s.begin(), s.end(),
58 std::ostream_iterator<std::pair<int, int> >(std::cout, "\n"));
60 return 0;
63 /* output:
64 69 5
65 69 0
66 69 6
67 69 1
68 69 7
69 69 2
70 69 8
71 69 3
72 69 9
73 69 4