Line data Source code
1 : /* src/future/unordered_map.hpp - future unordered_map library features
2 :
3 : Copyright (C) 1996-2013
4 : CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 :
6 : This file is part of CACAO.
7 :
8 : This program is free software; you can redistribute it and/or
9 : modify it under the terms of the GNU General Public License as
10 : published by the Free Software Foundation; either version 2, or (at
11 : your option) any later version.
12 :
13 : This program is distributed in the hope that it will be useful, but
14 : WITHOUT ANY WARRANTY; without even the implied warranty of
15 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 : General Public License for more details.
17 :
18 : You should have received a copy of the GNU General Public License
19 : along with this program; if not, write to the Free Software
20 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 : 02110-1301, USA.
22 :
23 : */
24 :
25 :
26 : #ifndef FUTURE_UNORDERED_MAP_HPP_
27 : #define FUTURE_UNORDERED_MAP_HPP_ 1
28 :
29 : #include "config.h"
30 :
31 : // get unordered_map
32 : #if HAVE_STD_TR1_UNORDERED_MAP
33 :
34 : #include <tr1/unordered_map>
35 :
36 : namespace cacao {
37 :
38 : namespace _future = std::tr1;
39 : const std::size_t unordered_map_default_bucket_count = 10;
40 :
41 : } // end namespace cacao
42 :
43 : #elif HAVE_BOOST_UNORDERED_MAP
44 :
45 : #include <boost/unordered_map.hpp>
46 :
47 : namespace cacao {
48 :
49 : namespace _future = boost;
50 : const std::size_t unordered_map_default_bucket_count = boost::unordered::detail::default_bucket_count;
51 :
52 : } // end namespace cacao
53 :
54 : #else
55 : #error "No implementation of unordered_map available"
56 : #endif
57 :
58 : #include "future/future_hash.hpp"
59 :
60 : namespace cacao {
61 :
62 : #if 0
63 : // we want this:
64 : template<
65 : class Key,
66 : class Hash = cacao::hash<Key>,
67 : class KeyEqual = std::equal_to<Key>,
68 : class Allocator = std::allocator<std::pair<const Key, T> >
69 : > using unordered_map = public _future::unordered_map<Key,Hash,KeyEqual,Allocator>;
70 : #endif
71 :
72 : template<
73 : class Key,
74 : class T,
75 : class Hash = cacao::hash<Key>,
76 : class KeyEqual = std::equal_to<Key>,
77 : class Allocator = std::allocator<std::pair<const Key, T> >
78 : >
79 165 : class unordered_map : public _future::unordered_map<Key,T,Hash,KeyEqual,Allocator> {
80 : typedef _future::unordered_map<Key,T,Hash,KeyEqual,Allocator> _Base;
81 : public:
82 : typedef typename _Base::key_type key_type;
83 : typedef typename _Base::mapped_type mapped_type;
84 : typedef typename _Base::value_type value_type;
85 : typedef typename _Base::size_type size_type;
86 : typedef typename _Base::difference_type difference_type;
87 : typedef typename _Base::hasher hasher;
88 : typedef typename _Base::key_equal key_equal;
89 : typedef typename _Base::allocator_type allocator_type;
90 : typedef typename _Base::reference reference;
91 : typedef typename _Base::const_reference const_reference;
92 : typedef typename _Base::pointer pointer;
93 : typedef typename _Base::const_pointer const_pointer;
94 : typedef typename _Base::iterator iterator;
95 : typedef typename _Base::const_iterator const_iterator;
96 : typedef typename _Base::local_iterator local_iterator;
97 : typedef typename _Base::const_local_iterator const_local_iterator;
98 :
99 165 : explicit unordered_map(
100 : size_type bucket_count = unordered_map_default_bucket_count,
101 : const Hash& hash = Hash(),
102 : const KeyEqual& equal = KeyEqual(),
103 : const Allocator& alloc = Allocator())
104 165 : : _Base(bucket_count, hash, equal, alloc) {}
105 :
106 : explicit unordered_map(
107 : const Allocator& alloc)
108 : : _Base(alloc) {}
109 :
110 : template<class InputIt>
111 : unordered_map(
112 : InputIt first,
113 : InputIt last,
114 : size_type bucket_count = unordered_map_default_bucket_count,
115 : const Hash& hash = Hash(),
116 : const KeyEqual& equal = KeyEqual(),
117 : const Allocator& alloc = Allocator())
118 : : _Base(first, last, bucket_count, hash, equal, alloc) {}
119 :
120 : unordered_map(const unordered_map& other) : _Base(other) {}
121 :
122 : unordered_map(const unordered_map& other, const Allocator& alloc) : _Base(other,alloc) {}
123 :
124 : };
125 :
126 : template<
127 : class Key,
128 : class T,
129 : class Hash = cacao::hash<Key>,
130 : class KeyEqual = std::equal_to<Key>,
131 : class Allocator = std::allocator<std::pair<const Key, T> >
132 : >
133 : class unordered_multimap : public _future::unordered_multimap<Key,T,Hash,KeyEqual,Allocator> {
134 : typedef _future::unordered_multimap<Key,T,Hash,KeyEqual,Allocator> _Base;
135 : public:
136 : typedef typename _Base::key_type key_type;
137 : typedef typename _Base::mapped_type mapped_type;
138 : typedef typename _Base::value_type value_type;
139 : typedef typename _Base::size_type size_type;
140 : typedef typename _Base::difference_type difference_type;
141 : typedef typename _Base::hasher hasher;
142 : typedef typename _Base::key_equal key_equal;
143 : typedef typename _Base::allocator_type allocator_type;
144 : typedef typename _Base::reference reference;
145 : typedef typename _Base::const_reference const_reference;
146 : typedef typename _Base::pointer pointer;
147 : typedef typename _Base::const_pointer const_pointer;
148 : typedef typename _Base::iterator iterator;
149 : typedef typename _Base::const_iterator const_iterator;
150 : typedef typename _Base::local_iterator local_iterator;
151 : typedef typename _Base::const_local_iterator const_local_iterator;
152 :
153 : explicit unordered_multimap(
154 : size_type bucket_count = unordered_map_default_bucket_count,
155 : const Hash& hash = Hash(),
156 : const KeyEqual& equal = KeyEqual(),
157 : const Allocator& alloc = Allocator())
158 : : _Base(bucket_count, hash, equal, alloc) {}
159 :
160 : explicit unordered_multimap(
161 : const Allocator& alloc)
162 : : _Base(alloc) {}
163 :
164 : template<class InputIt>
165 : unordered_multimap(
166 : InputIt first,
167 : InputIt last,
168 : size_type bucket_count = unordered_map_default_bucket_count,
169 : const Hash& hash = Hash(),
170 : const KeyEqual& equal = KeyEqual(),
171 : const Allocator& alloc = Allocator())
172 : : _Base(first, last, bucket_count, hash, equal, alloc) {}
173 :
174 : unordered_multimap(const unordered_multimap& other) : _Base(other) {}
175 :
176 : unordered_multimap(const unordered_multimap& other, const Allocator& alloc) : _Base(other,alloc) {}
177 :
178 : };
179 :
180 : } // end namespace cacao
181 :
182 : #endif /* FUTURE_UNORDERED_MAP_HPP_ */
183 :
184 : /*
185 : * These are local overrides for various environment variables in Emacs.
186 : * Please do not remove this and leave it at the end of the file, where
187 : * Emacs will automagically detect them.
188 : * ---------------------------------------------------------------------
189 : * Local variables:
190 : * mode: c++
191 : * indent-tabs-mode: t
192 : * c-basic-offset: 4
193 : * tab-width: 4
194 : * End:
195 : * vim:noexpandtab:sw=4:ts=4:
196 : */
|