1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/tools/stlport/stl/_function.h Wed Mar 31 12:33:34 2010 +0100
1.3 @@ -0,0 +1,427 @@
1.4 +/*
1.5 + *
1.6 + * Copyright (c) 1994
1.7 + * Hewlett-Packard Company
1.8 + *
1.9 + * Copyright (c) 1996-1998
1.10 + * Silicon Graphics Computer Systems, Inc.
1.11 + *
1.12 + * Copyright (c) 1997
1.13 + * Moscow Center for SPARC Technology
1.14 + *
1.15 + * Copyright (c) 1999
1.16 + * Boris Fomitchev
1.17 + *
1.18 + * This material is provided "as is", with absolutely no warranty expressed
1.19 + * or implied. Any use is at your own risk.
1.20 + *
1.21 + * Permission to use or copy this software for any purpose is hereby granted
1.22 + * without fee, provided the above notices are retained on all copies.
1.23 + * Permission to modify the code and to distribute modified code is granted,
1.24 + * provided the above notices are retained, and a notice that the code was
1.25 + * modified is included with the above copyright notice.
1.26 + *
1.27 + */
1.28 +
1.29 +/* NOTE: This is an internal header file, included by other STL headers.
1.30 + * You should not attempt to use it directly.
1.31 + */
1.32 +
1.33 +#ifndef _STLP_INTERNAL_FUNCTION_H
1.34 +#define _STLP_INTERNAL_FUNCTION_H
1.35 +
1.36 +#ifndef _STLP_TYPE_TRAITS_H
1.37 +# include <stl/type_traits.h>
1.38 +#endif
1.39 +
1.40 +#ifndef _STLP_INTERNAL_FUNCTION_BASE_H
1.41 +# include <stl/_function_base.h>
1.42 +#endif
1.43 +
1.44 +_STLP_BEGIN_NAMESPACE
1.45 +
1.46 +template <class _Tp>
1.47 +struct not_equal_to : public binary_function<_Tp, _Tp, bool> {
1.48 + bool operator()(const _Tp& __x, const _Tp& __y) const { return __x != __y; }
1.49 +};
1.50 +
1.51 +template <class _Tp>
1.52 +struct greater : public binary_function<_Tp, _Tp, bool> {
1.53 + bool operator()(const _Tp& __x, const _Tp& __y) const { return __x > __y; }
1.54 +};
1.55 +
1.56 +template <class _Tp>
1.57 +struct greater_equal : public binary_function<_Tp, _Tp, bool> {
1.58 + bool operator()(const _Tp& __x, const _Tp& __y) const { return __x >= __y; }
1.59 +};
1.60 +
1.61 +template <class _Tp>
1.62 +struct less_equal : public binary_function<_Tp, _Tp, bool> {
1.63 + bool operator()(const _Tp& __x, const _Tp& __y) const { return __x <= __y; }
1.64 +};
1.65 +
1.66 +template <class _Tp>
1.67 +struct divides : public binary_function<_Tp, _Tp, _Tp> {
1.68 + _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x / __y; }
1.69 +};
1.70 +
1.71 +template <class _Tp>
1.72 +struct modulus : public binary_function<_Tp, _Tp, _Tp> {
1.73 + _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x % __y; }
1.74 +};
1.75 +
1.76 +template <class _Tp>
1.77 +struct negate : public unary_function<_Tp, _Tp> {
1.78 + _Tp operator()(const _Tp& __x) const { return -__x; }
1.79 +};
1.80 +
1.81 +template <class _Tp>
1.82 +struct logical_and : public binary_function<_Tp, _Tp, bool> {
1.83 + bool operator()(const _Tp& __x, const _Tp& __y) const { return __x && __y; }
1.84 +};
1.85 +
1.86 +template <class _Tp>
1.87 +struct logical_or : public binary_function<_Tp, _Tp,bool> {
1.88 + bool operator()(const _Tp& __x, const _Tp& __y) const { return __x || __y; }
1.89 +};
1.90 +
1.91 +template <class _Tp>
1.92 +struct logical_not : public unary_function<_Tp, bool> {
1.93 + bool operator()(const _Tp& __x) const { return !__x; }
1.94 +};
1.95 +
1.96 +#if !defined (_STLP_NO_EXTENSIONS)
1.97 +// identity_element (not part of the C++ standard).
1.98 +template <class _Tp> inline _Tp identity_element(plus<_Tp>) { return _Tp(0); }
1.99 +template <class _Tp> inline _Tp identity_element(multiplies<_Tp>) { return _Tp(1); }
1.100 +#endif
1.101 +
1.102 +#if defined (_STLP_BASE_TYPEDEF_BUG)
1.103 +// this workaround is needed for SunPro 4.0.1
1.104 +// suggested by "Martin Abernethy" <gma@paston.co.uk>:
1.105 +
1.106 +// We have to introduce the XXary_predicate_aux structures in order to
1.107 +// access the argument and return types of predicate functions supplied
1.108 +// as type parameters. SUN C++ 4.0.1 compiler gives errors for template type parameters
1.109 +// of the form 'name1::name2', where name1 is itself a type parameter.
1.110 +template <class _Pair>
1.111 +struct __pair_aux : private _Pair {
1.112 + typedef typename _Pair::first_type first_type;
1.113 + typedef typename _Pair::second_type second_type;
1.114 +};
1.115 +
1.116 +template <class _Operation>
1.117 +struct __unary_fun_aux : private _Operation {
1.118 + typedef typename _Operation::argument_type argument_type;
1.119 + typedef typename _Operation::result_type result_type;
1.120 +};
1.121 +
1.122 +template <class _Operation>
1.123 +struct __binary_fun_aux : private _Operation {
1.124 + typedef typename _Operation::first_argument_type first_argument_type;
1.125 + typedef typename _Operation::second_argument_type second_argument_type;
1.126 + typedef typename _Operation::result_type result_type;
1.127 +};
1.128 +
1.129 +# define __UNARY_ARG(__Operation,__type) __unary_fun_aux<__Operation>::__type
1.130 +# define __BINARY_ARG(__Operation,__type) __binary_fun_aux<__Operation>::__type
1.131 +# define __PAIR_ARG(__Pair,__type) __pair_aux<__Pair>::__type
1.132 +#else
1.133 +# define __UNARY_ARG(__Operation,__type) __Operation::__type
1.134 +# define __BINARY_ARG(__Operation,__type) __Operation::__type
1.135 +# define __PAIR_ARG(__Pair,__type) __Pair::__type
1.136 +#endif
1.137 +
1.138 +template <class _Predicate>
1.139 +class unary_negate
1.140 + : public unary_function<typename __UNARY_ARG(_Predicate, argument_type), bool> {
1.141 + typedef unary_function<typename __UNARY_ARG(_Predicate, argument_type), bool> _Base;
1.142 +public:
1.143 + typedef typename _Base::argument_type argument_type;
1.144 +private:
1.145 + typedef typename __call_traits<argument_type>::param_type _ArgParamType;
1.146 +protected:
1.147 + _Predicate _M_pred;
1.148 +public:
1.149 + explicit unary_negate(const _Predicate& __x) : _M_pred(__x) {}
1.150 + bool operator()(_ArgParamType __x) const {
1.151 + return !_M_pred(__x);
1.152 + }
1.153 +};
1.154 +
1.155 +template <class _Predicate>
1.156 +inline unary_negate<_Predicate>
1.157 +not1(const _Predicate& __pred) {
1.158 + return unary_negate<_Predicate>(__pred);
1.159 +}
1.160 +
1.161 +template <class _Predicate>
1.162 +class binary_negate
1.163 + : public binary_function<typename __BINARY_ARG(_Predicate, first_argument_type),
1.164 + typename __BINARY_ARG(_Predicate, second_argument_type),
1.165 + bool> {
1.166 + typedef binary_function<typename __BINARY_ARG(_Predicate, first_argument_type),
1.167 + typename __BINARY_ARG(_Predicate, second_argument_type),
1.168 + bool> _Base;
1.169 +public:
1.170 + typedef typename _Base::first_argument_type first_argument_type;
1.171 + typedef typename _Base::second_argument_type second_argument_type;
1.172 +private:
1.173 + typedef typename __call_traits<first_argument_type>::param_type _FstArgParamType;
1.174 + typedef typename __call_traits<second_argument_type>::param_type _SndArgParamType;
1.175 +protected:
1.176 + _Predicate _M_pred;
1.177 +public:
1.178 + explicit binary_negate(const _Predicate& __x) : _M_pred(__x) {}
1.179 + bool operator()(_FstArgParamType __x, _SndArgParamType __y) const {
1.180 + return !_M_pred(__x, __y);
1.181 + }
1.182 +};
1.183 +
1.184 +template <class _Predicate>
1.185 +inline binary_negate<_Predicate>
1.186 +not2(const _Predicate& __pred) {
1.187 + return binary_negate<_Predicate>(__pred);
1.188 +}
1.189 +
1.190 +template <class _Operation>
1.191 +class binder1st :
1.192 + public unary_function<typename __BINARY_ARG(_Operation, second_argument_type),
1.193 + typename __BINARY_ARG(_Operation, result_type) > {
1.194 + typedef unary_function<typename __BINARY_ARG(_Operation, second_argument_type),
1.195 + typename __BINARY_ARG(_Operation, result_type) > _Base;
1.196 +public:
1.197 + typedef typename _Base::argument_type argument_type;
1.198 + typedef typename _Base::result_type result_type;
1.199 +private:
1.200 + typedef typename __call_traits<argument_type>::param_type _ArgParamType;
1.201 + typedef typename __call_traits<typename _Operation::first_argument_type>::param_type _ValueParamType;
1.202 +protected:
1.203 + //op is a Standard name (20.3.6.1), do no make it STLport naming convention compliant.
1.204 + _Operation op;
1.205 + typename _Operation::first_argument_type _M_value;
1.206 +public:
1.207 + binder1st(const _Operation& __x, _ValueParamType __y)
1.208 + : op(__x), _M_value(__y) {}
1.209 +
1.210 + result_type operator()(_ArgParamType __x) const {
1.211 + return op(_M_value, __x);
1.212 + }
1.213 +};
1.214 +
1.215 +template <class _Operation, class _Tp>
1.216 +inline binder1st<_Operation>
1.217 +bind1st(const _Operation& __fn, const _Tp& __x) {
1.218 + typedef typename _Operation::first_argument_type _Arg1_type;
1.219 + return binder1st<_Operation>(__fn, _Arg1_type(__x));
1.220 +}
1.221 +
1.222 +template <class _Operation>
1.223 +class binder2nd
1.224 + : public unary_function<typename __BINARY_ARG(_Operation, first_argument_type),
1.225 + typename __BINARY_ARG(_Operation, result_type)> {
1.226 + typedef unary_function<typename __BINARY_ARG(_Operation, first_argument_type),
1.227 + typename __BINARY_ARG(_Operation, result_type)> _Base;
1.228 +public:
1.229 + typedef typename _Base::argument_type argument_type;
1.230 + typedef typename _Base::result_type result_type;
1.231 +private:
1.232 + typedef typename __call_traits<argument_type>::param_type _ArgParamType;
1.233 + typedef typename __call_traits<typename _Operation::second_argument_type>::param_type _ValueParamType;
1.234 +protected:
1.235 + //op is a Standard name (20.3.6.3), do no make it STLport naming convention compliant.
1.236 + _Operation op;
1.237 + typename _Operation::second_argument_type value;
1.238 +public:
1.239 + binder2nd(const _Operation& __x, _ValueParamType __y)
1.240 + : op(__x), value(__y) {}
1.241 +
1.242 + result_type operator()(_ArgParamType __x) const {
1.243 + return op(__x, value);
1.244 + }
1.245 +};
1.246 +
1.247 +template <class _Operation, class _Tp>
1.248 +inline binder2nd<_Operation>
1.249 +bind2nd(const _Operation& __fn, const _Tp& __x) {
1.250 + typedef typename _Operation::second_argument_type _Arg2_type;
1.251 + return binder2nd<_Operation>(__fn, _Arg2_type(__x));
1.252 +}
1.253 +
1.254 +#if !defined (_STLP_NO_EXTENSIONS)
1.255 +// unary_compose and binary_compose (extensions, not part of the standard).
1.256 +
1.257 +template <class _Operation1, class _Operation2>
1.258 +class unary_compose :
1.259 + public unary_function<typename __UNARY_ARG(_Operation2, argument_type),
1.260 + typename __UNARY_ARG(_Operation1, result_type)> {
1.261 + typedef unary_function<typename __UNARY_ARG(_Operation2, argument_type),
1.262 + typename __UNARY_ARG(_Operation1, result_type)> _Base;
1.263 +public:
1.264 + typedef typename _Base::argument_type argument_type;
1.265 + typedef typename _Base::result_type result_type;
1.266 +private:
1.267 + typedef typename __call_traits<argument_type>::param_type _ArgParamType;
1.268 +protected:
1.269 + _Operation1 _M_fn1;
1.270 + _Operation2 _M_fn2;
1.271 +public:
1.272 + unary_compose(const _Operation1& __x, const _Operation2& __y)
1.273 + : _M_fn1(__x), _M_fn2(__y) {}
1.274 +
1.275 + result_type operator()(_ArgParamType __x) const {
1.276 + return _M_fn1(_M_fn2(__x));
1.277 + }
1.278 +};
1.279 +
1.280 +template <class _Operation1, class _Operation2>
1.281 +inline unary_compose<_Operation1,_Operation2>
1.282 +compose1(const _Operation1& __fn1, const _Operation2& __fn2) {
1.283 + return unary_compose<_Operation1,_Operation2>(__fn1, __fn2);
1.284 +}
1.285 +
1.286 +template <class _Operation1, class _Operation2, class _Operation3>
1.287 +class binary_compose :
1.288 + public unary_function<typename __UNARY_ARG(_Operation2, argument_type),
1.289 + typename __BINARY_ARG(_Operation1, result_type)> {
1.290 + typedef unary_function<typename __UNARY_ARG(_Operation2, argument_type),
1.291 + typename __BINARY_ARG(_Operation1, result_type)> _Base;
1.292 +public:
1.293 + typedef typename _Base::argument_type argument_type;
1.294 + typedef typename _Base::result_type result_type;
1.295 +private:
1.296 + typedef typename __call_traits<argument_type>::param_type _ArgParamType;
1.297 +protected:
1.298 + _Operation1 _M_fn1;
1.299 + _Operation2 _M_fn2;
1.300 + _Operation3 _M_fn3;
1.301 +public:
1.302 + binary_compose(const _Operation1& __x, const _Operation2& __y,
1.303 + const _Operation3& __z)
1.304 + : _M_fn1(__x), _M_fn2(__y), _M_fn3(__z) { }
1.305 +
1.306 + result_type operator()(_ArgParamType __x) const {
1.307 + return _M_fn1(_M_fn2(__x), _M_fn3(__x));
1.308 + }
1.309 +};
1.310 +
1.311 +template <class _Operation1, class _Operation2, class _Operation3>
1.312 +inline binary_compose<_Operation1, _Operation2, _Operation3>
1.313 +compose2(const _Operation1& __fn1, const _Operation2& __fn2,
1.314 + const _Operation3& __fn3) {
1.315 + return binary_compose<_Operation1,_Operation2,_Operation3>(__fn1, __fn2, __fn3);
1.316 +}
1.317 +
1.318 +// identity is an extension: it is not part of the standard.
1.319 +template <class _Tp> struct identity : public _STLP_PRIV _Identity<_Tp> {};
1.320 +// select1st and select2nd are extensions: they are not part of the standard.
1.321 +template <class _Pair> struct select1st : public _STLP_PRIV _Select1st<_Pair> {};
1.322 +template <class _Pair> struct select2nd : public _STLP_PRIV _Select2nd<_Pair> {};
1.323 +
1.324 +template <class _Arg1, class _Arg2>
1.325 +struct project1st : public _STLP_PRIV _Project1st<_Arg1, _Arg2> {};
1.326 +
1.327 +template <class _Arg1, class _Arg2>
1.328 +struct project2nd : public _STLP_PRIV _Project2nd<_Arg1, _Arg2> {};
1.329 +
1.330 +
1.331 +// constant_void_fun, constant_unary_fun, and constant_binary_fun are
1.332 +// extensions: they are not part of the standard. (The same, of course,
1.333 +// is true of the helper functions constant0, constant1, and constant2.)
1.334 +
1.335 +_STLP_MOVE_TO_PRIV_NAMESPACE
1.336 +
1.337 +template <class _Result>
1.338 +struct _Constant_void_fun {
1.339 + typedef _Result result_type;
1.340 + result_type _M_val;
1.341 +
1.342 + _Constant_void_fun(const result_type& __v) : _M_val(__v) {}
1.343 + const result_type& operator()() const { return _M_val; }
1.344 +};
1.345 +
1.346 +_STLP_MOVE_TO_STD_NAMESPACE
1.347 +
1.348 +template <class _Result>
1.349 +struct constant_void_fun : public _STLP_PRIV _Constant_void_fun<_Result> {
1.350 + constant_void_fun(const _Result& __v)
1.351 + : _STLP_PRIV _Constant_void_fun<_Result>(__v) {}
1.352 +};
1.353 +
1.354 +template <class _Result, _STLP_DFL_TMPL_PARAM( _Argument , _Result) >
1.355 +struct constant_unary_fun : public _STLP_PRIV _Constant_unary_fun<_Result, _Argument> {
1.356 + constant_unary_fun(const _Result& __v)
1.357 + : _STLP_PRIV _Constant_unary_fun<_Result, _Argument>(__v) {}
1.358 +};
1.359 +
1.360 +template <class _Result, _STLP_DFL_TMPL_PARAM( _Arg1 , _Result), _STLP_DFL_TMPL_PARAM( _Arg2 , _Arg1) >
1.361 +struct constant_binary_fun
1.362 + : public _STLP_PRIV _Constant_binary_fun<_Result, _Arg1, _Arg2> {
1.363 + constant_binary_fun(const _Result& __v)
1.364 + : _STLP_PRIV _Constant_binary_fun<_Result, _Arg1, _Arg2>(__v) {}
1.365 +};
1.366 +
1.367 +template <class _Result>
1.368 +inline constant_void_fun<_Result> constant0(const _Result& __val) {
1.369 + return constant_void_fun<_Result>(__val);
1.370 +}
1.371 +
1.372 +template <class _Result>
1.373 +inline constant_unary_fun<_Result,_Result> constant1(const _Result& __val) {
1.374 + return constant_unary_fun<_Result,_Result>(__val);
1.375 +}
1.376 +
1.377 +template <class _Result>
1.378 +inline constant_binary_fun<_Result,_Result,_Result>
1.379 +constant2(const _Result& __val) {
1.380 + return constant_binary_fun<_Result,_Result,_Result>(__val);
1.381 +}
1.382 +
1.383 +// subtractive_rng is an extension: it is not part of the standard.
1.384 +// Note: this code assumes that int is 32 bits.
1.385 +class subtractive_rng : public unary_function<_STLP_UINT32_T, _STLP_UINT32_T> {
1.386 +private:
1.387 + _STLP_UINT32_T _M_table[55];
1.388 + _STLP_UINT32_T _M_index1;
1.389 + _STLP_UINT32_T _M_index2;
1.390 +public:
1.391 + _STLP_UINT32_T operator()(_STLP_UINT32_T __limit) {
1.392 + _M_index1 = (_M_index1 + 1) % 55;
1.393 + _M_index2 = (_M_index2 + 1) % 55;
1.394 + _M_table[_M_index1] = _M_table[_M_index1] - _M_table[_M_index2];
1.395 + return _M_table[_M_index1] % __limit;
1.396 + }
1.397 +
1.398 + void _M_initialize(_STLP_UINT32_T __seed) {
1.399 + _STLP_UINT32_T __k = 1;
1.400 + _M_table[54] = __seed;
1.401 + _STLP_UINT32_T __i;
1.402 + for (__i = 0; __i < 54; __i++) {
1.403 + _STLP_UINT32_T __ii = (21 * (__i + 1) % 55) - 1;
1.404 + _M_table[__ii] = __k;
1.405 + __k = __seed - __k;
1.406 + __seed = _M_table[__ii];
1.407 + }
1.408 + for (int __loop = 0; __loop < 4; __loop++) {
1.409 + for (__i = 0; __i < 55; __i++)
1.410 + _M_table[__i] = _M_table[__i] - _M_table[(1 + __i + 30) % 55];
1.411 + }
1.412 + _M_index1 = 0;
1.413 + _M_index2 = 31;
1.414 + }
1.415 +
1.416 + subtractive_rng(unsigned int __seed) { _M_initialize(__seed); }
1.417 + subtractive_rng() { _M_initialize(161803398ul); }
1.418 +};
1.419 +
1.420 +#endif /* _STLP_NO_EXTENSIONS */
1.421 +
1.422 +_STLP_END_NAMESPACE
1.423 +
1.424 +#include <stl/_function_adaptors.h>
1.425 +
1.426 +#endif /* _STLP_INTERNAL_FUNCTION_H */
1.427 +
1.428 +// Local Variables:
1.429 +// mode:C++
1.430 +// End: