]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/ext/pb_assoc/detail/eq_fn/hash_eq_fn.hpp
* typeck.c (build_modify_expr): Tidy diagnostic message.
[thirdparty/gcc.git] / libstdc++-v3 / include / ext / pb_assoc / detail / eq_fn / hash_eq_fn.hpp
CommitLineData
fd1e1726
BK
1// -*- C++ -*-
2
3// Copyright (C) 2005 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
83f51799 18// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
fd1e1726
BK
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// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
31
32// Permission to use, copy, modify, sell, and distribute this software
33// is hereby granted without fee, provided that the above copyright
34// notice appears in all copies, and that both that copyright notice and
35// this permission notice appear in supporting documentation. None of
36// the above authors, nor IBM Haifa Research Laboratories, make any
37// representation about the suitability of this software for any
38// purpose. It is provided "as is" without express or implied warranty.
39
40/**
41 * @file hash_eq_fn.hpp
42 * Contains 2 eqivalence functions, one employing a hash value,
43 * and one ignoring it.
44 */
45
46#ifndef HASH_EQ_FN_HPP
47#define HASH_EQ_FN_HPP
48
49#include <utility>
50
51namespace pb_assoc
52{
53
54 namespace detail
55 {
56
57#ifdef PB_ASSOC_HASH_EQ_FN_DEBUG
58#define PB_ASSOC_DBG_ASSERT(X) assert(X)
59#define PB_ASSOC_DBG_VERIFY(X) assert(X)
60#define PB_ASSOC_DBG_ONLY(X) X
61#else // #ifdef PB_ASSOC_HASH_EQ_FN_DEBUG
62#define PB_ASSOC_DBG_ASSERT(X)
63#define PB_ASSOC_DBG_VERIFY(X) {if((X)==0);}
64#define PB_ASSOC_DBG_ONLY(X) ;
65#endif // #ifdef PB_ASSOC_HASH_EQ_FN_DEBUG
66
67 template<typename Key, class Eq_Fn, class Allocator, bool Store_Hash>
68 struct hash_eq_fn;
69
70#define PB_ASSOC_CLASS_T_DEC \
71 template<typename Key, class Eq_Fn, class Allocator>
72
73#define PB_ASSOC_CLASS_C_DEC \
74 hash_eq_fn< \
75 Key, \
76 Eq_Fn, \
77 Allocator, \
78 false>
79
80 /**
81 * Specialization 1- The client requests that hash values not be stored.
82 **/
83 template<typename Key, class Eq_Fn, class Allocator>
84 struct hash_eq_fn<Key, Eq_Fn, Allocator, false> : public Eq_Fn
85 {
86 typedef Eq_Fn my_eq_fn_base;
87
88 typedef typename Allocator::template rebind<Key>::other key_allocator;
89
90 typedef typename key_allocator::const_reference const_key_reference;
91
92 hash_eq_fn();
93
94 hash_eq_fn(const Eq_Fn& r_eq_fn);
95
96 inline bool
97 operator()(const_key_reference r_lhs_key, const_key_reference r_rhs_key) const;
98
99 inline void
100 swap(const PB_ASSOC_CLASS_C_DEC& r_other);
101 };
102
103 PB_ASSOC_CLASS_T_DEC
104 PB_ASSOC_CLASS_C_DEC::
105 hash_eq_fn()
106 { }
107
108 PB_ASSOC_CLASS_T_DEC
109 inline void
110 PB_ASSOC_CLASS_C_DEC::
111 swap(const PB_ASSOC_CLASS_C_DEC& r_other)
112 {
113 std::swap((Eq_Fn& )(*this), (Eq_Fn& )r_other);
114 }
115
116 PB_ASSOC_CLASS_T_DEC
117 PB_ASSOC_CLASS_C_DEC::
118 hash_eq_fn(const Eq_Fn& r_eq_fn) :
119 Eq_Fn(r_eq_fn)
120 { }
121
122 PB_ASSOC_CLASS_T_DEC
123 inline bool
124 PB_ASSOC_CLASS_C_DEC::
125 operator()(const_key_reference r_lhs_key, const_key_reference r_rhs_key) const
126 {
127 return (my_eq_fn_base::operator()(r_lhs_key, r_rhs_key));
128 }
129
130#undef PB_ASSOC_CLASS_T_DEC
131#undef PB_ASSOC_CLASS_C_DEC
132
133#define PB_ASSOC_CLASS_T_DEC \
134 template<typename Key, class Eq_Fn, class Allocator>
135
136#define PB_ASSOC_CLASS_C_DEC \
137 hash_eq_fn< \
138 Key, \
139 Eq_Fn, \
140 Allocator, \
141 true>
142
143 /**
144 * Specialization 2- The client requests that hash values be stored.
145 **/
146 template<typename Key, class Eq_Fn, class Allocator>
147 struct hash_eq_fn<Key, Eq_Fn, Allocator, true> :
148 public Eq_Fn
149 {
150 typedef typename Allocator::size_type size_type;
151
152 typedef Eq_Fn my_eq_fn_base;
153
154 typedef typename Allocator::template rebind<Key>::other key_allocator;
155
156 typedef typename key_allocator::const_reference const_key_reference;
157
158 hash_eq_fn();
159
160 hash_eq_fn(const Eq_Fn& r_eq_fn);
161
162 inline bool
163 operator()(const_key_reference r_lhs_key, size_type lhs_hash, const_key_reference r_rhs_key, size_type rhs_hash) const;
164
165 inline void
166 swap(const PB_ASSOC_CLASS_C_DEC& r_other);
167 };
168
169 PB_ASSOC_CLASS_T_DEC
170 PB_ASSOC_CLASS_C_DEC::
171 hash_eq_fn()
172 { }
173
174 PB_ASSOC_CLASS_T_DEC
175 PB_ASSOC_CLASS_C_DEC::
176 hash_eq_fn(const Eq_Fn& r_eq_fn) :
177 Eq_Fn(r_eq_fn)
178 { }
179
180 PB_ASSOC_CLASS_T_DEC
181 inline bool
182 PB_ASSOC_CLASS_C_DEC::
183 operator()(const_key_reference r_lhs_key, size_type lhs_hash, const_key_reference r_rhs_key, size_type rhs_hash) const
184 {
185 PB_ASSOC_DBG_ASSERT(!my_eq_fn_base::operator()(r_lhs_key, r_rhs_key) ||
186 lhs_hash == rhs_hash);
187
188 return (lhs_hash == rhs_hash&&
189 my_eq_fn_base::operator()(r_lhs_key, r_rhs_key));
190 }
191
192 PB_ASSOC_CLASS_T_DEC
193 inline void
194 PB_ASSOC_CLASS_C_DEC::
195 swap(const PB_ASSOC_CLASS_C_DEC& r_other)
196 {
197 std::swap((Eq_Fn& )(*this), (Eq_Fn& )(r_other));
198 }
199
200#undef PB_ASSOC_CLASS_T_DEC
201#undef PB_ASSOC_CLASS_C_DEC
202
203#undef PB_ASSOC_DBG_ASSERT
204#undef PB_ASSOC_DBG_VERIFY
205#undef PB_ASSOC_DBG_ONLY
206
207 } // namespace detail
208
209} // namespace pb_assoc
210
211#endif // #ifndef HASH_EQ_FN_HPP