int j = 0; for (list::iterator pos = v.begin(); pos != v.end(); ++pos) { std::next(pos, 1); if (*pos == x) { pos_list.push_back(j); } ++j; }