ReactOS  0.4.12-dev-375-g61fed54
_function.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 1994
4  * Hewlett-Packard Company
5  *
6  * Copyright (c) 1996-1998
7  * Silicon Graphics Computer Systems, Inc.
8  *
9  * Copyright (c) 1997
10  * Moscow Center for SPARC Technology
11  *
12  * Copyright (c) 1999
13  * Boris Fomitchev
14  *
15  * This material is provided "as is", with absolutely no warranty expressed
16  * or implied. Any use is at your own risk.
17  *
18  * Permission to use or copy this software for any purpose is hereby granted
19  * without fee, provided the above notices are retained on all copies.
20  * Permission to modify the code and to distribute modified code is granted,
21  * provided the above notices are retained, and a notice that the code was
22  * modified is included with the above copyright notice.
23  *
24  */
25 
26 /* NOTE: This is an internal header file, included by other STL headers.
27  * You should not attempt to use it directly.
28  */
29 
30 #ifndef _STLP_INTERNAL_FUNCTION_H
31 #define _STLP_INTERNAL_FUNCTION_H
32 
33 #ifndef _STLP_TYPE_TRAITS_H
34 # include <stl/type_traits.h>
35 #endif
36 
37 #ifndef _STLP_INTERNAL_FUNCTION_BASE_H
38 # include <stl/_function_base.h>
39 #endif
40 
42 
43 template <class _Tp>
44 struct not_equal_to : public binary_function<_Tp, _Tp, bool> {
45  bool operator()(const _Tp& __x, const _Tp& __y) const { return __x != __y; }
46 };
47 
48 template <class _Tp>
49 struct greater : public binary_function<_Tp, _Tp, bool> {
50  bool operator()(const _Tp& __x, const _Tp& __y) const { return __x > __y; }
51 };
52 
53 template <class _Tp>
54 struct greater_equal : public binary_function<_Tp, _Tp, bool> {
55  bool operator()(const _Tp& __x, const _Tp& __y) const { return __x >= __y; }
56 };
57 
58 template <class _Tp>
59 struct less_equal : public binary_function<_Tp, _Tp, bool> {
60  bool operator()(const _Tp& __x, const _Tp& __y) const { return __x <= __y; }
61 };
62 
63 template <class _Tp>
64 struct divides : public binary_function<_Tp, _Tp, _Tp> {
65  _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x / __y; }
66 };
67 
68 template <class _Tp>
69 struct modulus : public binary_function<_Tp, _Tp, _Tp> {
70  _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x % __y; }
71 };
72 
73 template <class _Tp>
74 struct negate : public unary_function<_Tp, _Tp> {
75  _Tp operator()(const _Tp& __x) const { return -__x; }
76 };
77 
78 template <class _Tp>
79 struct logical_and : public binary_function<_Tp, _Tp, bool> {
80  bool operator()(const _Tp& __x, const _Tp& __y) const { return __x && __y; }
81 };
82 
83 template <class _Tp>
84 struct logical_or : public binary_function<_Tp, _Tp,bool> {
85  bool operator()(const _Tp& __x, const _Tp& __y) const { return __x || __y; }
86 };
87 
88 template <class _Tp>
89 struct logical_not : public unary_function<_Tp, bool> {
90  bool operator()(const _Tp& __x) const { return !__x; }
91 };
92 
93 #if !defined (_STLP_NO_EXTENSIONS)
94 // identity_element (not part of the C++ standard).
95 template <class _Tp> inline _Tp identity_element(plus<_Tp>) { return _Tp(0); }
96 template <class _Tp> inline _Tp identity_element(multiplies<_Tp>) { return _Tp(1); }
97 #endif
98 
99 #if defined (_STLP_BASE_TYPEDEF_BUG)
100 // this workaround is needed for SunPro 4.0.1
101 // suggested by "Martin Abernethy" <gma@paston.co.uk>:
102 
103 // We have to introduce the XXary_predicate_aux structures in order to
104 // access the argument and return types of predicate functions supplied
105 // as type parameters. SUN C++ 4.0.1 compiler gives errors for template type parameters
106 // of the form 'name1::name2', where name1 is itself a type parameter.
107 template <class _Pair>
108 struct __pair_aux : private _Pair {
109  typedef typename _Pair::first_type first_type;
110  typedef typename _Pair::second_type second_type;
111 };
112 
113 template <class _Operation>
114 struct __unary_fun_aux : private _Operation {
115  typedef typename _Operation::argument_type argument_type;
116  typedef typename _Operation::result_type result_type;
117 };
118 
119 template <class _Operation>
120 struct __binary_fun_aux : private _Operation {
121  typedef typename _Operation::first_argument_type first_argument_type;
122  typedef typename _Operation::second_argument_type second_argument_type;
123  typedef typename _Operation::result_type result_type;
124 };
125 
126 # define __UNARY_ARG(__Operation,__type) __unary_fun_aux<__Operation>::__type
127 # define __BINARY_ARG(__Operation,__type) __binary_fun_aux<__Operation>::__type
128 # define __PAIR_ARG(__Pair,__type) __pair_aux<__Pair>::__type
129 #else
130 # define __UNARY_ARG(__Operation,__type) __Operation::__type
131 # define __BINARY_ARG(__Operation,__type) __Operation::__type
132 # define __PAIR_ARG(__Pair,__type) __Pair::__type
133 #endif
134 
135 template <class _Predicate>
137  : public unary_function<typename __UNARY_ARG(_Predicate, argument_type), bool> {
138  typedef unary_function<typename __UNARY_ARG(_Predicate, argument_type), bool> _Base;
139 public:
141 private:
143 protected:
144  _Predicate _M_pred;
145 public:
146  explicit unary_negate(const _Predicate& __x) : _M_pred(__x) {}
147  bool operator()(_ArgParamType __x) const {
148  return !_M_pred(__x);
149  }
150 };
151 
152 template <class _Predicate>
154 not1(const _Predicate& __pred) {
156 }
157 
158 template <class _Predicate>
160  : public binary_function<typename __BINARY_ARG(_Predicate, first_argument_type),
161  typename __BINARY_ARG(_Predicate, second_argument_type),
162  bool> {
163  typedef binary_function<typename __BINARY_ARG(_Predicate, first_argument_type),
164  typename __BINARY_ARG(_Predicate, second_argument_type),
165  bool> _Base;
166 public:
169 private:
172 protected:
173  _Predicate _M_pred;
174 public:
175  explicit binary_negate(const _Predicate& __x) : _M_pred(__x) {}
177  return !_M_pred(__x, __y);
178  }
179 };
180 
181 template <class _Predicate>
183 not2(const _Predicate& __pred) {
185 }
186 
187 template <class _Operation>
188 class binder1st :
189  public unary_function<typename __BINARY_ARG(_Operation, second_argument_type),
190  typename __BINARY_ARG(_Operation, result_type) > {
191  typedef unary_function<typename __BINARY_ARG(_Operation, second_argument_type),
192  typename __BINARY_ARG(_Operation, result_type) > _Base;
193 public:
195  typedef typename _Base::result_type result_type;
196 private:
200 protected:
201  //op is a Standard name (20.3.6.1), do no make it STLport naming convention compliant.
202  _Operation op;
203  typename _Operation::first_argument_type _M_value;
204 public:
205  binder1st(const _Operation& __x, _ValueParamType __y)
206  : op(__x), _M_value(__y) {}
207 
209  { return op(_M_value, __x); }
210  // DR 109 Missing binders for non-const sequence elements
212  { return op(_M_value, __x); }
213 };
214 
215 template <class _Operation, class _Tp>
217 bind1st(const _Operation& __fn, const _Tp& __x) {
218  typedef typename _Operation::first_argument_type _Arg1_type;
219  return binder1st<_Operation>(__fn, _Arg1_type(__x));
220 }
221 
222 template <class _Operation>
224  : public unary_function<typename __BINARY_ARG(_Operation, first_argument_type),
225  typename __BINARY_ARG(_Operation, result_type)> {
226  typedef unary_function<typename __BINARY_ARG(_Operation, first_argument_type),
227  typename __BINARY_ARG(_Operation, result_type)> _Base;
228 public:
230  typedef typename _Base::result_type result_type;
231 private:
235 protected:
236  //op is a Standard name (20.3.6.3), do no make it STLport naming convention compliant.
237  _Operation op;
238  typename _Operation::second_argument_type value;
239 public:
240  binder2nd(const _Operation& __x, _ValueParamType __y)
241  : op(__x), value(__y) {}
242 
244  { return op(__x, value); }
245  // DR 109 Missing binders for non-const sequence elements
247  { return op(__x, value); }
248 };
249 
250 template <class _Operation, class _Tp>
252 bind2nd(const _Operation& __fn, const _Tp& __x) {
253  typedef typename _Operation::second_argument_type _Arg2_type;
254  return binder2nd<_Operation>(__fn, _Arg2_type(__x));
255 }
256 
257 #if !defined (_STLP_NO_EXTENSIONS)
258 // unary_compose and binary_compose (extensions, not part of the standard).
259 
260 template <class _Operation1, class _Operation2>
262  public unary_function<typename __UNARY_ARG(_Operation2, argument_type),
263  typename __UNARY_ARG(_Operation1, result_type)> {
264  typedef unary_function<typename __UNARY_ARG(_Operation2, argument_type),
265  typename __UNARY_ARG(_Operation1, result_type)> _Base;
266 public:
268  typedef typename _Base::result_type result_type;
269 private:
271 protected:
272  _Operation1 _M_fn1;
273  _Operation2 _M_fn2;
274 public:
275  unary_compose(const _Operation1& __x, const _Operation2& __y)
276  : _M_fn1(__x), _M_fn2(__y) {}
277 
279  return _M_fn1(_M_fn2(__x));
280  }
281 };
282 
283 template <class _Operation1, class _Operation2>
285 compose1(const _Operation1& __fn1, const _Operation2& __fn2) {
286  return unary_compose<_Operation1,_Operation2>(__fn1, __fn2);
287 }
288 
289 template <class _Operation1, class _Operation2, class _Operation3>
291  public unary_function<typename __UNARY_ARG(_Operation2, argument_type),
292  typename __BINARY_ARG(_Operation1, result_type)> {
293  typedef unary_function<typename __UNARY_ARG(_Operation2, argument_type),
294  typename __BINARY_ARG(_Operation1, result_type)> _Base;
295 public:
297  typedef typename _Base::result_type result_type;
298 private:
300 protected:
301  _Operation1 _M_fn1;
302  _Operation2 _M_fn2;
303  _Operation3 _M_fn3;
304 public:
305  binary_compose(const _Operation1& __x, const _Operation2& __y,
306  const _Operation3& __z)
307  : _M_fn1(__x), _M_fn2(__y), _M_fn3(__z) { }
308 
310  return _M_fn1(_M_fn2(__x), _M_fn3(__x));
311  }
312 };
313 
314 template <class _Operation1, class _Operation2, class _Operation3>
316 compose2(const _Operation1& __fn1, const _Operation2& __fn2,
317  const _Operation3& __fn3) {
318  return binary_compose<_Operation1,_Operation2,_Operation3>(__fn1, __fn2, __fn3);
319 }
320 
321 // identity is an extension: it is not part of the standard.
322 template <class _Tp> struct identity : public _STLP_PRIV _Identity<_Tp> {};
323 // select1st and select2nd are extensions: they are not part of the standard.
324 template <class _Pair> struct select1st : public _STLP_PRIV _Select1st<_Pair> {};
325 template <class _Pair> struct select2nd : public _STLP_PRIV _Select2nd<_Pair> {};
326 
327 template <class _Arg1, class _Arg2>
328 struct project1st : public _STLP_PRIV _Project1st<_Arg1, _Arg2> {};
329 
330 template <class _Arg1, class _Arg2>
331 struct project2nd : public _STLP_PRIV _Project2nd<_Arg1, _Arg2> {};
332 
333 
334 // constant_void_fun, constant_unary_fun, and constant_binary_fun are
335 // extensions: they are not part of the standard. (The same, of course,
336 // is true of the helper functions constant0, constant1, and constant2.)
337 
339 
340 template <class _Result>
342  typedef _Result result_type;
344 
345  _Constant_void_fun(const result_type& __v) : _M_val(__v) {}
346  const result_type& operator()() const { return _M_val; }
347 };
348 
350 
351 template <class _Result>
353  constant_void_fun(const _Result& __v)
354  : _STLP_PRIV _Constant_void_fun<_Result>(__v) {}
355 };
356 
357 template <class _Result, _STLP_DFL_TMPL_PARAM( _Argument , _Result) >
358 struct constant_unary_fun : public _STLP_PRIV _Constant_unary_fun<_Result, _Argument> {
359  constant_unary_fun(const _Result& __v)
360  : _STLP_PRIV _Constant_unary_fun<_Result, _Argument>(__v) {}
361 };
362 
363 template <class _Result, _STLP_DFL_TMPL_PARAM( _Arg1 , _Result), _STLP_DFL_TMPL_PARAM( _Arg2 , _Arg1) >
365  : public _STLP_PRIV _Constant_binary_fun<_Result, _Arg1, _Arg2> {
366  constant_binary_fun(const _Result& __v)
367  : _STLP_PRIV _Constant_binary_fun<_Result, _Arg1, _Arg2>(__v) {}
368 };
369 
370 template <class _Result>
373 }
374 
375 template <class _Result>
378 }
379 
380 template <class _Result>
382 constant2(const _Result& __val) {
384 }
385 
386 // subtractive_rng is an extension: it is not part of the standard.
387 // Note: this code assumes that int is 32 bits.
388 class subtractive_rng : public unary_function<_STLP_UINT32_T, _STLP_UINT32_T> {
389 private:
393 public:
395  _M_index1 = (_M_index1 + 1) % 55;
396  _M_index2 = (_M_index2 + 1) % 55;
398  return _M_table[_M_index1] % __limit;
399  }
400 
402  _STLP_UINT32_T __k = 1;
403  _M_table[54] = __seed;
404  _STLP_UINT32_T __i;
405  for (__i = 0; __i < 54; __i++) {
406  _STLP_UINT32_T __ii = (21 * (__i + 1) % 55) - 1;
407  _M_table[__ii] = __k;
408  __k = __seed - __k;
409  __seed = _M_table[__ii];
410  }
411  for (int __loop = 0; __loop < 4; __loop++) {
412  for (__i = 0; __i < 55; __i++)
413  _M_table[__i] = _M_table[__i] - _M_table[(1 + __i + 30) % 55];
414  }
415  _M_index1 = 0;
416  _M_index2 = 31;
417  }
418 
419  subtractive_rng(unsigned int __seed) { _M_initialize(__seed); }
420  subtractive_rng() { _M_initialize(161803398ul); }
421 };
422 
423 #endif /* _STLP_NO_EXTENSIONS */
424 
426 
427 #include <stl/_function_adaptors.h>
428 
429 #endif /* _STLP_INTERNAL_FUNCTION_H */
430 
431 // Local Variables:
432 // mode:C++
433 // End:
__call_traits< argument_type >::const_param_type _ArgParamType
Definition: _function.h:299
_Operation op
Definition: _function.h:237
_Arg1 first_argument_type
result_type operator()(_ConstArgParamType __x) const
Definition: _function.h:243
Definition: get.c:139
_Tp identity_element(plus< _Tp >)
Definition: _function.h:95
const _Tp & const_param_type
Definition: type_traits.h:461
bool operator()(_FstArgParamType __x, _SndArgParamType __y) const
Definition: _function.h:176
constant_unary_fun< _Result, _Result > constant1(const _Result &__val)
Definition: _function.h:376
unary_function< typename __BINARY_ARG(_Operation, first_argument_type), typename __BINARY_ARG(_Operation, result_type)> _Base
Definition: _function.h:227
result_type operator()(_ArgParamType __x) const
Definition: _function.h:309
_Operation1 _M_fn1
Definition: _function.h:301
#define _STLP_UINT32_T
Definition: _apple.h:37
bool operator()(const _Tp &__x) const
Definition: _function.h:90
constant_void_fun< _Result > constant0(const _Result &__val)
Definition: _function.h:371
_STLP_UINT32_T _M_index1
Definition: _function.h:391
_STLP_INLINE_LOOP _InputIter _Predicate __pred
Definition: _algo.h:68
_Result result_type
Definition: _function.h:342
unary_negate(const _Predicate &__x)
Definition: _function.h:146
_Tp operator()(const _Tp &__x, const _Tp &__y) const
Definition: _function.h:65
_Arg2 second_argument_type
_Result result_type
unary_function< typename __UNARY_ARG(_Operation2, argument_type), typename __UNARY_ARG(_Operation1, result_type)> _Base
Definition: _function.h:265
binder1st(const _Operation &__x, _ValueParamType __y)
Definition: _function.h:205
constant_binary_fun(const _Result &__v)
Definition: _function.h:366
unary_compose< _Operation1, _Operation2 > compose1(const _Operation1 &__fn1, const _Operation2 &__fn2)
Definition: _function.h:285
binary_compose(const _Operation1 &__x, const _Operation2 &__y, const _Operation3 &__z)
Definition: _function.h:305
__call_traits< typename _Operation::second_argument_type >::const_param_type _ValueParamType
Definition: _function.h:234
__call_traits< argument_type >::const_param_type _ArgParamType
Definition: _function.h:270
binary_compose< _Operation1, _Operation2, _Operation3 > compose2(const _Operation1 &__fn1, const _Operation2 &__fn2, const _Operation3 &__fn3)
Definition: _function.h:316
#define _STLP_MOVE_TO_PRIV_NAMESPACE
Definition: features.h:524
result_type operator()(_ArgParamType __x) const
Definition: _function.h:278
_Base::argument_type argument_type
Definition: _function.h:140
binder2nd< _Operation > bind2nd(const _Operation &__fn, const _Tp &__x)
Definition: _function.h:252
_Predicate _M_pred
Definition: _function.h:173
#define __UNARY_ARG(__Operation, __type)
Definition: _function.h:130
_Base::argument_type argument_type
Definition: _function.h:229
_Operation::first_argument_type _M_value
Definition: _function.h:203
binary_negate< _Predicate > not2(const _Predicate &__pred)
Definition: _function.h:183
binder1st< _Operation > bind1st(const _Operation &__fn, const _Tp &__x)
Definition: _function.h:217
unary_compose(const _Operation1 &__x, const _Operation2 &__y)
Definition: _function.h:275
__call_traits< argument_type >::const_param_type _ConstArgParamType
Definition: _function.h:198
_Base::result_type result_type
Definition: _function.h:297
__call_traits< argument_type >::param_type _ArgParamType
Definition: _function.h:232
_Base::result_type result_type
Definition: _function.h:195
__call_traits< argument_type >::const_param_type _ConstArgParamType
Definition: _function.h:233
binary_negate(const _Predicate &__x)
Definition: _function.h:175
_Operation2 _M_fn2
Definition: _function.h:273
_Base::argument_type argument_type
Definition: _function.h:194
_Predicate _M_pred
Definition: _function.h:144
result_type operator()(_ConstArgParamType __x) const
Definition: _function.h:208
#define _STLP_MOVE_TO_STD_NAMESPACE
Definition: features.h:525
_Operation op
Definition: _function.h:202
unary_function< typename __UNARY_ARG(_Operation2, argument_type), typename __BINARY_ARG(_Operation1, result_type)> _Base
Definition: _function.h:294
_STLP_INLINE_LOOP _InputIter const _Tp & __val
Definition: _algobase.h:656
constant_void_fun(const _Result &__v)
Definition: _function.h:353
_Operation1 _M_fn1
Definition: _function.h:272
unary_negate< _Predicate > not1(const _Predicate &__pred)
Definition: _function.h:154
_Tp operator()(const _Tp &__x) const
Definition: _function.h:75
unary_function< typename __UNARY_ARG(_Predicate, argument_type), bool > _Base
Definition: _function.h:138
_Base::result_type result_type
Definition: _function.h:230
constant_unary_fun(const _Result &__v)
Definition: _function.h:359
const result_type & operator()() const
Definition: _function.h:346
_Constant_void_fun(const result_type &__v)
Definition: _function.h:345
__call_traits< typename _Operation::first_argument_type >::const_param_type _ValueParamType
Definition: _function.h:199
binder2nd(const _Operation &__x, _ValueParamType __y)
Definition: _function.h:240
#define _STLP_PRIV
Definition: _dm.h:70
result_type _M_val
Definition: _function.h:343
__call_traits< argument_type >::param_type _ArgParamType
Definition: _function.h:197
constant_binary_fun< _Result, _Result, _Result > constant2(const _Result &__val)
Definition: _function.h:382
_Base::result_type result_type
Definition: _function.h:268
_Operation::second_argument_type value
Definition: _function.h:238
void _M_initialize(_STLP_UINT32_T __seed)
Definition: _function.h:401
bool operator()(_ArgParamType __x) const
Definition: _function.h:147
_Tp operator()(const _Tp &__x, const _Tp &__y) const
Definition: _function.h:70
_Tp & param_type
Definition: type_traits.h:462
result_type operator()(_ArgParamType __x) const
Definition: _function.h:211
_Base::second_argument_type second_argument_type
Definition: _function.h:168
result_type operator()(_ArgParamType __x) const
Definition: _function.h:246
_Operation2 _M_fn2
Definition: _function.h:302
#define _STLP_END_NAMESPACE
Definition: features.h:503
bool operator()(const _Tp &__x, const _Tp &__y) const
Definition: _function.h:50
__call_traits< argument_type >::const_param_type _ArgParamType
Definition: _function.h:142
__call_traits< first_argument_type >::const_param_type _FstArgParamType
Definition: _function.h:170
bool operator()(const _Tp &__x, const _Tp &__y) const
Definition: _function.h:60
_STLP_UINT32_T _M_table[55]
Definition: _function.h:390
#define __BINARY_ARG(__Operation, __type)
Definition: _function.h:131
bool operator()(const _Tp &__x, const _Tp &__y) const
Definition: _function.h:80
_STLP_UINT32_T operator()(_STLP_UINT32_T __limit)
Definition: _function.h:394
_Operation3 _M_fn3
Definition: _function.h:303
__call_traits< second_argument_type >::const_param_type _SndArgParamType
Definition: _function.h:171
bool operator()(const _Tp &__x, const _Tp &__y) const
Definition: _function.h:85
_Base::argument_type argument_type
Definition: _function.h:267
#define _STLP_BEGIN_NAMESPACE
Definition: features.h:501
binary_function< typename __BINARY_ARG(_Predicate, first_argument_type), typename __BINARY_ARG(_Predicate, second_argument_type), bool > _Base
Definition: _function.h:165
_Base::argument_type argument_type
Definition: _function.h:296
_STLP_UINT32_T _M_index2
Definition: _function.h:392
bool operator()(const _Tp &__x, const _Tp &__y) const
Definition: _function.h:45
subtractive_rng(unsigned int __seed)
Definition: _function.h:419
bool operator()(const _Tp &__x, const _Tp &__y) const
Definition: _function.h:55
_Base::first_argument_type first_argument_type
Definition: _function.h:167
unary_function< typename __BINARY_ARG(_Operation, second_argument_type), typename __BINARY_ARG(_Operation, result_type) > _Base
Definition: _function.h:192