How are std::begin() and std::end() useful? I can't imagine a scenario where passing an object to a generic function that does nothing but call one of its methods is preferable to just calling that method directly, unless the function is a friend of the object and the method is private, but if the method is private, you shouldn't be calling it anyway In both cases you need to have access to the object, so I don't see how it could ever be useful.
^ This. Finally in C++ we have a generic way to get the beginning and end iterator on all iterable containers (besides naked pointers to the first element in a dynamic array, of course).
Framework wrote:
Err... no.
Are you sure? This looks pretty obfuscated to me:
1 2 3 4
for(std::set<SomeType::ThatType>::const_iterator it = mycontainer.begin(); it != mycontainer.end(); ++it)
{
*it += blah;
}
Whereas this looks obvious:
1 2 3 4
for(auto &v : mycontainer)
{
v += blah;
}
Framework wrote:
Do you see any sarcasm tags in my last reply?
No, but what you said was very seriously making me think you were being sarcastic. I've never seen the lazy-programmer argument used seriously before.
Framework wrote:
I disagree. Not once have I ever deemed their use valuable.
^ This. No more hackery, tracking size, adding pointers, or other crap. And the array can be swapped out for an STL container without changing any other code.
You also have said you haven't ever used much of the STL...
So how would you know if something is useful if you have never really used it? But that is all I will say don't want to be baited into another troll argument.
std::vector and std::map are used for almost everything, you use std::cout and std::cin for I/O, then there's std::ifstream and std::ofstream for files, you have to use std::istringstream and std::ostringstream for converting strings and numbers (or the new functions introduced in C++11), and don't forget std::string and std::sort. That's ten things I use all the time - please don't tell me you don't see a use for them.
And I have to repeat what I think chrisname already said, introducing a new keyword such as foreach would've been the better thing to do, as opposed to recycling for and giving it a new syntax.
Adding a 'foreach' keyword would have broken a lot of code (people implementing their own foreach)
Edit: also, how would not using auto make it look more obvious?