It seems that the requirements of the C ++ STL container are that the provided dispenser type value_type will be the same as the STL container value_type
Required: allocator_- type :: value_type is the same as X :: value_type.
However, the following code, which uses a row vector, but with a distributor for doubles, works fine on VS 2012 and g ++ 4.4.7. In g ++, valgrind also does not cause errors.
int main() { typedef vector<std::string, std::allocator<double> > StringList; StringList s; for(int i=0; i < 100; i++){ stringstream ss; ss << i; s.push_back(ss.str()); } for(StringList::iterator it = s.begin(); it != s.end(); ++it) { cout << *it << " "; } cout << endl; return 0; }
I am assuming that the dispenser returns internally to the dispenser of the type_type of the container (although maybe I'm wrong).
My question is that I am not reading the C ++ specification correctly, and in fact, all containers will always “reorder” the provided allocator to use the type they need? Or this is just normal practice, but not guaranteed.
In fact, can I count on this “function” that the containers will always take any dispenser that I provide (of any type) and make it work for the value_type of this container?
source share