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