What is the fundamental difference, if any, between a C++ std::vector and std::basic_string?
basic_string gives compiler and standard library implementations, a few freedoms over vector:
The "small string optimization" is valid on strings, which allows implementations to store the actual string, rather than a pointer to the string, in the string object when the string is short. Something along the lines of:
class string
{
size_t length;
union
{
char * usedWhenStringIsLong;
char usedWhenStringIsShort[sizeof(char*)];
};
};
In C++03, the underlying array need not be contiguous. Implementing basic_string in terms of something like a "rope" would be possible under the current standard. (Though nobody does this because that would make the members std::basic_string::c_str() and std::basic_string::data() too expensive to implement.)
C++11 now bans this behavior though.
In C++03, basic_string allows the compiler/library vendor to use copy-on-write for the data (which can save on copies), which is not allowed for std::vector. In practice, this used to be a lot more common, but it's less common nowadays because of the impact it has upon multithreading. Either way though, your code cannot rely on whether or not std::basic_string is implemented using COW.
C++11 again now bans this behavior.
There are a few helper methods tacked on to basic_string as well, but most are simple and of course could easily be implemented on top of vector.