epoc32/include/stdapis/stlportv5/stl/_numeric.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/_numeric.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
     1 /*
     2  *
     3  * Copyright (c) 1994
     4  * Hewlett-Packard Company
     5  *
     6  * Copyright (c) 1996,1997
     7  * Silicon Graphics Computer Systems, Inc.
     8  *
     9  * Copyright (c) 1999 
    10  * Boris Fomitchev
    11  *
    12  * This material is provided "as is", with absolutely no warranty expressed
    13  * or implied. Any use is at your own risk.
    14  *
    15  * Permission to use or copy this software for any purpose is hereby granted 
    16  * without fee, provided the above notices are retained on all copies.
    17  * Permission to modify the code and to distribute modified code is granted,
    18  * provided the above notices are retained, and a notice that the code was
    19  * modified is included with the above copyright notice.
    20  *
    21  */
    22 
    23 /* NOTE: This is an internal header file, included by other STL headers.
    24  *   You should not attempt to use it directly.
    25  */
    26 
    27 
    28 #ifndef _STLP_INTERNAL_NUMERIC_H
    29 #define _STLP_INTERNAL_NUMERIC_H
    30 
    31 #ifndef _STLP_INTERNAL_FUNCTION_H
    32 # include <stl/_function_base.h>
    33 #endif
    34 
    35 #ifndef _STLP_INTERNAL_ITERATOR_BASE_H
    36 # include <stl/_iterator_base.h>
    37 #endif
    38 
    39 _STLP_BEGIN_NAMESPACE
    40 
    41 template <class _InputIterator, class _Tp>
    42 _STLP_INLINE_LOOP
    43 _Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp _Init)
    44 {
    45   _STLP_DEBUG_CHECK(__check_range(__first, __last))
    46   for ( ; __first != __last; ++__first)
    47 #ifndef 	__SYMBIAN32__  	
    48     _Init = _Init + *__first;
    49 #else
    50 	    _Init +=  *__first;
    51 #endif
    52   return _Init;
    53 }
    54 
    55 template <class _InputIterator, class _Tp, class _BinaryOperation>
    56 _STLP_INLINE_LOOP
    57 _Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp _Init,
    58                _BinaryOperation __binary_op)
    59 {
    60   _STLP_DEBUG_CHECK(__check_range(__first, __last))
    61   for ( ; __first != __last; ++__first)
    62     _Init = __binary_op(_Init, *__first);
    63   return _Init;
    64 }
    65 
    66 template <class _InputIterator1, class _InputIterator2, class _Tp>
    67 _STLP_INLINE_LOOP
    68 _Tp inner_product(_InputIterator1 __first1, _InputIterator1 __last1,
    69                   _InputIterator2 __first2, _Tp _Init)
    70 {
    71   _STLP_DEBUG_CHECK(__check_range(__first1, __last1))
    72   for ( ; __first1 != __last1; ++__first1, ++__first2)
    73     _Init = _Init + (*__first1 * *__first2);
    74   return _Init;
    75 }
    76 
    77 template <class _InputIterator1, class _InputIterator2, class _Tp,
    78           class _BinaryOperation1, class _BinaryOperation2>
    79 _STLP_INLINE_LOOP
    80 _Tp inner_product(_InputIterator1 __first1, _InputIterator1 __last1,
    81                   _InputIterator2 __first2, _Tp _Init, 
    82                   _BinaryOperation1 __binary_op1,
    83                   _BinaryOperation2 __binary_op2)
    84 {
    85   _STLP_DEBUG_CHECK(__check_range(__first1, __last1))
    86   for ( ; __first1 != __last1; ++__first1, ++__first2)
    87     _Init = __binary_op1(_Init, __binary_op2(*__first1, *__first2));
    88   return _Init;
    89 }
    90 
    91 template <class _InputIterator, class _OutputIterator, class _Tp,
    92           class _BinaryOperation>
    93 _OutputIterator 
    94 __partial_sum(_InputIterator __first, _InputIterator __last, 
    95               _OutputIterator __result, _Tp*, _BinaryOperation __binary_op);
    96 
    97 
    98 template <class _InputIterator, class _OutputIterator>
    99 inline _OutputIterator 
   100 partial_sum(_InputIterator __first, _InputIterator __last,
   101             _OutputIterator __result) {
   102   return __partial_sum(__first, __last, __result, _STLP_VALUE_TYPE(__first, _InputIterator),
   103                        __plus(_STLP_VALUE_TYPE(__first, _InputIterator)));
   104 }
   105 
   106 template <class _InputIterator, class _OutputIterator, class _BinaryOperation>
   107 inline _OutputIterator 
   108 partial_sum(_InputIterator __first, _InputIterator __last,
   109             _OutputIterator __result, _BinaryOperation __binary_op) {
   110   return __partial_sum(__first, __last, __result, _STLP_VALUE_TYPE(__first, _InputIterator), 
   111                        __binary_op);
   112 }
   113 
   114 
   115 template <class _InputIterator, class _OutputIterator, class _Tp, 
   116           class _BinaryOperation>
   117 _OutputIterator
   118 __adjacent_difference(_InputIterator __first, _InputIterator __last, 
   119                       _OutputIterator __result, _Tp*,
   120                       _BinaryOperation __binary_op);
   121 
   122 template <class _InputIterator, class _OutputIterator>
   123 inline _OutputIterator
   124 adjacent_difference(_InputIterator __first,
   125                     _InputIterator __last, _OutputIterator __result) {
   126   return __adjacent_difference(__first, __last, __result,
   127                                _STLP_VALUE_TYPE(__first, _InputIterator),
   128                                __minus(_STLP_VALUE_TYPE(__first, _InputIterator)));
   129 }
   130 
   131 template <class _InputIterator, class _OutputIterator, class _BinaryOperation>
   132 _OutputIterator 
   133 adjacent_difference(_InputIterator __first, _InputIterator __last,
   134                     _OutputIterator __result, _BinaryOperation __binary_op) {
   135   return __adjacent_difference(__first, __last, __result,
   136                                _STLP_VALUE_TYPE(__first, _InputIterator),
   137                                __binary_op);
   138 }
   139 
   140 template <class _Tp, class _Integer, class _MonoidOperation>
   141 _Tp __power(_Tp __x, _Integer __n, _MonoidOperation __opr);
   142 
   143 # ifndef _STLP_NO_EXTENSIONS
   144 
   145 // Returns __x ** __n, where __n >= 0.  _Note that "multiplication"
   146 // is required to be associative, but not necessarily commutative.
   147 
   148 template <class _Tp, class _Integer>
   149 inline _Tp __power(_Tp __x, _Integer __n)
   150 {
   151   return __power(__x, __n, multiplies<_Tp>());
   152 }
   153 
   154 // Alias for the internal name __power.  Note that power is an extension,
   155 // not part of the C++ standard.
   156 template <class _Tp, class _Integer, class _MonoidOperation>
   157 inline _Tp power(_Tp __x, _Integer __n, _MonoidOperation __opr) {
   158   return __power(__x, __n, __opr);
   159 }
   160 
   161 
   162 template <class _Tp, class _Integer>
   163 inline _Tp power(_Tp __x, _Integer __n) {
   164   return __power(__x, __n, multiplies<_Tp>());
   165 }
   166 
   167 // iota is not part of the C++ standard.  It is an extension.
   168 
   169 template <class _ForwardIterator, class _Tp>
   170 _STLP_INLINE_LOOP
   171 void 
   172 iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __val)
   173 {
   174   _STLP_DEBUG_CHECK(__check_range(__first, __last))
   175   while (__first != __last)
   176     *__first++ = __val++;
   177 }
   178 # endif
   179 
   180 _STLP_END_NAMESPACE
   181 
   182 # if !defined (_STLP_LINK_TIME_INSTANTIATION)
   183 #  include <stl/_numeric.c>
   184 # endif
   185 
   186 #endif /* _STLP_INTERNAL_NUMERIC_H */
   187 
   188 // Local Variables:
   189 // mode:C++
   190 // End: