dimanche 2 juillet 2017

What will this code print on screen?

I need help figuring out why would this code print (8,8) (8,8) (0,8) (7,8) (6,8) (5,8) (4,8) (3,8) (1,8) (0,8) (8,8) on screen. I don't understand how increment and decrement operators work on iterators u and v in function g. I know that set will have elements 0, 1, 3, 4, 5, 6, 7, 8. But I don't understand how "walking" through the set works.

template <typename T> std::complex<double> g(T &u, T &v) { return {*--u, *v++}; }

std::set<int> s{3, 8, 4, 7, 0, 1, 1, 5, 7, 3, 6}; std::set<int>::iterator v(s.begin()), w(s.end()); while(v != w) std::cout << g(v, w) << " "; std::cout << std::endl;

Aucun commentaire:

Enregistrer un commentaire