Skip to content

Instantly share code, notes, and snippets.

@mtao
Last active August 29, 2015 14:10
Show Gist options
  • Save mtao/ad2cfe409846c0605bb6 to your computer and use it in GitHub Desktop.
Save mtao/ad2cfe409846c0605bb6 to your computer and use it in GitHub Desktop.
#include <vector>
#include <algorithm>
#include <iterator>
#include <iostream>
int main(int argc, char* argv[]) {
std::vector<int> indices(1e6);
/*
std::transform(indices.begin(),indices.end(), indices.begin(), [&indices](int& v) -> int {
return std::distance(indices.data(),&v);
});
*/
/*
std::for_each(indices.begin(),indices.end(), [&indices](int& v) {
v = std::distance(indices.data(),&v);
});
*/
std::iota(indices.begin(),indices.end(),0);
for(auto&& v: indices) {
std::cout << v << " ";
}
std::cout << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment