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