Hacker News new | past | comments | ask | show | jobs | submit login

That's a good point, but when I think of the typical code for non-range-based for loop it looks like:

    for (vector<string>::iterator i = data.begin(); i != data.end(); ++i) {
        ofile << *i << std::endl;
    
    }
which makes it pretty clear what types we're dealing with.



I think in C++1y we'll be able to define a function 'foreach' that we can use like:

    foreach(data, []<class T>(const T & item) {
        ofile << item << std::endl;
    });
This should eliminate the potential implicit conversion to temp. But I'm not sure it's seriously better than the original range based for with auto.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: