Merge -r 127928:132243 from trunk
[official-gcc.git] / libstdc++-v3 / testsuite / ext / pb_ds / example / hash_find_neg.cc
blobc77e6e0a141050b56acb6f42bed875f3e0ed1093
1 // { dg-do compile }
2 // -*- C++ -*-
4 // Copyright (C) 2005, 2006 Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the terms
8 // of the GNU General Public License as published by the Free Software
9 // Foundation; either version 2, or (at your option) any later
10 // version.
12 // This library is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this library; see the file COPYING. If not, write to
19 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
20 // MA 02111-1307, USA.
22 // As a special exception, you may use this file as part of a free
23 // software library without restriction. Specifically, if other files
24 // instantiate templates or use macros or inline functions from this
25 // file, or you compile this file and link it with other files to
26 // produce an executable, this file does not by itself cause the
27 // resulting executable to be covered by the GNU General Public
28 // License. This exception does not however invalidate any other
29 // reasons why the executable file might be covered by the GNU General
30 // Public License.
32 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
34 // Permission to use, copy, modify, sell, and distribute this software
35 // is hereby granted without fee, provided that the above copyright
36 // notice appears in all copies, and that both that copyright notice
37 // and this permission notice appear in supporting documentation. None
38 // of the above authors, nor IBM Haifa Research Laboratories, make any
39 // representation about the suitability of this software for any
40 // purpose. It is provided "as is" without express or implied
41 // warranty.
43 /**
44 * @file hash_bad_find_example.cpp
45 * An example showing how *not* to use unordered containers.
48 /**
49 * This non-compiling example shows wrong use of unordered
50 * associative-containers. These types of containers have distinct
51 * point-type and range-type iterator types.
52 **/
54 #include <utility>
55 #include <ext/pb_ds/assoc_container.hpp>
57 using namespace std;
58 using namespace __gnu_pbds;
60 int main()
62 // A collision-chaining hash table mapping ints to chars.
63 typedef cc_hash_table<int, char> map_t;
65 // A map_t object.
66 map_t h;
68 // Insert a value mapping the int 1 to the char 'a'.
69 h.insert(make_pair(1, 'a'));
71 // Find the entry of the key '1' the* wrong* way.
72 // The following line will not compile, since map_t::find returns a
73 // point-iterator, which, by design, is not convertible to a
74 // range-iterator.
75 map_t::iterator it = h.find(1); // { dg-error "conversion from" }
77 return 0;