3 ms·
Auto everywhere is pretty dangerous despite what Mr. Sutter says. Many C++ libraries rely on type conversion (in high performance math it's very common however
by pandaman 15y ago
Auto everywhere is pretty dangerous despite what Mr. Sutter says. Many C++ libraries rely on type conversion (in high performance math it's very common however you can find it as close as the STL's vector<bool>).
Whenever you use your own memory allocator and/or care about performance (and this is whenever you are writing high performance/high reliability code) library smart pointers are pretty useless too.
Other things are not as controversial as these two, but don't really define the modern C++. Herb should have read his friend's, Anderi Alexandrescu's, book from ten years ago to get a hint of what modern C++ looks like :)
(I know he has read it. I guess he is just trying to pimp C++ to Java/PHP/Python/etc developers).
- phaedrus 15y agoHe's not advocating "auto everywhere", he just said it will make the STL algorithms easier to use (which it will). The other benefit of auto is for generic code (code in templates) where you might not necessarily know what the return type is, or at least where the return type is going to be very complicated to specify. (This last is the same reason C# added var at the same time as they added LINQ - the return types of LINQ expressions would be difficult to specify manually.)
- pandaman 15y agoHe says "Use C++11 auto wherever possible." Nobody argues auto and decltype is necessary for generic code but this not what Sutter's writing about. In fact he does not have a single word like "generic" or "template" in his entire article. Which alone should be a good indication this has nothing to do with the modern C++ style unlike Alexandrescu's book with the similar name.