epoc32/include/stdapis/stlportv5/stl/_function_base.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100
branchSymbian2
changeset 3 e1b950c65cb4
parent 2 epoc32/include/stdapis/stlport/stl/_function_base.h@2fe1408b6811
child 4 837f303aceeb
permissions -rw-r--r--
Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
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@2
    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@2
    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_BASE_H
williamr@2
    31
#define _STLP_INTERNAL_FUNCTION_BASE_H
williamr@2
    32
williamr@2
    33
#ifndef _STLP_CONFIG_H
williamr@2
    34
#include <stl/_config.h>
williamr@2
    35
#endif
williamr@2
    36
williamr@2
    37
_STLP_BEGIN_NAMESPACE
williamr@2
    38
williamr@2
    39
template <class _Arg, class _Result>
williamr@2
    40
struct unary_function {
williamr@2
    41
  typedef _Arg argument_type;
williamr@2
    42
  typedef _Result result_type;
williamr@2
    43
};
williamr@2
    44
williamr@2
    45
template <class _Arg1, class _Arg2, class _Result>
williamr@2
    46
struct binary_function {
williamr@2
    47
  typedef _Arg1 first_argument_type;
williamr@2
    48
  typedef _Arg2 second_argument_type;
williamr@2
    49
  typedef _Result result_type;
williamr@2
    50
};      
williamr@2
    51
williamr@2
    52
template <class _Tp>
williamr@2
    53
struct equal_to : public binary_function<_Tp,_Tp,bool> 
williamr@2
    54
{
williamr@2
    55
  bool operator()(const _Tp& __x, const _Tp& __y) const { return __x == __y; }
williamr@2
    56
};
williamr@2
    57
williamr@2
    58
template <class _Tp>
williamr@2
    59
struct not_equal_to : public binary_function<_Tp,_Tp,bool> 
williamr@2
    60
{
williamr@2
    61
  bool operator()(const _Tp& __x, const _Tp& __y) const { return __x != __y; }
williamr@2
    62
};
williamr@2
    63
williamr@2
    64
template <class _Tp>
williamr@2
    65
struct greater : public binary_function<_Tp,_Tp,bool> 
williamr@2
    66
{
williamr@2
    67
  bool operator()(const _Tp& __x, const _Tp& __y) const { return __x > __y; }
williamr@2
    68
};
williamr@2
    69
williamr@2
    70
template <class _Tp>
williamr@2
    71
struct less : public binary_function<_Tp,_Tp,bool> 
williamr@2
    72
{
williamr@2
    73
  bool operator()(const _Tp& __x, const _Tp& __y) const { return __x < __y; }
williamr@2
    74
};
williamr@2
    75
williamr@2
    76
template <class _Tp>
williamr@2
    77
struct greater_equal : public binary_function<_Tp,_Tp,bool>
williamr@2
    78
{
williamr@2
    79
  bool operator()(const _Tp& __x, const _Tp& __y) const { return __x >= __y; }
williamr@2
    80
};
williamr@2
    81
williamr@2
    82
template <class _Tp>
williamr@2
    83
struct less_equal : public binary_function<_Tp,_Tp,bool> 
williamr@2
    84
{
williamr@2
    85
  bool operator()(const _Tp& __x, const _Tp& __y) const { return __x <= __y; }
williamr@2
    86
};
williamr@2
    87
williamr@2
    88
template <class _Tp>
williamr@2
    89
less<_Tp> __less(_Tp* ) { return less<_Tp>(); }
williamr@2
    90
williamr@2
    91
template <class _Tp>
williamr@2
    92
equal_to<_Tp> __equal_to(_Tp* ) { return equal_to<_Tp>(); }
williamr@2
    93
williamr@2
    94
template <class _Tp>
williamr@2
    95
struct plus : public binary_function<_Tp,_Tp,_Tp> {
williamr@2
    96
  _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x + __y; }
williamr@2
    97
};
williamr@2
    98
williamr@2
    99
template <class _Tp>
williamr@2
   100
struct minus : public binary_function<_Tp,_Tp,_Tp> {
williamr@2
   101
  _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x - __y; }
williamr@2
   102
};
williamr@2
   103
williamr@2
   104
template <class _Tp>
williamr@2
   105
plus<_Tp> __plus(_Tp* ) { return plus<_Tp>(); }
williamr@2
   106
williamr@2
   107
template <class _Tp>
williamr@2
   108
minus<_Tp> __minus(_Tp* ) { return minus<_Tp>(); }
williamr@2
   109
williamr@2
   110
template <class _Tp>
williamr@2
   111
struct multiplies : public binary_function<_Tp,_Tp,_Tp> {
williamr@2
   112
  _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x * __y; }
williamr@2
   113
};
williamr@2
   114
williamr@2
   115
template <class _Tp>
williamr@2
   116
struct divides : public binary_function<_Tp,_Tp,_Tp> {
williamr@2
   117
  _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x / __y; }
williamr@2
   118
};
williamr@2
   119
williamr@2
   120
template <class _Tp>
williamr@2
   121
struct modulus : public binary_function<_Tp,_Tp,_Tp> 
williamr@2
   122
{
williamr@2
   123
  _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x % __y; }
williamr@2
   124
};
williamr@2
   125
williamr@2
   126
template <class _Tp>
williamr@2
   127
struct negate : public unary_function<_Tp,_Tp> 
williamr@2
   128
{
williamr@2
   129
  _Tp operator()(const _Tp& __x) const { return -__x; }
williamr@2
   130
};
williamr@2
   131
williamr@2
   132
template <class _Tp>
williamr@2
   133
struct logical_and : public binary_function<_Tp,_Tp,bool>
williamr@2
   134
{
williamr@2
   135
  bool operator()(const _Tp& __x, const _Tp& __y) const { return __x && __y; }
williamr@2
   136
};
williamr@2
   137
williamr@2
   138
template <class _Tp>
williamr@2
   139
struct logical_or : public binary_function<_Tp,_Tp,bool>
williamr@2
   140
{
williamr@2
   141
  bool operator()(const _Tp& __x, const _Tp& __y) const { return __x || __y; }
williamr@2
   142
};
williamr@2
   143
williamr@2
   144
template <class _Tp>
williamr@2
   145
struct logical_not : public unary_function<_Tp,bool>
williamr@2
   146
{
williamr@2
   147
  bool operator()(const _Tp& __x) const { return !__x; }
williamr@2
   148
};
williamr@2
   149
williamr@2
   150
template <class _Pair>
williamr@2
   151
struct _Select1st : public unary_function<_Pair, typename _Pair::first_type> {
williamr@2
   152
  const typename _Pair::first_type& operator()(const _Pair& __x) const {
williamr@2
   153
    return __x.first;
williamr@2
   154
  }
williamr@2
   155
};
williamr@2
   156
williamr@2
   157
template <class _Pair>
williamr@2
   158
struct _Select2nd : public unary_function<_Pair, typename _Pair::second_type>
williamr@2
   159
{
williamr@2
   160
  const typename _Pair::second_type& operator()(const _Pair& __x) const {
williamr@2
   161
    return __x.second;
williamr@2
   162
  }
williamr@2
   163
};
williamr@2
   164
williamr@2
   165
// project1st and project2nd are extensions: they are not part of the standard
williamr@2
   166
template <class _Arg1, class _Arg2>
williamr@2
   167
struct _Project1st : public binary_function<_Arg1, _Arg2, _Arg1> {
williamr@2
   168
  _Arg1 operator()(const _Arg1& __x, const _Arg2&) const { return __x; }
williamr@2
   169
};
williamr@2
   170
williamr@2
   171
template <class _Arg1, class _Arg2>
williamr@2
   172
struct _Project2nd : public binary_function<_Arg1, _Arg2, _Arg2> {
williamr@2
   173
  _Arg2 operator()(const _Arg1&, const _Arg2& __y) const { return __y; }
williamr@2
   174
};
williamr@2
   175
williamr@2
   176
#ifdef _STLP_MULTI_CONST_TEMPLATE_ARG_BUG
williamr@2
   177
// fbp : sort of select1st just for maps
williamr@2
   178
template <class _Pair, class _Whatever>		
williamr@2
   179
// JDJ (CW Pro1 doesn't like const when first_type is also const)
williamr@2
   180
struct __Select1st_hint : public unary_function<_Pair, _Whatever> {
williamr@2
   181
    const _Whatever& operator () (const _Pair& __x) const { return __x.first; }
williamr@2
   182
};
williamr@2
   183
# define  _STLP_SELECT1ST(__x,__y) __Select1st_hint< __x, __y >
williamr@2
   184
# else
williamr@2
   185
# define  _STLP_SELECT1ST(__x, __y) _Select1st< __x >
williamr@2
   186
# endif
williamr@2
   187
williamr@2
   188
template <class _Tp>
williamr@2
   189
struct _Identity : public unary_function<_Tp,_Tp> {
williamr@2
   190
  const _Tp& operator()(const _Tp& __x) const { return __x; }
williamr@2
   191
};
williamr@2
   192
williamr@2
   193
template <class _Result, class _Argument>
williamr@2
   194
struct _Constant_unary_fun {
williamr@2
   195
  typedef _Argument argument_type;
williamr@2
   196
  typedef  _Result  result_type;
williamr@2
   197
  result_type _M_val;
williamr@2
   198
williamr@2
   199
  _Constant_unary_fun(const result_type& __v) : _M_val(__v) {}
williamr@2
   200
  const result_type& operator()(const _Argument&) const { return _M_val; }
williamr@2
   201
};
williamr@2
   202
williamr@2
   203
template <class _Result, class _Arg1, class _Arg2>
williamr@2
   204
struct _Constant_binary_fun {
williamr@2
   205
  typedef  _Arg1   first_argument_type;
williamr@2
   206
  typedef  _Arg2   second_argument_type;
williamr@2
   207
  typedef  _Result result_type;
williamr@2
   208
  _Result _M_val;
williamr@2
   209
williamr@2
   210
  _Constant_binary_fun(const _Result& __v) : _M_val(__v) {}
williamr@2
   211
  const result_type& operator()(const _Arg1&, const _Arg2&) const {
williamr@2
   212
    return _M_val;
williamr@2
   213
  }
williamr@2
   214
};
williamr@2
   215
williamr@2
   216
// identity_element (not part of the C++ standard).
williamr@2
   217
template <class _Tp> inline _Tp __identity_element(plus<_Tp>) {  return _Tp(0); }
williamr@2
   218
template <class _Tp> inline _Tp __identity_element(multiplies<_Tp>) { return _Tp(1); }
williamr@2
   219
williamr@2
   220
_STLP_END_NAMESPACE
williamr@2
   221
williamr@2
   222
#endif /* _STLP_INTERNAL_FUNCTION_BASE_H */
williamr@2
   223
williamr@2
   224
// Local Variables:
williamr@2
   225
// mode:C++
williamr@2
   226
// End: