Last active
August 29, 2015 14:20
-
-
Save thiagomg/42f0b8632dbbb8484953 to your computer and use it in GitHub Desktop.
Do macro ao template
This file contains 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
template<typename T, typename U> | |
void fill2(T &v, U start, U step) { | |
*begin(v) = start; | |
generate(begin(v)+1, end(v), [&start, &step]() { return start += step; }); | |
//alternative - this is not a proper std::fill, but a generate | |
//for(auto &item : v) { | |
// item = start; | |
// start += step; | |
//} | |
} | |
template<typename T> | |
typename T::value_type accum2(T &v) { | |
typename T::value_type ret{}; | |
//auto inside lambda, only in c++14 | |
for_each(begin(v), end(v), [&ret](auto &val) { ret += val; }); | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment