3 ms·
Good points. Also, first paragraph says C++11 (too be honest, C++11 mode) yet first example has std::vector< std::vector <int> >::const_iterator. Where's auto,
by stinos 12y ago
Good points. Also, first paragraph says C++11 (too be honest, C++11 mode) yet first example has std::vector< std::vector <int> >::const_iterator. Where's auto, cbegin/cend ?
In short: none of the C++ code written in the article resembles what a well-trained, well-behaved C++ programmer uses. And the same cannot be said of the Rust code, I think.
On the other hand: maybe the whole point of the article is something like 'you don't have to be super well-trained in Rust yet won't shoot yourself in the foot'.
- wfunction 12y agoYou really think auto and cbegin/cend make any difference here?
- verroq 12y agoC++ programmers generally know the iterator invalidation rules though.
- stinos 12y agoCompilation-wise: of course not. As an illustration of what is wrong with the code: yes. auto means you don't have to spell out the complete iterator definition. cbegin\cend is just a matter of const-correctness.
- jason_dstillery 12y agoYes, auto will save you: std::vector<bool> features(const Widget& w); ... auto highPriority = features(w)[5]; processWidget(w, highPriority); //whoops, undefined behavior This is from Scott Meyers' new Effective Modern C++, in the chapter about why you should use 'auto'. Even the new 'safe' and 'convenient' features are loaded footguns.