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.
     1 /*
     2  *
     3  * Copyright (c) 1994
     4  * Hewlett-Packard Company
     5  *
     6  * Copyright (c) 1996-1998
     7  * Silicon Graphics Computer Systems, Inc.
     8  *
     9  * Copyright (c) 1997
    10  * Moscow Center for SPARC Technology
    11  *
    12  * Copyright (c) 1999
    13  * Boris Fomitchev
    14  *
    15  * This material is provided "as is", with absolutely no warranty expressed
    16  * or implied. Any use is at your own risk.
    17  *
    18  * Permission to use or copy this software for any purpose is hereby granted
    19  * without fee, provided the above notices are retained on all copies.
    20  * Permission to modify the code and to distribute modified code is granted,
    21  * provided the above notices are retained, and a notice that the code was
    22  * modified is included with the above copyright notice.
    23  *
    24  */
    25 
    26 /* NOTE: This is an internal header file, included by other STL headers.
    27  *   You should not attempt to use it directly.
    28  */
    29 
    30 #ifndef _STLP_INTERNAL_FUNCTION_BASE_H
    31 #define _STLP_INTERNAL_FUNCTION_BASE_H
    32 
    33 #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && !defined (_STLP_TYPE_TRAITS_H)
    34 #  include <stl/type_traits.h>
    35 #endif
    36 
    37 _STLP_BEGIN_NAMESPACE
    38 
    39 template <class _Arg, class _Result>
    40 struct unary_function {
    41   typedef _Arg argument_type;
    42   typedef _Result result_type;
    43 };
    44 
    45 template <class _Arg1, class _Arg2, class _Result>
    46 struct binary_function {
    47   typedef _Arg1 first_argument_type;
    48   typedef _Arg2 second_argument_type;
    49   typedef _Result result_type;
    50 };
    51 
    52 template <class _Tp>
    53 struct equal_to : public binary_function<_Tp, _Tp, bool> {
    54   bool operator()(const _Tp& __x, const _Tp& __y) const { return __x == __y; }
    55 };
    56 
    57 template <class _Tp>
    58 struct less : public binary_function<_Tp,_Tp,bool>
    59 #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
    60 /* less is the default template parameter for many STL containers, to fully use
    61  * the move constructor feature we need to know that the default less is just a
    62  * functor.
    63  */
    64               , public __stlport_class<less<_Tp> >
    65 #endif
    66 {
    67   bool operator()(const _Tp& __x, const _Tp& __y) const { return __x < __y; }
    68 
    69 #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
    70   //This is for a very special compiler config: partial template specialization
    71   //but no template function partial ordering.
    72   void swap(less<_Tp>&) {}
    73 #endif
    74 };
    75 
    76 #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
    77 template <class _Tp>
    78 struct __type_traits<less<_Tp> > {
    79 #if !defined (__BORLANDC__)
    80   typedef typename _IsSTLportClass<less<_Tp> >::_Ret _STLportLess;
    81 #else
    82   enum { _Is = _IsSTLportClass<less<_Tp> >::_Is };
    83   typedef typename __bool2type<_Is>::_Ret _STLportLess;
    84 #endif
    85   typedef _STLportLess has_trivial_default_constructor;
    86   typedef _STLportLess has_trivial_copy_constructor;
    87   typedef _STLportLess has_trivial_assignment_operator;
    88   typedef _STLportLess has_trivial_destructor;
    89   typedef _STLportLess is_POD_type;
    90 };
    91 #endif
    92 
    93 _STLP_MOVE_TO_PRIV_NAMESPACE
    94 
    95 template <class _Tp>
    96 less<_Tp> __less(_Tp* ) { return less<_Tp>(); }
    97 
    98 template <class _Tp>
    99 equal_to<_Tp> __equal_to(_Tp* ) { return equal_to<_Tp>(); }
   100 
   101 _STLP_MOVE_TO_STD_NAMESPACE
   102 
   103 template <class _Tp>
   104 struct plus : public binary_function<_Tp, _Tp, _Tp> {
   105   _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x + __y; }
   106 };
   107 
   108 template <class _Tp>
   109 struct minus : public binary_function<_Tp, _Tp, _Tp> {
   110   _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x - __y; }
   111 };
   112 
   113 _STLP_MOVE_TO_PRIV_NAMESPACE
   114 
   115 template <class _Tp>
   116 plus<_Tp> __plus(_Tp* ) { return plus<_Tp>(); }
   117 
   118 template <class _Tp>
   119 minus<_Tp> __minus(_Tp* ) { return minus<_Tp>(); }
   120 
   121 _STLP_MOVE_TO_STD_NAMESPACE
   122 
   123 template <class _Tp>
   124 struct multiplies : public binary_function<_Tp, _Tp, _Tp> {
   125   _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x * __y; }
   126 };
   127 
   128 _STLP_MOVE_TO_PRIV_NAMESPACE
   129 
   130 template <class _Pair>
   131 struct _Select1st : public unary_function<_Pair, typename _Pair::first_type> {
   132   const typename _Pair::first_type& operator()(const _Pair& __x) const {
   133     return __x.first;
   134   }
   135 };
   136 
   137 template <class _Pair>
   138 struct _Select2nd : public unary_function<_Pair, typename _Pair::second_type> {
   139   const typename _Pair::second_type& operator()(const _Pair& __x) const {
   140     return __x.second;
   141   }
   142 };
   143 
   144 // project1st and project2nd are extensions: they are not part of the standard
   145 template <class _Arg1, class _Arg2>
   146 struct _Project1st : public binary_function<_Arg1, _Arg2, _Arg1> {
   147   _Arg1 operator()(const _Arg1& __x, const _Arg2&) const { return __x; }
   148 };
   149 
   150 template <class _Arg1, class _Arg2>
   151 struct _Project2nd : public binary_function<_Arg1, _Arg2, _Arg2> {
   152   _Arg2 operator()(const _Arg1&, const _Arg2& __y) const { return __y; }
   153 };
   154 
   155 #if defined (_STLP_MULTI_CONST_TEMPLATE_ARG_BUG)
   156 // fbp : sort of select1st just for maps
   157 template <class _Pair, class _Whatever>
   158 // JDJ (CW Pro1 doesn't like const when first_type is also const)
   159 struct __Select1st_hint : public unary_function<_Pair, _Whatever> {
   160     const _Whatever& operator () (const _Pair& __x) const { return __x.first; }
   161 };
   162 #  define  _STLP_SELECT1ST(__x,__y) _STLP_PRIV __Select1st_hint< __x, __y >
   163 #else
   164 #  define  _STLP_SELECT1ST(__x, __y) _STLP_PRIV _Select1st< __x >
   165 #endif
   166 
   167 template <class _Tp>
   168 struct _Identity : public unary_function<_Tp,_Tp> {
   169   const _Tp& operator()(const _Tp& __x) const { return __x; }
   170 };
   171 
   172 template <class _Result, class _Argument>
   173 struct _Constant_unary_fun {
   174   typedef _Argument argument_type;
   175   typedef  _Result  result_type;
   176   result_type _M_val;
   177 
   178   _Constant_unary_fun(const result_type& __v) : _M_val(__v) {}
   179   const result_type& operator()(const _Argument&) const { return _M_val; }
   180 };
   181 
   182 template <class _Result, class _Arg1, class _Arg2>
   183 struct _Constant_binary_fun {
   184   typedef  _Arg1   first_argument_type;
   185   typedef  _Arg2   second_argument_type;
   186   typedef  _Result result_type;
   187   _Result _M_val;
   188 
   189   _Constant_binary_fun(const _Result& __v) : _M_val(__v) {}
   190   const result_type& operator()(const _Arg1&, const _Arg2&) const {
   191     return _M_val;
   192   }
   193 };
   194 
   195 // identity_element (not part of the C++ standard).
   196 template <class _Tp> inline _Tp __identity_element(plus<_Tp>) {  return _Tp(0); }
   197 template <class _Tp> inline _Tp __identity_element(multiplies<_Tp>) { return _Tp(1); }
   198 
   199 _STLP_MOVE_TO_STD_NAMESPACE
   200 
   201 _STLP_END_NAMESPACE
   202 
   203 #endif /* _STLP_INTERNAL_FUNCTION_BASE_H */
   204 
   205 // Local Variables:
   206 // mode:C++
   207 // End: