On Dec 13, 2:15 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>
No UB. Insertion in a map _copies_ the object that you
insert. So, even though the 'v' goes away when 'foo' returns,
the copy made by 'sv.insert' stays in the global map, so to
speak (the actual location is determined by the allocator the
map uses for its "values").
Thanks Victor. I also thought it was no UB, but wanted to confirm. So
even something like this would be very legal --
map<string, vector<long m1;
map<string, vector<long::iterator itr;
...
itr = m1.find("xyz");
if (itr != m1.end()) {
vector<longv1 = itr->second;
v1.push_back(8);
}
The above sequence would indeed add 8 in the vector associated with
string "xyz" in map, correct?
Another unrelated question --
stringstream strm;
....
Are strm.str().length() and strlen(strm.c_str()) going to be equal?
Any case in which they might differ?
Thanks again ..