|
|
Le 21/11/2013 20:57, Orchid Win7 v1 nous fit lire :
> "What's wrong with using vector.front()?"
> But this code... this crazy code seems to be *assuming* that all the
> elements always just happen to be perfectly contiguous in memory.
>
all is in the specification... C++, but which version ?
For instance, [] on std::string is unspecified for complexity in C++98.
In C++11, it is constant in complexity.
which mean a loop with an index to access all element of a string is:
* dangerous in C++98, for performance
* fine in C++11.
From specification of std::vector, the elements are contiguous in term
of storage.
> I'm still trying to figure out whether this audacious assumption about
> the internal behaviour of a library class is more or less evil than just
> trying to do manual memory management correctly...
There is the concepts... vector, string, map...
and there is the specifications.
your best friend is www.cplusplus.com/reference, and the search box.
>
> Manual memory management? Pretty evil.
>
> Relying on internal library implementation details? Pretty evil.
If if remains unspecified, it is evil, but READ THE SPECS!
>
> Maybe the set of coding evilness is only partially ordered...
Post a reply to this message
|
|