summaryrefslogtreecommitdiffstats
path: root/contrib/libstdc++/include/bits/stl_numeric.h
diff options
context:
space:
mode:
authorkan <kan@FreeBSD.org>2004-07-28 03:12:05 +0000
committerkan <kan@FreeBSD.org>2004-07-28 03:12:05 +0000
commit96bad46eee8bf907dceb152bbb9d128bed5a4956 (patch)
tree75ef0e6da73746d6849e25a0996ae34e1aeff51d /contrib/libstdc++/include/bits/stl_numeric.h
parent5e00ec74d8ce58f99801200d4d3d0412c7cc1b28 (diff)
downloadFreeBSD-src-96bad46eee8bf907dceb152bbb9d128bed5a4956.zip
FreeBSD-src-96bad46eee8bf907dceb152bbb9d128bed5a4956.tar.gz
Gcc 3.4.2 20040728 C++ support bits.
Diffstat (limited to 'contrib/libstdc++/include/bits/stl_numeric.h')
-rw-r--r--contrib/libstdc++/include/bits/stl_numeric.h163
1 files changed, 137 insertions, 26 deletions
diff --git a/contrib/libstdc++/include/bits/stl_numeric.h b/contrib/libstdc++/include/bits/stl_numeric.h
index 23f2bcc..58762a4 100644
--- a/contrib/libstdc++/include/bits/stl_numeric.h
+++ b/contrib/libstdc++/include/bits/stl_numeric.h
@@ -1,6 +1,6 @@
// Numeric functions implementation -*- C++ -*-
-// Copyright (C) 2001 Free Software Foundation, Inc.
+// Copyright (C) 2001, 2004 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
@@ -58,78 +58,153 @@
* You should not attempt to use it directly.
*/
-#ifndef _CPP_BITS_STL_NUMERIC_H
-#define _CPP_BITS_STL_NUMERIC_H 1
+#ifndef _STL_NUMERIC_H
+#define _STL_NUMERIC_H 1
+
+#include <debug/debug.h>
namespace std
{
+ /**
+ * @brief Accumulate values in a range.
+ *
+ * Accumulates the values in the range [first,last) using operator+(). The
+ * initial value is @a init. The values are processed in order.
+ *
+ * @param first Start of range.
+ * @param last End of range.
+ * @param init Starting value to add other values to.
+ * @return The final sum.
+ */
template<typename _InputIterator, typename _Tp>
_Tp
accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
{
// concept requirements
- __glibcpp_function_requires(_InputIteratorConcept<_InputIterator>)
+ __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
+ __glibcxx_requires_valid_range(__first, __last);
for ( ; __first != __last; ++__first)
__init = __init + *__first;
return __init;
}
+ /**
+ * @brief Accumulate values in a range with operation.
+ *
+ * Accumulates the values in the range [first,last) using the function
+ * object @a binary_op. The initial value is @a init. The values are
+ * processed in order.
+ *
+ * @param first Start of range.
+ * @param last End of range.
+ * @param init Starting value to add other values to.
+ * @param binary_op Function object to accumulate with.
+ * @return The final sum.
+ */
template<typename _InputIterator, typename _Tp, typename _BinaryOperation>
_Tp
accumulate(_InputIterator __first, _InputIterator __last, _Tp __init,
_BinaryOperation __binary_op)
{
// concept requirements
- __glibcpp_function_requires(_InputIteratorConcept<_InputIterator>)
+ __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
+ __glibcxx_requires_valid_range(__first, __last);
for ( ; __first != __last; ++__first)
__init = __binary_op(__init, *__first);
return __init;
}
+ /**
+ * @brief Compute inner product of two ranges.
+ *
+ * Starting with an initial value of @a init, multiplies successive
+ * elements from the two ranges and adds each product into the accumulated
+ * value using operator+(). The values in the ranges are processed in
+ * order.
+ *
+ * @param first1 Start of range 1.
+ * @param last1 End of range 1.
+ * @param first2 Start of range 2.
+ * @param init Starting value to add other values to.
+ * @return The final inner product.
+ */
template<typename _InputIterator1, typename _InputIterator2, typename _Tp>
_Tp
inner_product(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _Tp __init)
{
// concept requirements
- __glibcpp_function_requires(_InputIteratorConcept<_InputIterator1>)
- __glibcpp_function_requires(_InputIteratorConcept<_InputIterator2>)
+ __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
+ __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
+ __glibcxx_requires_valid_range(__first1, __last1);
for ( ; __first1 != __last1; ++__first1, ++__first2)
__init = __init + (*__first1 * *__first2);
return __init;
}
+ /**
+ * @brief Compute inner product of two ranges.
+ *
+ * Starting with an initial value of @a init, applies @a binary_op2 to
+ * successive elements from the two ranges and accumulates each result into
+ * the accumulated value using @a binary_op1. The values in the ranges are
+ * processed in order.
+ *
+ * @param first1 Start of range 1.
+ * @param last1 End of range 1.
+ * @param first2 Start of range 2.
+ * @param init Starting value to add other values to.
+ * @param binary_op1 Function object to accumulate with.
+ * @param binary_op2 Function object to apply to pairs of input values.
+ * @return The final inner product.
+ */
template<typename _InputIterator1, typename _InputIterator2, typename _Tp,
typename _BinaryOperation1, typename _BinaryOperation2>
_Tp
inner_product(_InputIterator1 __first1, _InputIterator1 __last1,
- _InputIterator2 __first2, _Tp __init,
+ _InputIterator2 __first2, _Tp __init,
_BinaryOperation1 __binary_op1,
_BinaryOperation2 __binary_op2)
{
// concept requirements
- __glibcpp_function_requires(_InputIteratorConcept<_InputIterator1>)
- __glibcpp_function_requires(_InputIteratorConcept<_InputIterator2>)
+ __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
+ __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
+ __glibcxx_requires_valid_range(__first1, __last1);
for ( ; __first1 != __last1; ++__first1, ++__first2)
__init = __binary_op1(__init, __binary_op2(*__first1, *__first2));
return __init;
}
+ /**
+ * @brief Return list of partial sums
+ *
+ * Accumulates the values in the range [first,last) using operator+().
+ * As each successive input value is added into the total, that partial sum
+ * is written to @a result. Therefore, the first value in result is the
+ * first value of the input, the second value in result is the sum of the
+ * first and second input values, and so on.
+ *
+ * @param first Start of input range.
+ * @param last End of input range.
+ * @param result Output to write sums to.
+ * @return Iterator pointing just beyond the values written to result.
+ */
template<typename _InputIterator, typename _OutputIterator>
- _OutputIterator
+ _OutputIterator
partial_sum(_InputIterator __first, _InputIterator __last,
_OutputIterator __result)
{
typedef typename iterator_traits<_InputIterator>::value_type _ValueType;
// concept requirements
- __glibcpp_function_requires(_InputIteratorConcept<_InputIterator>)
- __glibcpp_function_requires(_OutputIteratorConcept<_OutputIterator, _ValueType>)
+ __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
+ __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, _ValueType>)
+ __glibcxx_requires_valid_range(__first, __last);
if (__first == __last) return __result;
*__result = *__first;
@@ -141,16 +216,31 @@ namespace std
return ++__result;
}
+ /**
+ * @brief Return list of partial sums
+ *
+ * Accumulates the values in the range [first,last) using operator+().
+ * As each successive input value is added into the total, that partial sum
+ * is written to @a result. Therefore, the first value in result is the
+ * first value of the input, the second value in result is the sum of the
+ * first and second input values, and so on.
+ *
+ * @param first Start of input range.
+ * @param last End of input range.
+ * @param result Output to write sums to.
+ * @return Iterator pointing just beyond the values written to result.
+ */
template<typename _InputIterator, typename _OutputIterator, typename _BinaryOperation>
- _OutputIterator
+ _OutputIterator
partial_sum(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _BinaryOperation __binary_op)
{
typedef typename iterator_traits<_InputIterator>::value_type _ValueType;
// concept requirements
- __glibcpp_function_requires(_InputIteratorConcept<_InputIterator>)
- __glibcpp_function_requires(_OutputIteratorConcept<_OutputIterator, _ValueType>)
+ __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
+ __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, _ValueType>)
+ __glibcxx_requires_valid_range(__first, __last);
if (__first == __last) return __result;
*__result = *__first;
@@ -162,6 +252,17 @@ namespace std
return ++__result;
}
+ /**
+ * @brief Return differences between adjacent values.
+ *
+ * Computes the difference between adjacent values in the range
+ * [first,last) using operator-() and writes the result to @a result.
+ *
+ * @param first Start of input range.
+ * @param last End of input range.
+ * @param result Output to write sums to.
+ * @return Iterator pointing just beyond the values written to result.
+ */
template<typename _InputIterator, typename _OutputIterator>
_OutputIterator
adjacent_difference(_InputIterator __first,
@@ -170,8 +271,9 @@ namespace std
typedef typename iterator_traits<_InputIterator>::value_type _ValueType;
// concept requirements
- __glibcpp_function_requires(_InputIteratorConcept<_InputIterator>)
- __glibcpp_function_requires(_OutputIteratorConcept<_OutputIterator, _ValueType>)
+ __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
+ __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, _ValueType>)
+ __glibcxx_requires_valid_range(__first, __last);
if (__first == __last) return __result;
*__result = *__first;
@@ -184,16 +286,29 @@ namespace std
return ++__result;
}
+ /**
+ * @brief Return differences between adjacent values.
+ *
+ * Computes the difference between adjacent values in the range
+ * [first,last) using the function object @a binary_op and writes the
+ * result to @a result.
+ *
+ * @param first Start of input range.
+ * @param last End of input range.
+ * @param result Output to write sums to.
+ * @return Iterator pointing just beyond the values written to result.
+ */
template<typename _InputIterator, typename _OutputIterator, typename _BinaryOperation>
- _OutputIterator
+ _OutputIterator
adjacent_difference(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _BinaryOperation __binary_op)
{
typedef typename iterator_traits<_InputIterator>::value_type _ValueType;
// concept requirements
- __glibcpp_function_requires(_InputIteratorConcept<_InputIterator>)
- __glibcpp_function_requires(_OutputIteratorConcept<_OutputIterator, _ValueType>)
+ __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
+ __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, _ValueType>)
+ __glibcxx_requires_valid_range(__first, __last);
if (__first == __last) return __result;
*__result = *__first;
@@ -208,8 +323,4 @@ namespace std
} // namespace std
-#endif /* _CPP_BITS_STL_NUMERIC_H */
-
-// Local Variables:
-// mode:C++
-// End:
+#endif /* _STL_NUMERIC_H */
OpenPOWER on IntegriCloud