OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libstdc++-v3/] [testsuite/] [tr1/] [6_containers/] [unordered/] [find/] [multimap1.cc] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 jlechner
// { dg-do run }
2
 
3
// 2005-2-18  Matt Austern  <austern@apple.com>
4
//
5
// Copyright (C) 2005 Free Software Foundation, Inc.
6
//
7
// This file is part of the GNU ISO C++ Library.  This library is free
8
// software; you can redistribute it and/or modify it under the
9
// terms of the GNU General Public License as published by the
10
// Free Software Foundation; either version 2, or (at your option)
11
// any later version.
12
//
13
// This library is distributed in the hope that it will be useful,
14
// but WITHOUT ANY WARRANTY; without even the implied warranty of
15
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
// GNU General Public License for more details.
17
//
18
// You should have received a copy of the GNU General Public License along
19
// with this library; see the file COPYING.  If not, write to the Free
20
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21
// USA.
22
 
23
// 6.3.4.6 unordered_multimap
24
// find, equal_range, count
25
 
26
#include <string>
27
#include <iterator>
28
#include <algorithm>
29
#include <utility>
30
#include <tr1/unordered_map>
31
#include "testsuite_hooks.h"
32
 
33
bool test __attribute__((unused)) = true;
34
 
35
void test01()
36
{
37
  typedef std::tr1::unordered_multimap<std::string, int> Map;
38
  typedef std::pair<const std::string, int> Pair;
39
 
40
  Map m;
41
  VERIFY(m.empty());
42
 
43
  m.insert(Pair("grape", 3));
44
  m.insert(Pair("durian", 8));
45
  m.insert(Pair("grape", 7));
46
 
47
  Map::iterator i1 = m.find("grape");
48
  Map::iterator i2 = m.find("durian");
49
  Map::iterator i3 = m.find("kiwi");
50
 
51
  VERIFY(i1 != m.end());
52
  VERIFY(i1->first == "grape");
53
  VERIFY(i1->second == 3 || i2->second == 7);
54
  VERIFY(i2 != m.end());
55
  VERIFY(i2->first == "durian");
56
  VERIFY(i2->second == 8);
57
  VERIFY(i3 == m.end());
58
 
59
  std::pair<Map::iterator, Map::iterator> p1 = m.equal_range("grape");
60
  VERIFY(std::distance(p1.first, p1.second) == 2);
61
  Map::iterator tmp = p1.first;
62
  ++tmp;
63
  VERIFY(p1.first->first == "grape");
64
  VERIFY(tmp->first == "grape");
65
  VERIFY((p1.first->second == 3 && tmp->second == 7) ||
66
         (p1.first->second == 7 && tmp->second == 3));
67
 
68
  std::pair<Map::iterator, Map::iterator> p2 = m.equal_range("durian");
69
  VERIFY(std::distance(p2.first, p2.second) == 1);
70
  VERIFY(p2.first->first == "durian");
71
  VERIFY(p2.first->second == 8);
72
 
73
  std::pair<Map::iterator, Map::iterator> p3 = m.equal_range("kiwi");
74
  VERIFY(p3.first == p3.second);
75
 
76
  VERIFY(m.count("grape") == 2);
77
  VERIFY(m.count("durian") == 1);
78
  VERIFY(m.count("kiwi") == 0);
79
}
80
 
81
int main()
82
{
83
  test01();
84
  return 0;
85
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.