4 ms·
I'm a C++ expert, but I've never touched std::for_each, for example. (I could learn it in about two minutes if it became necessary to know, but it hasn't ever
by sillysaurus3 13y ago
I'm a C++ expert, but I've never touched std::for_each, for example. (I could learn it in about two minutes if it became necessary to know, but it hasn't ever been.)
In general, #include <algorithm> is a bit worrisome, because it usually indicates someone is trying to be overly clever with C++. On the other hand, if the codebase is written in that style, then the whole codebase should be consistently written in that style. The inconsistency is the worrisome part: either use it everywhere or nowhere.
Anyway, STL is pretty massive, and knowing all of it isn't the same thing as being a C++ expert. Knowing what to avoid is almost as important as knowing what to use.
- jcd748 13y agoYou probably don't need std::for_each anymore. With C++11, you can do the following: for (const auto& element : collection) { } What's wrong with <algorithm>? I use it all the time for sort, swap, and random_shuffle comes up more frequently than I expect.
- sillysaurus3 13y agoThose are all fine. Actually, I forgot that sort was in <algorithm>. I was just recalling some of the horrors I've seen due to pre-C++11 fanciness. There seems to be a temptation for C++ programmers to overuse clever tricks. Luckily, with C++11 fewer tricks are necessary. Unfortunately, the gamedev industry will probably be stuck with pre-C++11 for another decade.
- emmelaich 13y ago> I'm a C++ expert .. > I forgot that sort was in <algorithm> Uhm, sillysaurus3, could I see you in my office please. :-)
- sillysaurus3 13y agoMy brain space is limited, so I use it sparingly. Memorizing which header file provides which function is something I've left out. That's what IDEs and Google are for. ;)
- ryandrake 13y agoWhen I used to do C++ interviews more often, and I encountered someone who believed themself to be a "C++ expert" I'd sometimes pull up: http://en.cppreference.com/w/cpp/header http://en.cppreference.com/w/cpp/header and ask the candidate to pick three headers from the standard library that they found interesting and tell me about their contents, how they can be used, what the pitfalls are, etc. If they get a mild panicked look in their eyes and go straight for string, vector, and iostream, my spidey-sense starts tingling..... EDITed for grammar
- sillysaurus3 13y agoReading those headers are fun! That's a genius idea.