C++ (Qt)void traverse(vector<int> v, bool reverse){ auto it = reverse ? v.crbegin() : v.cbegin(); auto end = reverse ? v.crend() : v.cend(); while (it != end) { auto n = *it++; ... }}
C++ (Qt)void traverse(vector<int> v, bool reverse){ auto vv = v; if (reverse) std::reverse(vv.cbegin(), vv.cend()); for (auto n : vv) { ... }}
C++ (Qt)for (size_t i = 0; i < vec.size(); ++i) { size_t index = reverse ? (vec.size() - i - 1) : i; vec[index] = ...}
C++ (Qt)auto itF = vec.begin();auto itB = vec.rbegin(); whle (true) { if (!reverse && itF == vec.end()) break; if (reverse && itB == vec.rend()) break; auto & val = reverse ? (*itB++) : (*itF++); ...}
C++ (Qt)template<typename Container, typename Func>void func( Container c, Func func, bool reverse ){ if( reverse ) for_each( c.crbegin(), c.crend(), func ); else for_each( c.cbegin(), c.cend(), func );} int main( int, char *[] ){ vector<int> data { 10, 20, 30, 40, 50 }; func( data, [=]( int v ){ cerr << v << endl; }, false ); return 0;}
C++ (Qt) auto vv = v;