forked from boostorg/range
reformatted numeric.hpp
This commit is contained in:
@ -1,14 +1,8 @@
|
|||||||
///////////////////////////////////////////////////////////////////////////////
|
// Copyright 2009-2014 Neil Groves.
|
||||||
/// \file algorithm.hpp
|
|
||||||
/// Contains range-based versions of the std algorithms
|
|
||||||
//
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Copyright 2009 Neil Groves.
|
|
||||||
// Distributed under the Boost Software License, Version 1.0. (See
|
// Distributed under the Boost Software License, Version 1.0. (See
|
||||||
// accompanying file LICENSE_1_0.txt or copy at
|
// accompanying file LICENSE_1_0.txt or copy at
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
//
|
//
|
||||||
|
|
||||||
// Copyright 2006 Thorsten Ottosen.
|
// Copyright 2006 Thorsten Ottosen.
|
||||||
// Distributed under the Boost Software License, Version 1.0. (See
|
// Distributed under the Boost Software License, Version 1.0. (See
|
||||||
// accompanying file LICENSE_1_0.txt or copy at
|
// accompanying file LICENSE_1_0.txt or copy at
|
||||||
@ -18,7 +12,9 @@
|
|||||||
// Distributed under the Boost Software License, Version 1.0. (See
|
// Distributed under the Boost Software License, Version 1.0. (See
|
||||||
// accompanying file LICENSE_1_0.txt or copy at
|
// accompanying file LICENSE_1_0.txt or copy at
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
//
|
||||||
|
// Contains range-based versions of the numeric std algorithms
|
||||||
|
//
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
#pragma once
|
#pragma once
|
||||||
#endif
|
#endif
|
||||||
@ -42,14 +38,19 @@ namespace boost
|
|||||||
template<class SinglePassRange, class Value>
|
template<class SinglePassRange, class Value>
|
||||||
inline Value accumulate(const SinglePassRange& rng, Value init)
|
inline Value accumulate(const SinglePassRange& rng, Value init)
|
||||||
{
|
{
|
||||||
BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange> ));
|
BOOST_RANGE_CONCEPT_ASSERT((
|
||||||
|
SinglePassRangeConcept<const SinglePassRange>));
|
||||||
|
|
||||||
return std::accumulate(boost::begin(rng), boost::end(rng), init);
|
return std::accumulate(boost::begin(rng), boost::end(rng), init);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class SinglePassRange, class Value, class BinaryOperation>
|
template<class SinglePassRange, class Value, class BinaryOperation>
|
||||||
inline Value accumulate( const SinglePassRange& rng, Value init, BinaryOperation op )
|
inline Value accumulate(const SinglePassRange& rng, Value init,
|
||||||
|
BinaryOperation op)
|
||||||
{
|
{
|
||||||
BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange> ));
|
BOOST_RANGE_CONCEPT_ASSERT((
|
||||||
|
SinglePassRangeConcept<const SinglePassRange> ));
|
||||||
|
|
||||||
return std::accumulate(boost::begin(rng), boost::end(rng), init, op);
|
return std::accumulate(boost::begin(rng), boost::end(rng), init, op);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,38 +78,61 @@ namespace boost
|
|||||||
|
|
||||||
} // namespace range_detail
|
} // namespace range_detail
|
||||||
|
|
||||||
template< class SinglePassRange1, class SinglePassRange2, class Value >
|
template<
|
||||||
inline Value inner_product( const SinglePassRange1& rng1, const SinglePassRange2& rng2, Value init )
|
class SinglePassRange1,
|
||||||
|
class SinglePassRange2,
|
||||||
|
class Value
|
||||||
|
>
|
||||||
|
inline Value inner_product(
|
||||||
|
const SinglePassRange1& rng1,
|
||||||
|
const SinglePassRange2& rng2,
|
||||||
|
Value init)
|
||||||
{
|
{
|
||||||
BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange1> ));
|
BOOST_RANGE_CONCEPT_ASSERT((
|
||||||
BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange2> ));
|
SinglePassRangeConcept<const SinglePassRange1>));
|
||||||
|
|
||||||
|
BOOST_RANGE_CONCEPT_ASSERT((
|
||||||
|
SinglePassRangeConcept<const SinglePassRange2>));
|
||||||
|
|
||||||
BOOST_ASSERT(
|
BOOST_ASSERT(
|
||||||
range_detail::inner_product_precondition(
|
range_detail::inner_product_precondition(
|
||||||
rng1, rng2,
|
rng1, rng2,
|
||||||
typename range_category<const SinglePassRange1>::type(),
|
typename range_category<const SinglePassRange1>::type(),
|
||||||
typename range_category<const SinglePassRange2>::type()));
|
typename range_category<const SinglePassRange2>::type()));
|
||||||
|
|
||||||
return std::inner_product( boost::begin(rng1), boost::end(rng1),
|
return std::inner_product(
|
||||||
|
boost::begin(rng1), boost::end(rng1),
|
||||||
boost::begin(rng2), init);
|
boost::begin(rng2), init);
|
||||||
}
|
}
|
||||||
|
|
||||||
template< class SinglePassRange1,
|
template<
|
||||||
|
class SinglePassRange1,
|
||||||
class SinglePassRange2,
|
class SinglePassRange2,
|
||||||
class Value,
|
class Value,
|
||||||
class BinaryOperation1, class BinaryOperation2 >
|
class BinaryOperation1,
|
||||||
inline Value inner_product( const SinglePassRange1& rng1, const SinglePassRange2& rng2,
|
class BinaryOperation2
|
||||||
|
>
|
||||||
|
inline Value inner_product(
|
||||||
|
const SinglePassRange1& rng1,
|
||||||
|
const SinglePassRange2& rng2,
|
||||||
Value init,
|
Value init,
|
||||||
BinaryOperation1 op1, BinaryOperation2 op2 )
|
BinaryOperation1 op1,
|
||||||
|
BinaryOperation2 op2)
|
||||||
{
|
{
|
||||||
BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange1> ));
|
BOOST_RANGE_CONCEPT_ASSERT((
|
||||||
BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange2> ));
|
SinglePassRangeConcept<const SinglePassRange1>));
|
||||||
|
|
||||||
|
BOOST_RANGE_CONCEPT_ASSERT((
|
||||||
|
SinglePassRangeConcept<const SinglePassRange2>));
|
||||||
|
|
||||||
BOOST_ASSERT(
|
BOOST_ASSERT(
|
||||||
range_detail::inner_product_precondition(
|
range_detail::inner_product_precondition(
|
||||||
rng1, rng2,
|
rng1, rng2,
|
||||||
typename range_category<const SinglePassRange1>::type(),
|
typename range_category<const SinglePassRange1>::type(),
|
||||||
typename range_category<const SinglePassRange2>::type()));
|
typename range_category<const SinglePassRange2>::type()));
|
||||||
|
|
||||||
return std::inner_product( boost::begin(rng1), boost::end(rng1),
|
return std::inner_product(
|
||||||
|
boost::begin(rng1), boost::end(rng1),
|
||||||
boost::begin(rng2), init, op1, op2);
|
boost::begin(rng2), init, op1, op2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,37 +140,49 @@ namespace boost
|
|||||||
inline OutputIterator partial_sum(const SinglePassRange& rng,
|
inline OutputIterator partial_sum(const SinglePassRange& rng,
|
||||||
OutputIterator result)
|
OutputIterator result)
|
||||||
{
|
{
|
||||||
BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange> ));
|
BOOST_RANGE_CONCEPT_ASSERT((
|
||||||
|
SinglePassRangeConcept<const SinglePassRange>));
|
||||||
|
|
||||||
return std::partial_sum(boost::begin(rng), boost::end(rng), result);
|
return std::partial_sum(boost::begin(rng), boost::end(rng), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class SinglePassRange, class OutputIterator, class BinaryOperation>
|
template<class SinglePassRange, class OutputIterator, class BinaryOperation>
|
||||||
inline OutputIterator partial_sum ( const SinglePassRange& rng, OutputIterator result,
|
inline OutputIterator partial_sum(
|
||||||
|
const SinglePassRange& rng,
|
||||||
|
OutputIterator result,
|
||||||
BinaryOperation op)
|
BinaryOperation op)
|
||||||
{
|
{
|
||||||
BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange> ));
|
BOOST_RANGE_CONCEPT_ASSERT((
|
||||||
|
SinglePassRangeConcept<const SinglePassRange>));
|
||||||
|
|
||||||
return std::partial_sum(boost::begin(rng), boost::end(rng), result, op);
|
return std::partial_sum(boost::begin(rng), boost::end(rng), result, op);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class SinglePassRange, class OutputIterator>
|
template<class SinglePassRange, class OutputIterator>
|
||||||
inline OutputIterator adjacent_difference ( const SinglePassRange& rng,
|
inline OutputIterator adjacent_difference(
|
||||||
|
const SinglePassRange& rng,
|
||||||
OutputIterator result)
|
OutputIterator result)
|
||||||
{
|
{
|
||||||
BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange> ));
|
BOOST_RANGE_CONCEPT_ASSERT((
|
||||||
|
SinglePassRangeConcept<const SinglePassRange>));
|
||||||
|
|
||||||
return std::adjacent_difference(boost::begin(rng), boost::end(rng),
|
return std::adjacent_difference(boost::begin(rng), boost::end(rng),
|
||||||
result);
|
result);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class SinglePassRange, class OutputIterator, class BinaryOperation>
|
template<class SinglePassRange, class OutputIterator, class BinaryOperation>
|
||||||
inline OutputIterator adjacent_difference ( const SinglePassRange& rng,
|
inline OutputIterator adjacent_difference(
|
||||||
|
const SinglePassRange& rng,
|
||||||
OutputIterator result,
|
OutputIterator result,
|
||||||
BinaryOperation op)
|
BinaryOperation op)
|
||||||
{
|
{
|
||||||
BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<SinglePassRange> ));
|
BOOST_RANGE_CONCEPT_ASSERT((
|
||||||
|
SinglePassRangeConcept<const SinglePassRange>));
|
||||||
|
|
||||||
return std::adjacent_difference(boost::begin(rng), boost::end(rng),
|
return std::adjacent_difference(boost::begin(rng), boost::end(rng),
|
||||||
result, op);
|
result, op);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace boost
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user