epoc32/include/stdapis/stlportv5/stl/_numeric.c
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.c@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  *
     4  * Copyright (c) 1994
     5  * Hewlett-Packard Company
     6  *
     7  * Copyright (c) 1996,1997
     8  * Silicon Graphics Computer Systems, Inc.
     9  *
    10  * Copyright (c) 1997
    11  * Moscow Center for SPARC Technology
    12  *
    13  * Copyright (c) 1999 
    14  * Boris Fomitchev
    15  *
    16  * This material is provided "as is", with absolutely no warranty expressed
    17  * or implied. Any use is at your own risk.
    18  *
    19  * Permission to use or copy this software for any purpose is hereby granted 
    20  * without fee, provided the above notices are retained on all copies.
    21  * Permission to modify the code and to distribute modified code is granted,
    22  * provided the above notices are retained, and a notice that the code was
    23  * modified is included with the above copyright notice.
    24  *
    25  */
    26 #ifndef _STLP_NUMERIC_C
    27 #define _STLP_NUMERIC_C
    28 
    29 #ifndef _STLP_INTERNAL_NUMERIC_H
    30 # include <stl/_numeric.h>
    31 #endif
    32 
    33 _STLP_BEGIN_NAMESPACE
    34 
    35 template <class _InputIterator, class _OutputIterator, class _Tp,
    36           class _BinaryOperation>
    37 _OutputIterator 
    38 __partial_sum(_InputIterator __first, _InputIterator __last, 
    39               _OutputIterator __result, _Tp*, _BinaryOperation __binary_op)
    40 {
    41   _STLP_DEBUG_CHECK(__check_range(__first, __last))
    42   if (__first == __last) return __result;
    43   *__result = *__first;
    44 
    45   _Tp __val = *__first;
    46   while (++__first != __last) {
    47     __val = __binary_op(__val, *__first);
    48     *++__result = __val;
    49   }
    50   return ++__result;
    51 }
    52 
    53 template <class _InputIterator, class _OutputIterator, class _Tp, 
    54           class _BinaryOperation>
    55 _OutputIterator
    56 __adjacent_difference(_InputIterator __first, _InputIterator __last, 
    57                       _OutputIterator __result, _Tp*,
    58                       _BinaryOperation __binary_op) {
    59   _STLP_DEBUG_CHECK(__check_range(__first, __last))
    60   if (__first == __last) return __result;
    61   *__result = *__first;
    62   _Tp __val = *__first;
    63   while (++__first != __last) {
    64     _Tp __tmp = *__first;
    65     *++__result = __binary_op(__tmp, __val);
    66     __val = __tmp;
    67   }
    68   return ++__result;
    69 }
    70 
    71 
    72 template <class _Tp, class _Integer, class _MonoidOperation>
    73 _Tp __power(_Tp __x, _Integer __n, _MonoidOperation __opr) 
    74 {
    75   _STLP_MPWFIX_TRY
    76   if (__n == 0)
    77     return __identity_element(__opr);
    78   else {
    79     while ((__n & 1) == 0) {
    80       __n >>= 1;
    81       __x = __opr(__x, __x);
    82     }
    83     _Tp __result = __x;
    84 	_STLP_MPWFIX_TRY
    85     __n >>= 1;
    86     while (__n != 0) {
    87       __x = __opr(__x, __x);
    88       if ((__n & 1) != 0)
    89         __result = __opr(__result, __x);
    90       __n >>= 1;
    91     }
    92     return __result;
    93 	_STLP_MPWFIX_CATCH
    94   }
    95   _STLP_MPWFIX_CATCH_ACTION(__x = _Tp())
    96 }
    97 
    98 _STLP_END_NAMESPACE
    99 
   100 #endif /*  _STLP_NUMERIC_C */
   101 
   102 // Local Variables:
   103 // mode:C++
   104 // End: