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