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