Sierra Toolkit  Version of the Day
utility_eastl.h
1 /*
2 Copyright (C) 2005,2009-2010 Electronic Arts, Inc. All rights reserved.
3 
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
6 are met:
7 
8 1. Redistributions of source code must retain the above copyright
9  notice, this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright
11  notice, this list of conditions and the following disclaimer in the
12  documentation and/or other materials provided with the distribution.
13 3. Neither the name of Electronic Arts, Inc. ("EA") nor the names of
14  its contributors may be used to endorse or promote products derived
15  from this software without specific prior written permission.
16 
17 THIS SOFTWARE IS PROVIDED BY ELECTRONIC ARTS AND ITS CONTRIBUTORS "AS IS" AND ANY
18 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL ELECTRONIC ARTS OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 
30 // EASTL/utility.h
31 // Written and maintained by Paul Pedriana - 2005.
33 
34 
35 
36 #ifndef EASTL_UTILITY_H
37 #define EASTL_UTILITY_H
38 
39 
40 #include <stk_util/util/config_eastl.h>
41 
42 
43 #ifdef _MSC_VER
44  #pragma warning(push) // VC++ generates a bogus warning that you cannot code away.
45  #pragma warning(disable: 4619) // There is no warning number 'number'.
46  #pragma warning(disable: 4217) // Member template functions cannot be used for copy-assignment or copy-construction.
47  #pragma warning(disable: 4512) // 'class' : assignment operator could not be generated. // This disabling would best be put elsewhere.
48 #endif
49 
50 
51 namespace eastl
52 {
53 
67  namespace rel_ops
68  {
69  template <typename T>
70  inline bool operator!=(const T& x, const T& y)
71  { return !(x == y); }
72 
73  template <typename T>
74  inline bool operator>(const T& x, const T& y)
75  { return (y < x); }
76 
77  template <typename T>
78  inline bool operator<=(const T& x, const T& y)
79  { return !(y < x); }
80 
81  template <typename T>
82  inline bool operator>=(const T& x, const T& y)
83  { return !(x < y); }
84  }
85 
86 
87 
93  template <typename T1, typename T2>
94  struct pair
95  {
96  typedef T1 first_type;
97  typedef T2 second_type;
98 
99  T1 first;
100  T2 second;
101 
102  pair();
103  pair(const T1& x);
104  pair(const T1& x, const T2& y);
105 
106  template <typename U, typename V>
107  pair(const pair<U, V>& p);
108 
109  // pair(const pair& p); // Not necessary, as default version is OK.
110  // pair& operator=(const pair& p); // Not necessary, as default version is OK.
111  };
112 
113 
114 
115 
126  template <typename T>
127  struct use_self // : public unary_function<T, T> // Perhaps we want to make it a subclass of unary_function.
128  {
129  typedef T result_type;
130 
131  const T& operator()(const T& x) const
132  { return x; }
133  };
134 
142  template <typename Pair>
143  struct use_first // : public unary_function<Pair, typename Pair::first_type> // Perhaps we want to make it a subclass of unary_function.
144  {
145  typedef typename Pair::first_type result_type;
146 
147  const result_type& operator()(const Pair& x) const
148  { return x.first; }
149  };
150 
156  template <typename Pair>
157  struct use_second // : public unary_function<Pair, typename Pair::second_type> // Perhaps we want to make it a subclass of unary_function.
158  {
159  typedef typename Pair::second_type result_type;
160 
161  const result_type& operator()(const Pair& x) const
162  { return x.second; }
163  };
164 
165 
166 
167 
168 
170  // pair
172 
173  template <typename T1, typename T2>
174  inline pair<T1, T2>::pair()
175  : first(), second()
176  {
177  // Empty
178  }
179 
180 
181  template <typename T1, typename T2>
182  inline pair<T1, T2>::pair(const T1& x)
183  : first(x), second()
184  {
185  // Empty
186  }
187 
188 
189  template <typename T1, typename T2>
190  inline pair<T1, T2>::pair(const T1& x, const T2& y)
191  : first(x), second(y)
192  {
193  // Empty
194  }
195 
196 
197  template <typename T1, typename T2>
198  template <typename U, typename V>
199  inline pair<T1, T2>::pair(const pair<U, V>& p)
200  : first(p.first), second(p.second)
201  {
202  // Empty
203  }
204 
205 
206 
207 
209  // global operators
211 
212  template <typename T1, typename T2>
213  inline bool operator==(const pair<T1, T2>& a, const pair<T1, T2>& b)
214  {
215  return ((a.first == b.first) && (a.second == b.second));
216  }
217 
218 
219  template <typename T1, typename T2>
220  inline bool operator<(const pair<T1, T2>& a, const pair<T1, T2>& b)
221  {
222  // Note that we use only operator < in this expression. Otherwise we could
223  // use the simpler: return (a.m1 == b.m1) ? (a.m2 < b.m2) : (a.m1 < b.m1);
224  // The user can write a specialization for this operator to get around this
225  // in cases where the highest performance is required.
226  return ((a.first < b.first) || (!(b.first < a.first) && (a.second < b.second)));
227  }
228 
229 
230  template <typename T1, typename T2>
231  inline bool operator!=(const pair<T1, T2>& a, const pair<T1, T2>& b)
232  {
233  return !(a == b);
234  }
235 
236 
237  template <typename T1, typename T2>
238  inline bool operator>(const pair<T1, T2>& a, const pair<T1, T2>& b)
239  {
240  return b < a;
241  }
242 
243 
244  template <typename T1, typename T2>
245  inline bool operator>=(const pair<T1, T2>& a, const pair<T1, T2>& b)
246  {
247  return !(a < b);
248  }
249 
250 
251  template <typename T1, typename T2>
252  inline bool operator<=(const pair<T1, T2>& a, const pair<T1, T2>& b)
253  {
254  return !(b < a);
255  }
256 
257 
258 
259 
275  template <typename T1, typename T2>
276  inline pair<T1, T2> make_pair(T1 a, T2 b)
277  {
278  return pair<T1, T2>(a, b);
279  }
280 
281 
282  template <typename T1, typename T2>
283  inline pair<T1, T2> make_pair_ref(const T1& a, const T2& b)
284  {
285  return pair<T1, T2>(a, b);
286  }
287 
288 
289 } // namespace eastl
290 
291 
292 #ifdef _MSC_VER
293  #pragma warning(pop)
294 #endif
295 
296 
297 #endif // Header include guard
pair< T1, T2 > make_pair(T1 a, T2 b)
EA Standard Template Library.