Duane Hebert said:
way.
Any idea why the standard doesn't define std::string spoo(0) to create
an empty string? Seems like a good idea.
For consistency. Constructing a std::string object from a single
integral value invokes the std::basic_string(const Char* p, const
Allocator& a = Allocator()) constructor. This kinda works just like
the C library functions strcpy(), strcat(), strlen(), and so on.
You will find that those C functions do not treat a null pointer as a
null string (some implementation may, but dereferencing a null pointer
yields undefined behaviour). All my favorite C library
implementations signal an error.
Another reason is the pay-for-what-you-use principal. Why should
every string construction have to pay the price of a null-check just
in case?