Skip to content

Instantly share code, notes, and snippets.

@simmplecoder
Created August 12, 2016 20:39
Show Gist options
  • Save simmplecoder/de89a88e496a697cd2f8f7ec846ed49d to your computer and use it in GitHub Desktop.
Save simmplecoder/de89a88e496a697cd2f8f7ec846ed49d to your computer and use it in GitHub Desktop.
#pragma once
#include <numeric>
namespace impl_details
{
template <typename T, typename UnaryAdvanceOp>
class proxy
{
T value;
UnaryAdvanceOp op;
public:
proxy(T init_value, UnaryAdvanceOp op_) :
value(init_value),
op(op_)
{
}
operator T()
{
return value;
}
T operator++()
{
value = op(value);
return value;
}
T operator++(int)
{
T old = value;
value = op(value);
return old;
}
};
}
template <typename OutputIterator, typename T, typename UnaryAdavanceOp>
void stepping_iota(OutputIterator first, OutputIterator last, T init_value, UnaryAdavanceOp op)
{
impl_details::proxy<T, UnaryAdavanceOp> p(init_value, op);
std::iota(first, last, p);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment