PR libstdc++/19664 round 3
[platform/upstream/gcc.git] / libstdc++-v3 / include / tr1 / unordered_map
1 // TR1 unordered_map -*- C++ -*-
2
3 // Copyright (C) 2005, 2006 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.
10
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.
15
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,
19 // USA.
20
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction.  Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License.  This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
29
30 /** @file 
31  *  This is a TR1 C++ Library header. 
32  */
33
34 #ifndef _TR1_UNORDERED_MAP
35 #define _TR1_UNORDERED_MAP 1
36
37 #include <tr1/hashtable>
38 #include <tr1/functional>
39
40 namespace std
41 {
42 _GLIBCXX_BEGIN_NAMESPACE(tr1)
43
44   // XXX When we get typedef templates these class definitions
45   // will be unnecessary.
46   template<class Key, class T,
47            class Hash = hash<Key>,
48            class Pred = std::equal_to<Key>,
49            class Alloc = std::allocator<std::pair<const Key, T> >,
50            bool cache_hash_code = false>
51     class unordered_map
52     : public hashtable<Key, std::pair<const Key, T>, Alloc,
53                        detail::extract1st<std::pair<const Key, T> >, Pred, 
54                        Hash, detail::mod_range_hashing,
55                        detail::default_ranged_hash,
56                        detail::prime_rehash_policy,
57                        cache_hash_code, false, true>
58     {
59       typedef hashtable<Key, std::pair<const Key, T>, Alloc,
60                         detail::extract1st<std::pair<const Key, T> >, Pred,
61                         Hash, detail::mod_range_hashing,
62                         detail::default_ranged_hash,
63                         detail::prime_rehash_policy,
64                         cache_hash_code, false, true>
65       Base;
66
67     public:
68       typedef typename Base::size_type size_type;
69       typedef typename Base::hasher hasher;
70       typedef typename Base::key_equal key_equal;
71       typedef typename Base::allocator_type allocator_type;
72
73       explicit
74       unordered_map(size_type n = 10,
75                     const hasher& hf = hasher(),
76                     const key_equal& eql = key_equal(),
77                     const allocator_type& a = allocator_type())
78       : Base(n, hf, detail::mod_range_hashing(),
79              detail::default_ranged_hash(),
80              eql, detail::extract1st<std::pair<const Key, T> >(), a)
81       { }
82
83       template<typename InputIterator>
84         unordered_map(InputIterator f, InputIterator l, 
85                       size_type n = 10,
86                       const hasher& hf = hasher(), 
87                       const key_equal& eql = key_equal(), 
88                       const allocator_type& a = allocator_type())
89         : Base (f, l, n, hf, detail::mod_range_hashing(),
90                 detail::default_ranged_hash(),
91                 eql, detail::extract1st<std::pair<const Key, T> >(), a)
92         { }
93     };
94   
95   template<class Key, class T,
96            class Hash = hash<Key>,
97            class Pred = std::equal_to<Key>,
98            class Alloc = std::allocator<std::pair<const Key, T> >,
99            bool cache_hash_code = false>
100     class unordered_multimap
101     : public hashtable <Key, std::pair<const Key, T>,
102                         Alloc,
103                         detail::extract1st<std::pair<const Key, T> >, Pred,
104                         Hash, detail::mod_range_hashing,
105                         detail::default_ranged_hash,
106                         detail::prime_rehash_policy,
107                         cache_hash_code, false, false>
108     {
109       typedef hashtable <Key, std::pair<const Key, T>,
110                          Alloc,
111                          detail::extract1st<std::pair<const Key, T> >, Pred,
112                          Hash, detail::mod_range_hashing,
113                          detail::default_ranged_hash,
114                          detail::prime_rehash_policy,
115                          cache_hash_code, false, false>
116         Base;
117
118     public:
119       typedef typename Base::size_type size_type;
120       typedef typename Base::hasher hasher;
121       typedef typename Base::key_equal key_equal;
122       typedef typename Base::allocator_type allocator_type;
123       
124       explicit
125       unordered_multimap(size_type n = 10,
126                          const hasher& hf = hasher(),
127                          const key_equal& eql = key_equal(),
128                          const allocator_type& a = allocator_type())
129       : Base (n, hf, detail::mod_range_hashing(),
130               detail::default_ranged_hash(),
131               eql, detail::extract1st<std::pair<const Key, T> >(), a)
132       { }
133
134
135       template<typename InputIterator>
136         unordered_multimap(InputIterator f, InputIterator l, 
137                            typename Base::size_type n = 0,
138                            const hasher& hf = hasher(), 
139                            const key_equal& eql = key_equal(), 
140                            const allocator_type& a = allocator_type())
141         : Base (f, l, n, hf, detail::mod_range_hashing(),
142                 detail::default_ranged_hash(),
143                 eql, detail::extract1st<std::pair<const Key, T> >(), a)
144         { }
145     };
146
147   template<class Key, class T, class Hash, class Pred, class Alloc,
148            bool cache_hash_code>
149     inline void
150     swap(unordered_map<Key, T, Hash, Pred, Alloc, cache_hash_code>& x,
151          unordered_map<Key, T, Hash, Pred, Alloc, cache_hash_code>& y)
152     { x.swap(y); }
153
154   template<class Key, class T, class Hash, class Pred, class Alloc,
155            bool cache_hash_code>
156     inline void
157     swap(unordered_multimap<Key, T, Hash, Pred, Alloc, cache_hash_code>& x,
158          unordered_multimap<Key, T, Hash, Pred, Alloc, cache_hash_code>& y)
159     { x.swap(y); }
160
161 _GLIBCXX_END_NAMESPACE
162 }
163
164 #endif // _TR1_UNORDERED_MAP