3 ms·
I feel the first example for ranges is a bit contrived, most people would end up with something more like: void get_ids_adult_users(const std::vector<user_t>
by another2another 4y ago
I feel the first example for ranges is a bit contrived, most people would end up with something more like:
void get_ids_adult_users(const std::vector<user_t>& allUsers, std::vector<int>& adultUsers)
{
for (const user_t& user: allUsers) {
if (user.age >= 18) {
adultUsers.push_back(user.age);
}
}
}
probably after calling reserve() on the adultUsers vector to avoid resizing.