|
|
|
|
|
by mehrdadn
2527 days ago
|
|
With begin()/end() it's probably fine, but for-each loops it's not a great idea since then you run into problems when there was a cast intended. The main (only?) example of this pattern in the standard is vector<bool>, so of course people's immediate reaction to blame this on vector<bool>. However that's just the example currently in the standard, and people use it for other things too. By using auto you end up writing code that can break. Example: typedef std::vector<bool> Vec;
Vec f(1, false);
for (typename Vec::value_type &&x : f) { std::cout << typeid(x).name() << std::endl; }
for (auto &&x : f) { std::cout << typeid(x).name() << std::endl; }
|
|