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