/* Metrowerks Standard Library
 * Copyright  1995-2004 Metrowerks Corporation.  All rights reserved.
 *
 * $Date: 2004/06/15 14:17:18 $
 * $Revision: 1.19.2.1 $
 */

// numeric

#ifndef _NUMERIC
#define _NUMERIC

/*  numeric synopsis

namespace std
{

template <class InputIterator, class T>
T
accumulate(InputIterator first, InputIterator last, T init);

template <class InputIterator, class T, class BinaryOperation>
T
accumulate(InputIterator first, InputIterator last, T init, BinaryOperation binary_op);

template <class InputIterator1, class InputIterator2, class T>
T
inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init);

template <class InputIterator1, class InputIterator2, class T,
          class BinaryOperation1, class BinaryOperation2>
T
inner_product(InputIterator1 first1, InputIterator1 last1,
              InputIterator2 first2, T init, BinaryOperation1 binary_op1,
                                             BinaryOperation2 binary_op2);

template <class InputIterator, class OutputIterator>
OutputIterator
partial_sum(InputIterator first, InputIterator last, OutputIterator result);

template <class InputIterator, class OutputIterator, class BinaryOperation>
OutputIterator
partial_sum(InputIterator first, InputIterator last, OutputIterator result,
            BinaryOperation binary_op);

template <class InputIterator, class OutputIterator>
OutputIterator
adjacent_difference(InputIterator first, InputIterator last, OutputIterator result);

template <class InputIterator, class OutputIterator, class BinaryOperation>
OutputIterator
adjacent_difference(InputIterator first, InputIterator last, OutputIterator result,
                    BinaryOperation binary_op);

}  // std
*/

#include <mslconfig>

#include <iterator>

#ifndef RC_INVOKED

#ifdef __MWERKS__
#pragma options align=native
#endif

#ifdef _MSL_FORCE_ENUMS_ALWAYS_INT
	#if _MSL_FORCE_ENUMS_ALWAYS_INT
		#pragma enumsalwaysint on
	#else
		#pragma enumsalwaysint off
	#endif
#endif  // _MSL_FORCE_ENUMS_ALWAYS_INT

#ifdef _MSL_FORCE_ENABLE_BOOL_SUPPORT
	#if _MSL_FORCE_ENABLE_BOOL_SUPPORT
		#pragma bool on
	#else
		#pragma bool off
	#endif
#endif  // _MSL_FORCE_ENABLE_BOOL_SUPPORT

#ifndef _MSL_NO_CPP_NAMESPACE
	namespace std {
#endif

template <class InputIterator, class T>
inline
T
accumulate(InputIterator first, InputIterator last, T init)
{
	for (; first != last; ++first)
		init = init + *first;
	return init;
}

template <class InputIterator, class T, class BinaryOperation>
inline
T
accumulate(InputIterator first, InputIterator last, T init, BinaryOperation binary_op)
{
	for (; first != last; ++first)
		init = binary_op(init, *first);
	return init;
}

template <class InputIterator1, class InputIterator2, class T>
inline
T
inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init)
{
	for (; first1 != last1; ++first1, ++first2)
		init = init + *first1 * *first2;
	return init;
}

template <class InputIterator1, class InputIterator2, class T,
	class BinaryOperation1, class BinaryOperation2>
inline
T
inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2,
	T init, BinaryOperation1 binary_op1, BinaryOperation2 binary_op2)
{
	for (; first1 != last1; ++first1, ++first2)
		init = binary_op1(init, binary_op2(*first1, *first2));
	return init;
}

template <class InputIterator, class OutputIterator>
inline
OutputIterator
partial_sum(InputIterator first, InputIterator last, OutputIterator result)
{
	if (first == last)
		return result;
	typename iterator_traits<InputIterator>::value_type tmp(*first);
	*result = tmp;
	for (++first, ++result; first != last; ++first, ++result)
		*result = tmp = tmp + *first;
	return result;
}

template <class InputIterator, class OutputIterator, class BinaryOperation>
inline
OutputIterator
partial_sum(InputIterator first, InputIterator last, OutputIterator result,
	BinaryOperation binary_op)
{
	if (first == last)
		return result;
	typename iterator_traits<InputIterator>::value_type tmp(*first);
	*result = tmp;
	for (++first, ++result; first != last; ++first, ++result)
		*result = tmp = binary_op(tmp, *first);
	return result;
}

template <class InputIterator, class OutputIterator>
inline
OutputIterator
adjacent_difference(InputIterator first, InputIterator last, OutputIterator result)
{
	typedef typename iterator_traits<InputIterator>::value_type T;
	if (first == last)
		return result;
	T tmp1(*first);
	*result = tmp1;
	for (++first, ++result; first != last; ++first, ++result)
	{
		T tmp2(*first);
		*result = tmp2 - tmp1;
		tmp1 = tmp2;
	}
	return result;
}

template <class InputIterator, class OutputIterator, class BinaryOperation>
OutputIterator
adjacent_difference(InputIterator first, InputIterator last, OutputIterator result,
	BinaryOperation binary_op)
{
	typedef typename iterator_traits<InputIterator>::value_type T;
	if (first == last)
		return result;
	T tmp1(*first);
	*result = tmp1;
	for (++first, ++result; first != last; ++first, ++result)
	{
		T tmp2(*first);
		*result = binary_op(tmp2, tmp1);
		tmp1 = tmp2;
	}
	return result;
}

#ifndef _MSL_NO_CPP_NAMESPACE
	} // namespace std
#endif

#ifdef _MSL_FORCE_ENUMS_ALWAYS_INT
	#pragma enumsalwaysint reset
#endif

#ifdef _MSL_FORCE_ENABLE_BOOL_SUPPORT
	#pragma bool reset
#endif

#ifdef __MWERKS__
#pragma options align=reset
#endif

#endif // RC_INVOKED

#endif // _NUMERIC

// hh 971223 Made include guards standard
// hh 971223 added alignment wrapper
// hh 971223 Changed filename from numeric.h to numeric
// hh 971230 added RC_INVOKED wrapper
// hh 990506 Rewrote
// hh 010402 Removed 68K CMF support
