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