C++11/14 idioms I use every day
От: flаt  
Дата: 19.08.14 11:49
Оценка:
http://seshbot.com/blog/2014/08/16/modern-c-plus-plus-idioms-i-use-every-day/

Возник вопрос по

the proposal for enhanced ranged-based for syntax to prevent accidental misuse (currently the recommended syntax is actuall for (auto && x : xs), but this will allow us to use for (x : xs))


Почему (точнее, для чего) в range-based for нужна RV-ссылка, а не обычная? В каких случаях это может потребоваться?

ЗЫ: https://github.com/ryanhaining/cppitertools/ — классная штука:

for (auto i : range(10)) {
    cout << i << '\n';
}
vector<int> vec{2, 4, 6, 8};
for (auto e : enumerate(vec)) { 
    cout << e.index
         << ": "
         << e.element
         << '\n';
}
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.