Instantly share code, notes, and snippets.

Embed
What would you like to do?
template<typename InputIterator, typename T>
void fill_ap(InputIterator first, InputIterator last, T first_term, T common_difference)
{
T n{};
while (first != last)
{
*first = first_term + n * common_difference;
++n;
++first;
}
}
template<typename OutputIterator, typename T>
void unfold_ap(T value, T first_term, T common_difference, OutputIterator result)
{
T n{};
while (value > T{})
{
T x = first_term + n * common_difference;
*result = x;
value -= x;
++n;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment