/home/ntakagi/work/STLport-5.1.5/stlport/stl/_numeric.c

Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * Copyright (c) 1994
00005  * Hewlett-Packard Company
00006  *
00007  * Copyright (c) 1996,1997
00008  * Silicon Graphics Computer Systems, Inc.
00009  *
00010  * Copyright (c) 1997
00011  * Moscow Center for SPARC Technology
00012  *
00013  * Copyright (c) 1999
00014  * Boris Fomitchev
00015  *
00016  * This material is provided "as is", with absolutely no warranty expressed
00017  * or implied. Any use is at your own risk.
00018  *
00019  * Permission to use or copy this software for any purpose is hereby granted
00020  * without fee, provided the above notices are retained on all copies.
00021  * Permission to modify the code and to distribute modified code is granted,
00022  * provided the above notices are retained, and a notice that the code was
00023  * modified is included with the above copyright notice.
00024  *
00025  */
00026 #ifndef _STLP_NUMERIC_C
00027 #define _STLP_NUMERIC_C
00028 
00029 #ifndef _STLP_INTERNAL_NUMERIC_H
00030 # include <stl/_numeric.h>
00031 #endif
00032 
00033 _STLP_BEGIN_NAMESPACE
00034 
00035 _STLP_MOVE_TO_PRIV_NAMESPACE
00036 
00037 template <class _InputIterator, class _OutputIterator, class _Tp,
00038           class _BinaryOperation>
00039 _OutputIterator
00040 __partial_sum(_InputIterator __first, _InputIterator __last,
00041               _OutputIterator __result, _Tp*, _BinaryOperation __binary_op) {
00042   _STLP_DEBUG_CHECK(__check_range(__first, __last))
00043   if (__first == __last) return __result;
00044   *__result = *__first;
00045 
00046   _Tp __val = *__first;
00047   while (++__first != __last) {
00048     __val = __binary_op(__val, *__first);
00049     *++__result = __val;
00050   }
00051   return ++__result;
00052 }
00053 
00054 template <class _InputIterator, class _OutputIterator, class _Tp,
00055           class _BinaryOperation>
00056 _OutputIterator
00057 __adjacent_difference(_InputIterator __first, _InputIterator __last,
00058                       _OutputIterator __result, _Tp*,
00059                       _BinaryOperation __binary_op) {
00060   _STLP_DEBUG_CHECK(__check_range(__first, __last))
00061   if (__first == __last) return __result;
00062   *__result = *__first;
00063   _Tp __val = *__first;
00064   while (++__first != __last) {
00065     _Tp __tmp = *__first;
00066     *++__result = __binary_op(__tmp, __val);
00067     __val = __tmp;
00068   }
00069   return ++__result;
00070 }
00071 
00072 
00073 template <class _Tp, class _Integer, class _MonoidOperation>
00074 _Tp __power(_Tp __x, _Integer __n, _MonoidOperation __opr) {
00075   _STLP_MPWFIX_TRY
00076   if (__n == 0)
00077     return __identity_element(__opr);
00078   else {
00079     while ((__n & 1) == 0) {
00080       __n >>= 1;
00081       __x = __opr(__x, __x);
00082     }
00083     _Tp __result = __x;
00084   _STLP_MPWFIX_TRY
00085     __n >>= 1;
00086     while (__n != 0) {
00087       __x = __opr(__x, __x);
00088       if ((__n & 1) != 0)
00089         __result = __opr(__result, __x);
00090       __n >>= 1;
00091     }
00092     return __result;
00093   _STLP_MPWFIX_CATCH
00094   }
00095   _STLP_MPWFIX_CATCH_ACTION(__x = _Tp())
00096 }
00097 
00098 _STLP_MOVE_TO_STD_NAMESPACE
00099 
00100 _STLP_END_NAMESPACE
00101 
00102 #endif /*  _STLP_NUMERIC_C */
00103 
00104 // Local Variables:
00105 // mode:C++
00106 // End:



Generated on Mon Mar 10 15:32:31 2008 by  doxygen 1.5.1