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