previously that was std::string::c_str()
's job, but as of c++11, data()
also provides it, why was c_str()'s null-terminating-character added to std::string::data()
? to me it seems like a waste of CPU cycles, in cases where the null-terminating-character is not relevant at all and only data() is used, a c++03 compiler doesn't have to care about the terminator, and don't have to write 0 to the terminator every time the string is resized, but a c++11 compiler, because of the data()
-null-guarantee, have to waste cycles writing 0 every time the string is resized, so since it potentially makes code slower, I guess they had some reason to add that guarantee, what was it?
mardi 2 juillet 2019
why did c++11 make std::string::data() add a null terminating character?
Inscription à :
Publier les commentaires (Atom)
Aucun commentaire:
Enregistrer un commentaire