Skip to content

Instantly share code, notes, and snippets.

@fabiogaluppo
Created December 7, 2015 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabiogaluppo/8a92d515241d0edb6b9a to your computer and use it in GitHub Desktop.
Save fabiogaluppo/8a92d515241d0edb6b9a to your computer and use it in GitHub Desktop.
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