Skip to content

Instantly share code, notes, and snippets.

@yoya
Created November 1, 2018 14:51
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 yoya/17232e758df7a567f79d526fbce3824c to your computer and use it in GitHub Desktop.
Save yoya/17232e758df7a567f79d526fbce3824c to your computer and use it in GitHub Desktop.
iterator_test.cpp (take3 OK!)
// g++ -std=c++11 iterator_test.cpp
#include <iostream>
#include <vector>
#include <algorithm>
class my_vector {
public:
std::vector<int> m_vec;
my_vector(int len, int value): m_vec(len, value) { ; }
std::vector<int>::const_iterator begin() const { return m_vec.begin(); }
std::vector<int>::const_iterator end() const { return m_vec.end(); }
std::vector<int>::iterator begin() { return m_vec.begin(); }
std::vector<int>::iterator end() { return m_vec.end(); }
};
int main(void) {
const my_vector v1(10, 255);
my_vector v2(10, 0);
std::transform(v1.begin(), v1.end(), v2.begin(),
[](float val) { return val/10; });
for (int n : v2.m_vec) {
std::cout << n << ' ';
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment