Re: strings and NULL argument passing
Rolf Magnus wrote:
>Which constructor? std::string?
>
Yes. The memory allocation alone would outweigh that simple check by far.
For small strings, there may not even be any dynamic allocation.
>
The problem is that the C++ standard doesn't require it,
I'm not sure that's a "problem." I agree that it would be a good idea
for std::string to detect null initializers, though.
Mabye, but the typical implementor isn't setting out to provide the
"lowest common denominator;" in fact, the opposite tends to be true.
Each implementor typically provides features the others don't, both as a
matter of QoI, and to achieve lock-in.
Rolf Magnus wrote:
Jeff Schwab wrote:
>
>
>James Kanze wrote:
>[snipped code that (oops) initialized a std::string from NULL]
>>On Nov 13, 8:05 pm, Jeff Schwab <j...@schwabcen ter.comwrote:
>>>Rolf Magnus wrote:
>>>>sanjay wrote:
>>>Rolf Magnus wrote:
>>>>sanjay wrote:
>>Compared to the rest of what the constructor has to do, I rather
>>suspect that the run-time cost of checking isn't measurable.
>>suspect that the run-time cost of checking isn't measurable.
Yes. The memory allocation alone would outweigh that simple check by far.
>If the OP's std::string isn't detecting null initializers, the decision
>apparently was made by the implementor that the check was expensive
>enough to avoid.
>apparently was made by the implementor that the check was expensive
>enough to avoid.
The problem is that the C++ standard doesn't require it,
for std::string to detect null initializers, though.
so I guess some
library implementor could think that there is no point in doing such a
check, since the user can't rely on it anyway.
library implementor could think that there is no point in doing such a
check, since the user can't rely on it anyway.
"lowest common denominator;" in fact, the opposite tends to be true.
Each implementor typically provides features the others don't, both as a
matter of QoI, and to achieve lock-in.
Comment