Return a mutable char* pointing to a string's internal buffer, which may not be null-terminated. Writing through this pointer will modify the string. string_as_array(&str)[i] is valid for 0 <= i < str.size() until the next call to a string method that invalidates iterators. Prior to C++11, there was no standard-blessed way of getting a mutable reference to a string's internal buffer. The require
| 348 | // According to Matt Austern, this should already work on all current C++98 |
| 349 | // implementations. |
| 350 | inline char* string_as_array(string* str) { |
| 351 | // DO NOT USE const_cast<char*>(str->data())! See the unittest for why. |
| 352 | return str->empty() ? NULL : &*str->begin(); |
| 353 | } |
| 354 | |
| 355 | // These are methods that test two hash maps/sets for equality. These exist |
| 356 | // because the == operator in the STL can return false when the maps/sets |
no test coverage detected