In C++11 array, dynarray, string, and vector all got the data method which:
Returns pointer to the underlying array serving as element storage. The pointer is such that range [
data();data() + size()) is always a valid range, even if the container is empty. [Source]
This method is provided in a mutable and const version for all applicable containers, for example:
T* vector<T>::data();
const T* vector<T>::data() const;
All applicable containers, that is, except string which [only provides theconstversion][1]:
const char* string::data() const;
What happened here? Why did string get shortchanged, when char* string::data() would be so helpful?
Aucun commentaire:
Enregistrer un commentaire