Skip to content

Instantly share code, notes, and snippets.

@thiagomg
Last active August 29, 2015 14:20
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 thiagomg/42f0b8632dbbb8484953 to your computer and use it in GitHub Desktop.
Save thiagomg/42f0b8632dbbb8484953 to your computer and use it in GitHub Desktop.
Do macro ao template
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