Commit 2b4b07ca authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Add more convenience helpers for applying algorithms to a range

GnuPG-bug-id: 6115
parent 2fa5e706
......@@ -78,6 +78,37 @@ bool contains_if(const Container &container, UnaryPredicate p)
return std::find_if(std::begin(container), std::end(container), p) != std::end(container);
}
/**
* Convenience helper for copying elements of @p range.
* Use std::ranges::copy_if() instead if you can use C++20.
*/
template<typename InputRange, typename OutputIterator, typename UnaryPredicate>
OutputIterator copy(InputRange &&range, OutputIterator result)
{
return std::copy(std::begin(range), std::end(range), result);
}
/**
* Convenience helper for copying elements of @p range for which predicate @p p
* returns @c true.
* Use std::ranges::copy_if() instead if you can use C++20.
*/
template<typename InputRange, typename OutputIterator, typename UnaryPredicate>
OutputIterator copy_if(InputRange &&range, OutputIterator result, UnaryPredicate p)
{
return std::copy_if(std::begin(range), std::end(range), result, p);
}
/**
* Convenience helper for transforming the elements of @p range.
* Use std::ranges::transform() instead if you can use C++20.
*/
template<typename InputRange, typename OutputIterator, typename UnaryOperation>
OutputIterator transform(InputRange &&range, OutputIterator result, UnaryOperation op)
{
return std::transform(std::begin(range), std::end(range), result, op);
}
/**
* Convenience helper for removing elements from a vector @p v for which
* predicate @p p returns @c true.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment