Re: Hidden Features and Dark Corners of STL?
On Oct 21, 8:38 pm, Juha Nieminen <nos...@thanks.invalid> wrote:
puzzlecracker wrote:
What do you think about these dark corners of stl? which
ones would you add?
You wouldn't believe how many C++ programmers don't know this
simple trick, even though it's rather obvious when you know
how iterators and how initializing a container with an
iterator range work.
int main(int argc, char* argv[])
{
std::vector<std::string> params(argv, argv+argc);
// Now all the command-line parameters are in the 'params' vector
}
In fact, I have seen quite some C++ programs out there which
don't take advantage of initializing (or assigning) containers
with iterator ranges even tough they could. It seems that many
C++ programmers simply haven't understood the usefulness of
this simple thing.
One of the reasons might be that it's still not portable. Some
older implementations of the standard library (like the one
delivered with Sun CC) still don't use template members,
although the compiler supports them. So you find yourself
having to write:
std::vector<std::string> args;
std::copy( argv, argv + argc, std::back_inserter( args ) );
--
James Kanze