epoc32/include/stdapis/stlportv5/stl/_function_base.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 3 e1b950c65cb4
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
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@4
    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@4
    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@4
    33
#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && !defined (_STLP_TYPE_TRAITS_H)
williamr@4
    34
#  include <stl/type_traits.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@4
    50
};
williamr@2
    51
williamr@2
    52
template <class _Tp>
williamr@4
    53
struct equal_to : public binary_function<_Tp, _Tp, bool> {
williamr@2
    54
  bool operator()(const _Tp& __x, const _Tp& __y) const { return __x == __y; }
williamr@2
    55
};
williamr@2
    56
williamr@2
    57
template <class _Tp>
williamr@4
    58
struct less : public binary_function<_Tp,_Tp,bool>
williamr@4
    59
#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
williamr@4
    60
/* less is the default template parameter for many STL containers, to fully use
williamr@4
    61
 * the move constructor feature we need to know that the default less is just a
williamr@4
    62
 * functor.
williamr@4
    63
 */
williamr@4
    64
              , public __stlport_class<less<_Tp> >
williamr@4
    65
#endif
williamr@2
    66
{
williamr@4
    67
  bool operator()(const _Tp& __x, const _Tp& __y) const { return __x < __y; }
williamr@4
    68
williamr@4
    69
#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
williamr@4
    70
  //This is for a very special compiler config: partial template specialization
williamr@4
    71
  //but no template function partial ordering.
williamr@4
    72
  void swap(less<_Tp>&) {}
williamr@4
    73
#endif
williamr@2
    74
};
williamr@2
    75
williamr@4
    76
#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
williamr@2
    77
template <class _Tp>
williamr@4
    78
struct __type_traits<less<_Tp> > {
williamr@4
    79
#if !defined (__BORLANDC__)
williamr@4
    80
  typedef typename _IsSTLportClass<less<_Tp> >::_Ret _STLportLess;
williamr@4
    81
#else
williamr@4
    82
  enum { _Is = _IsSTLportClass<less<_Tp> >::_Is };
williamr@4
    83
  typedef typename __bool2type<_Is>::_Ret _STLportLess;
williamr@4
    84
#endif
williamr@4
    85
  typedef _STLportLess has_trivial_default_constructor;
williamr@4
    86
  typedef _STLportLess has_trivial_copy_constructor;
williamr@4
    87
  typedef _STLportLess has_trivial_assignment_operator;
williamr@4
    88
  typedef _STLportLess has_trivial_destructor;
williamr@4
    89
  typedef _STLportLess is_POD_type;
williamr@2
    90
};
williamr@4
    91
#endif
williamr@2
    92
williamr@4
    93
_STLP_MOVE_TO_PRIV_NAMESPACE
williamr@2
    94
williamr@2
    95
template <class _Tp>
williamr@2
    96
less<_Tp> __less(_Tp* ) { return less<_Tp>(); }
williamr@2
    97
williamr@2
    98
template <class _Tp>
williamr@2
    99
equal_to<_Tp> __equal_to(_Tp* ) { return equal_to<_Tp>(); }
williamr@2
   100
williamr@4
   101
_STLP_MOVE_TO_STD_NAMESPACE
williamr@4
   102
williamr@2
   103
template <class _Tp>
williamr@4
   104
struct plus : public binary_function<_Tp, _Tp, _Tp> {
williamr@2
   105
  _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x + __y; }
williamr@2
   106
};
williamr@2
   107
williamr@2
   108
template <class _Tp>
williamr@4
   109
struct minus : public binary_function<_Tp, _Tp, _Tp> {
williamr@2
   110
  _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x - __y; }
williamr@2
   111
};
williamr@2
   112
williamr@4
   113
_STLP_MOVE_TO_PRIV_NAMESPACE
williamr@4
   114
williamr@2
   115
template <class _Tp>
williamr@2
   116
plus<_Tp> __plus(_Tp* ) { return plus<_Tp>(); }
williamr@2
   117
williamr@2
   118
template <class _Tp>
williamr@2
   119
minus<_Tp> __minus(_Tp* ) { return minus<_Tp>(); }
williamr@2
   120
williamr@4
   121
_STLP_MOVE_TO_STD_NAMESPACE
williamr@4
   122
williamr@2
   123
template <class _Tp>
williamr@4
   124
struct multiplies : public binary_function<_Tp, _Tp, _Tp> {
williamr@2
   125
  _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x * __y; }
williamr@2
   126
};
williamr@2
   127
williamr@4
   128
_STLP_MOVE_TO_PRIV_NAMESPACE
williamr@2
   129
williamr@2
   130
template <class _Pair>
williamr@2
   131
struct _Select1st : public unary_function<_Pair, typename _Pair::first_type> {
williamr@2
   132
  const typename _Pair::first_type& operator()(const _Pair& __x) const {
williamr@2
   133
    return __x.first;
williamr@2
   134
  }
williamr@2
   135
};
williamr@2
   136
williamr@2
   137
template <class _Pair>
williamr@4
   138
struct _Select2nd : public unary_function<_Pair, typename _Pair::second_type> {
williamr@2
   139
  const typename _Pair::second_type& operator()(const _Pair& __x) const {
williamr@2
   140
    return __x.second;
williamr@2
   141
  }
williamr@2
   142
};
williamr@2
   143
williamr@2
   144
// project1st and project2nd are extensions: they are not part of the standard
williamr@2
   145
template <class _Arg1, class _Arg2>
williamr@2
   146
struct _Project1st : public binary_function<_Arg1, _Arg2, _Arg1> {
williamr@2
   147
  _Arg1 operator()(const _Arg1& __x, const _Arg2&) const { return __x; }
williamr@2
   148
};
williamr@2
   149
williamr@2
   150
template <class _Arg1, class _Arg2>
williamr@2
   151
struct _Project2nd : public binary_function<_Arg1, _Arg2, _Arg2> {
williamr@2
   152
  _Arg2 operator()(const _Arg1&, const _Arg2& __y) const { return __y; }
williamr@2
   153
};
williamr@2
   154
williamr@4
   155
#if defined (_STLP_MULTI_CONST_TEMPLATE_ARG_BUG)
williamr@2
   156
// fbp : sort of select1st just for maps
williamr@4
   157
template <class _Pair, class _Whatever>
williamr@2
   158
// JDJ (CW Pro1 doesn't like const when first_type is also const)
williamr@2
   159
struct __Select1st_hint : public unary_function<_Pair, _Whatever> {
williamr@2
   160
    const _Whatever& operator () (const _Pair& __x) const { return __x.first; }
williamr@2
   161
};
williamr@4
   162
#  define  _STLP_SELECT1ST(__x,__y) _STLP_PRIV __Select1st_hint< __x, __y >
williamr@4
   163
#else
williamr@4
   164
#  define  _STLP_SELECT1ST(__x, __y) _STLP_PRIV _Select1st< __x >
williamr@4
   165
#endif
williamr@2
   166
williamr@2
   167
template <class _Tp>
williamr@2
   168
struct _Identity : public unary_function<_Tp,_Tp> {
williamr@2
   169
  const _Tp& operator()(const _Tp& __x) const { return __x; }
williamr@2
   170
};
williamr@2
   171
williamr@2
   172
template <class _Result, class _Argument>
williamr@2
   173
struct _Constant_unary_fun {
williamr@2
   174
  typedef _Argument argument_type;
williamr@2
   175
  typedef  _Result  result_type;
williamr@2
   176
  result_type _M_val;
williamr@2
   177
williamr@2
   178
  _Constant_unary_fun(const result_type& __v) : _M_val(__v) {}
williamr@2
   179
  const result_type& operator()(const _Argument&) const { return _M_val; }
williamr@2
   180
};
williamr@2
   181
williamr@2
   182
template <class _Result, class _Arg1, class _Arg2>
williamr@2
   183
struct _Constant_binary_fun {
williamr@2
   184
  typedef  _Arg1   first_argument_type;
williamr@2
   185
  typedef  _Arg2   second_argument_type;
williamr@2
   186
  typedef  _Result result_type;
williamr@2
   187
  _Result _M_val;
williamr@2
   188
williamr@2
   189
  _Constant_binary_fun(const _Result& __v) : _M_val(__v) {}
williamr@2
   190
  const result_type& operator()(const _Arg1&, const _Arg2&) const {
williamr@2
   191
    return _M_val;
williamr@2
   192
  }
williamr@2
   193
};
williamr@2
   194
williamr@2
   195
// identity_element (not part of the C++ standard).
williamr@2
   196
template <class _Tp> inline _Tp __identity_element(plus<_Tp>) {  return _Tp(0); }
williamr@2
   197
template <class _Tp> inline _Tp __identity_element(multiplies<_Tp>) { return _Tp(1); }
williamr@2
   198
williamr@4
   199
_STLP_MOVE_TO_STD_NAMESPACE
williamr@4
   200
williamr@2
   201
_STLP_END_NAMESPACE
williamr@2
   202
williamr@2
   203
#endif /* _STLP_INTERNAL_FUNCTION_BASE_H */
williamr@2
   204
williamr@2
   205
// Local Variables:
williamr@2
   206
// mode:C++
williamr@2
   207
// End: