Created
August 12, 2016 20:39
-
-
Save simmplecoder/de89a88e496a697cd2f8f7ec846ed49d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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