libDwm-0.6.0
DwmOperators.hh
Go to the documentation of this file.
1 //===========================================================================
2 // @(#) $DwmPath: dwm/libDwm/tags/libDwm-0.6.0/include/DwmOperators.hh 8401 $
3 // @(#) $Id: DwmOperators.hh 8401 2016-04-17 06:44:31Z dwm $
4 //===========================================================================
5 // Copyright (c) Daniel W. McRobb 2007, 2016
6 // All rights reserved.
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions
10 // are met:
11 //
12 // 1. Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // 2. Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 // 3. The names of the authors and copyright holders may not be used to
18 // endorse or promote products derived from this software without
19 // specific prior written permission.
20 //
21 // IN NO EVENT SHALL DANIEL W. MCROBB BE LIABLE TO ANY PARTY FOR
22 // DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
23 // INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE,
24 // EVEN IF DANIEL W. MCROBB HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
25 // DAMAGE.
26 //
27 // THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND
28 // DANIEL W. MCROBB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
29 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. DANIEL W. MCROBB MAKES NO
30 // REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND, EITHER
31 // IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32 // WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE,
33 // OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
34 // TRADEMARK OR OTHER RIGHTS.
35 //===========================================================================
36 
37 //---------------------------------------------------------------------------
40 //---------------------------------------------------------------------------
41 
42 #ifndef _DWMOPERATORS_HH_
43 #define _DWMOPERATORS_HH_
44 
45 #include <unordered_map>
46 #include <unordered_set>
47 
48 #include "DwmPortability.hh"
49 
50 //----------------------------------------------------------------------------
52 //----------------------------------------------------------------------------
53 #if (! defined(__clang__))
54 #if (! HAVE_GPLUSPLUS_VERSION(4,6))
55 template <typename _keyT, typename _valueT, typename _Hash,
56  typename _Pred, typename _Alloc>
57 bool operator ==
58 (const std::unordered_map<_keyT, _valueT, _Hash, _Pred, _Alloc> & a,
59  const std::unordered_map<_keyT, _valueT, _Hash, _Pred, _Alloc> & b)
60 {
61  if (a.size() != b.size())
62  return(false);
63  typename std::unordered_map<_keyT, _valueT, _Hash, _Pred, _Alloc>::const_iterator
64  ai, bi;
65  for (ai = a.begin(); ai != a.end(); ++ai) {
66  bi = b.find(ai->first);
67  if (bi == b.end())
68  return(false);
69  if (bi->second != ai->second)
70  return(false);
71  }
72  return(true);
73 }
74 #endif
75 #endif
76 
77 //----------------------------------------------------------------------------
79 //----------------------------------------------------------------------------
80 #if (! defined(__clang__))
81 #if (! HAVE_GPLUSPLUS_VERSION(4,6))
82 template <typename _keyT, typename _valueT, typename _Hash,
83  typename _Pred, typename _Alloc>
84 bool operator !=
85 (const std::unordered_map<_keyT, _valueT, _Hash, _Pred, _Alloc> & a,
86  const std::unordered_map<_keyT, _valueT, _Hash, _Pred, _Alloc> & b)
87 {
88  return(! (a == b));
89 }
90 #endif
91 #endif
92 
93 //----------------------------------------------------------------------------
95 //----------------------------------------------------------------------------
96 #if (! defined(__clang__))
97 #if (! HAVE_GPLUSPLUS_VERSION(4,6))
98 template <typename _keyT, typename _valueT, typename _Hash,
99  typename _Pred, typename _Alloc>
100 bool operator ==
101 (const std::unordered_multimap<_keyT, _valueT, _Hash, _Pred, _Alloc> & a,
102  const std::unordered_multimap<_keyT, _valueT, _Hash, _Pred, _Alloc> & b)
103 {
104  // Are the multimaps the same size?
105  if (a.size() != b.size())
106  return(false);
107  typedef typename std::unordered_multimap<_keyT, _valueT, _Hash, _Pred, _Alloc>::const_iterator ConstIterator;
108  ConstIterator ai;
109  for (ai = a.begin(); ai != a.end(); ++ai) {
110  std::pair<ConstIterator,ConstIterator> aiRange =
111  a.equal_range(ai->first);
112  std::pair<ConstIterator,ConstIterator> biRange =
113  b.equal_range(ai->first);
114  // Do we have the same number of entries for the given key in
115  // each multimap?
116  if (std::distance(aiRange.first, aiRange.second)
117  != std::distance(biRange.first, biRange.second)) {
118  return(false);
119  }
120 
121  // Do we have the same number of each value for the given key?
122  size_t aCount = 0, bCount = 0;
123  ConstIterator ari = aiRange.first;
124  for ( ; ari != aiRange.second; ++ari) {
125  ConstIterator ri;
126  for (ri = aiRange.first; ri != aiRange.second; ++ri) {
127  if (ri->second == ari->second) {
128  ++aCount;
129  }
130  }
131  for (ri = biRange.first ; ri != biRange.second; ++ri) {
132  if (ri->second == ari->second) {
133  ++bCount;
134  }
135  }
136  }
137  if (aCount != bCount) {
138  return(false);
139  }
140  }
141  return(true);
142 }
143 #endif
144 #endif
145 
146 #if (! defined(__clang__))
147 #if (! HAVE_GPLUSPLUS_VERSION(4,6))
148 //----------------------------------------------------------------------------
150 //----------------------------------------------------------------------------
151 template <typename _keyT, typename _valueT, typename _Hash,
152  typename _Pred, typename _Alloc>
153 bool operator !=
154 (const std::unordered_multimap<_keyT, _valueT, _Hash, _Pred, _Alloc> & a,
155  const std::unordered_multimap<_keyT, _valueT, _Hash, _Pred, _Alloc> & b)
156 {
157  return(! (a == b));
158 }
159 #endif
160 #endif
161 
162 //----------------------------------------------------------------------------
164 //----------------------------------------------------------------------------
165 #if (! defined(__clang__))
166 #if (! HAVE_GPLUSPLUS_VERSION(4,6))
167 template <typename _valueT, typename _Hash,
168  typename _Pred, typename _Alloc>
169 bool operator ==
170 (const std::unordered_set<_valueT, _Hash, _Pred, _Alloc> & a,
171  const std::unordered_set<_valueT, _Hash, _Pred, _Alloc> & b)
172 {
173  if (a.size() != b.size())
174  return(false);
175  typename std::unordered_set<_valueT, _Hash, _Pred, _Alloc>::const_iterator
176  ai, bi;
177  for (ai = a.begin(); ai != a.end(); ++ai) {
178  bi = b.find(*ai);
179  if (bi == b.end())
180  return(false);
181  if (*bi != *ai)
182  return(false);
183  }
184  return(true);
185 }
186 #endif
187 #endif
188 
189 //----------------------------------------------------------------------------
191 //----------------------------------------------------------------------------
192 #if (! defined(__clang__))
193 #if (! HAVE_GPLUSPLUS_VERSION(4,6))
194 template <typename _valueT, typename _Hash,
195  typename _Pred, typename _Alloc>
196 bool operator !=
197 (const std::unordered_set<_valueT, _Hash, _Pred, _Alloc> & a,
198  const std::unordered_set<_valueT, _Hash, _Pred, _Alloc> & b)
199 {
200  return(! (a == b));
201 }
202 #endif
203 #endif
204 
205 //----------------------------------------------------------------------------
207 //----------------------------------------------------------------------------
208 #if (! defined(__clang__))
209 #if (! HAVE_GPLUSPLUS_VERSION(4,6))
210 template <typename _valueT, typename _Hash,
211  typename _Pred, typename _Alloc>
212 bool operator ==
213 (const std::unordered_multiset<_valueT, _Hash, _Pred, _Alloc> & a,
214  const std::unordered_multiset<_valueT, _Hash, _Pred, _Alloc> & b)
215 {
216  // Are the multisets the same size?
217  if (a.size() != b.size())
218  return(false);
219  typedef typename std::unordered_multiset<_valueT, _Hash, _Pred, _Alloc>::const_iterator ConstIterator;
220  ConstIterator ai;
221  for (ai = a.begin(); ai != a.end(); ++ai) {
222  std::pair<ConstIterator,ConstIterator> aiRange = a.equal_range(*ai);
223  std::pair<ConstIterator,ConstIterator> biRange = b.equal_range(*ai);
224  // Do we have the same number of entries for the given key in
225  // each multiset?
226  if (std::distance(aiRange.first, aiRange.second)
227  != std::distance(biRange.first, biRange.second)) {
228  return(false);
229  }
230  }
231  return(true);
232 }
233 #endif
234 #endif
235 
236 //----------------------------------------------------------------------------
238 //----------------------------------------------------------------------------
239 #if (! defined(__clang__))
240 #if (! HAVE_GPLUSPLUS_VERSION(4,6))
241 template <typename _valueT, typename _Hash,
242  typename _Pred, typename _Alloc>
243 bool operator !=
244 (const std::unordered_multiset<_valueT, _Hash, _Pred, _Alloc> & a,
245  const std::unordered_multiset<_valueT, _Hash, _Pred, _Alloc> & b)
246 {
247  return(! (a == b));
248 }
249 #endif
250 #endif
251 
252 #endif // _DWMOPERATORS_HH_
253 
254 //---------------------------- emacs settings -----------------------------
255 // Local Variables:
256 // mode: C++/la
257 // tab-width: 2
258 // indent-tabs-mode: nil
259 // c-basic-offset: 2
260 // End:
261 //-------------------------------------------------------------------------
A configure target for dealing with OS differences.