_numeric.h

00001 /*
00002  *
00003  * Copyright (c) 1994
00004  * Hewlett-Packard Company
00005  *
00006  * Copyright (c) 1996,1997
00007  * Silicon Graphics Computer Systems, Inc.
00008  *
00009  * Copyright (c) 1999 
00010  * Boris Fomitchev
00011  *
00012  * This material is provided "as is", with absolutely no warranty expressed
00013  * or implied. Any use is at your own risk.
00014  *
00015  * Permission to use or copy this software for any purpose is hereby granted 
00016  * without fee, provided the above notices are retained on all copies.
00017  * Permission to modify the code and to distribute modified code is granted,
00018  * provided the above notices are retained, and a notice that the code was
00019  * modified is included with the above copyright notice.
00020  *
00021  */
00022 
00023 /* NOTE: This is an internal header file, included by other STL headers.
00024  *   You should not attempt to use it directly.
00025  */
00026 
00027 
00028 #ifndef _STLP_INTERNAL_NUMERIC_H
00029 #define _STLP_INTERNAL_NUMERIC_H
00030 
00031 #ifndef _STLP_INTERNAL_FUNCTION_H
00032 # include <stl/_function_base.h>
00033 #endif
00034 
00035 #ifndef _STLP_INTERNAL_ITERATOR_BASE_H
00036 # include <stl/_iterator_base.h>
00037 #endif
00038 
00039 _STLP_BEGIN_NAMESPACE
00040 
00041 template <class _InputIterator, class _Tp>
00042 _STLP_INLINE_LOOP
00043 _Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp _Init)
00044 {
00045   _STLP_DEBUG_CHECK(__check_range(__first, __last))
00046   for ( ; __first != __last; ++__first)
00047     _Init = _Init + *__first;
00048   return _Init;
00049 }
00050 
00051 template <class _InputIterator, class _Tp, class _BinaryOperation>
00052 _STLP_INLINE_LOOP
00053 _Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp _Init,
00054                _BinaryOperation __binary_op)
00055 {
00056   _STLP_DEBUG_CHECK(__check_range(__first, __last))
00057   for ( ; __first != __last; ++__first)
00058     _Init = __binary_op(_Init, *__first);
00059   return _Init;
00060 }
00061 
00062 template <class _InputIterator1, class _InputIterator2, class _Tp>
00063 _STLP_INLINE_LOOP
00064 _Tp inner_product(_InputIterator1 __first1, _InputIterator1 __last1,
00065                   _InputIterator2 __first2, _Tp _Init)
00066 {
00067   _STLP_DEBUG_CHECK(__check_range(__first1, __last1))
00068   for ( ; __first1 != __last1; ++__first1, ++__first2)
00069     _Init = _Init + (*__first1 * *__first2);
00070   return _Init;
00071 }
00072 
00073 template <class _InputIterator1, class _InputIterator2, class _Tp,
00074           class _BinaryOperation1, class _BinaryOperation2>
00075 _STLP_INLINE_LOOP
00076 _Tp inner_product(_InputIterator1 __first1, _InputIterator1 __last1,
00077                   _InputIterator2 __first2, _Tp _Init, 
00078                   _BinaryOperation1 __binary_op1,
00079                   _BinaryOperation2 __binary_op2)
00080 {
00081   _STLP_DEBUG_CHECK(__check_range(__first1, __last1))
00082   for ( ; __first1 != __last1; ++__first1, ++__first2)
00083     _Init = __binary_op1(_Init, __binary_op2(*__first1, *__first2));
00084   return _Init;
00085 }
00086 
00087 template <class _InputIterator, class _OutputIterator, class _Tp,
00088           class _BinaryOperation>
00089 _OutputIterator 
00090 __partial_sum(_InputIterator __first, _InputIterator __last, 
00091               _OutputIterator __result, _Tp*, _BinaryOperation __binary_op);
00092 
00093 
00094 template <class _InputIterator, class _OutputIterator>
00095 inline _OutputIterator 
00096 partial_sum(_InputIterator __first, _InputIterator __last,
00097             _OutputIterator __result) {
00098   return __partial_sum(__first, __last, __result, _STLP_VALUE_TYPE(__first, _InputIterator),
00099                        __plus(_STLP_VALUE_TYPE(__first, _InputIterator)));
00100 }
00101 
00102 template <class _InputIterator, class _OutputIterator, class _BinaryOperation>
00103 inline _OutputIterator 
00104 partial_sum(_InputIterator __first, _InputIterator __last,
00105             _OutputIterator __result, _BinaryOperation __binary_op) {
00106   return __partial_sum(__first, __last, __result, _STLP_VALUE_TYPE(__first, _InputIterator), 
00107                        __binary_op);
00108 }
00109 
00110 
00111 template <class _InputIterator, class _OutputIterator, class _Tp, 
00112           class _BinaryOperation>
00113 _OutputIterator
00114 __adjacent_difference(_InputIterator __first, _InputIterator __last, 
00115                       _OutputIterator __result, _Tp*,
00116                       _BinaryOperation __binary_op);
00117 
00118 template <class _InputIterator, class _OutputIterator>
00119 inline _OutputIterator
00120 adjacent_difference(_InputIterator __first,
00121                     _InputIterator __last, _OutputIterator __result) {
00122   return __adjacent_difference(__first, __last, __result,
00123                                _STLP_VALUE_TYPE(__first, _InputIterator),
00124                                __minus(_STLP_VALUE_TYPE(__first, _InputIterator)));
00125 }
00126 
00127 template <class _InputIterator, class _OutputIterator, class _BinaryOperation>
00128 _OutputIterator 
00129 adjacent_difference(_InputIterator __first, _InputIterator __last,
00130                     _OutputIterator __result, _BinaryOperation __binary_op) {
00131   return __adjacent_difference(__first, __last, __result,
00132                                _STLP_VALUE_TYPE(__first, _InputIterator),
00133                                __binary_op);
00134 }
00135 
00136 template <class _Tp, class _Integer, class _MonoidOperation>
00137 _Tp __power(_Tp __x, _Integer __n, _MonoidOperation __opr);
00138 
00139 # ifndef _STLP_NO_EXTENSIONS
00140 
00141 // Returns __x ** __n, where __n >= 0.  _Note that "multiplication"
00142 // is required to be associative, but not necessarily commutative.
00143 
00144 template <class _Tp, class _Integer>
00145 inline _Tp __power(_Tp __x, _Integer __n)
00146 {
00147   return __power(__x, __n, multiplies<_Tp>());
00148 }
00149 
00150 // Alias for the internal name __power.  Note that power is an extension,
00151 // not part of the C++ standard.
00152 template <class _Tp, class _Integer, class _MonoidOperation>
00153 inline _Tp power(_Tp __x, _Integer __n, _MonoidOperation __opr) {
00154   return __power(__x, __n, __opr);
00155 }
00156 
00157 
00158 template <class _Tp, class _Integer>
00159 inline _Tp power(_Tp __x, _Integer __n) {
00160   return __power(__x, __n, multiplies<_Tp>());
00161 }
00162 
00163 // iota is not part of the C++ standard.  It is an extension.
00164 
00165 template <class _ForwardIterator, class _Tp>
00166 _STLP_INLINE_LOOP
00167 void 
00168 iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value)
00169 {
00170   _STLP_DEBUG_CHECK(__check_range(__first, __last))
00171   while (__first != __last)
00172     *__first++ = __value++;
00173 }
00174 # endif
00175 
00176 _STLP_END_NAMESPACE
00177 
00178 # if !defined (_STLP_LINK_TIME_INSTANTIATION)
00179 #  include <stl/_numeric.c>
00180 # endif
00181 
00182 #endif /* _STLP_INTERNAL_NUMERIC_H */
00183 
00184 // Local Variables:
00185 // mode:C++
00186 // End:

Generated on Mon Jun 5 10:20:46 2006 for Intelligence.kdevelop by  doxygen 1.4.6