[ptr_container] No insert(it, [key, ]value) in associative pointer container?
Hi, I'd like to know why there's no method 'insert' that mimicks stl's associative container's insert method that accepts an iterator that points to where the value could be placed, and the value? Regards, rod
Rodolfo Lima skrev:
Hi, I'd like to know why there's no method 'insert' that mimicks stl's associative container's insert method that accepts an iterator that points to where the value could be placed, and the value?
Regards, rod
Was it ptr_map you got this problem with? For some reason I forgot to add the overloads to ptr_map, but not to ptr_set. Thanks -Thorsten
Thorsten Ottosen skrev:
Rodolfo Lima skrev:
Hi, I'd like to know why there's no method 'insert' that mimicks stl's associative container's insert method that accepts an iterator that points to where the value could be placed, and the value?
Regards, rod
Was it ptr_map you got this problem with? For some reason I forgot to add the overloads to ptr_map, but not to ptr_set.
The problem is that there is no exception-safe way to pass around pair<key,T*>. The only alternative would be to add iterator insert( iterator, ref_pair<key,T*> ). such that we can insert an element from another ptr_map. Would this be satisfactory? -Thorsten
Thorsten Ottosen escreveu:
iterator insert( iterator, ref_pair<key,T*> ).
such that we can insert an element from another ptr_map.
Would this be satisfactory?
Hi, I was thinking of something along the lines of iterator insert(iterator, const key_type &key, std::auto_ptr<T> ptr); and iterator insert(iterator, const key_type &key, mapped_type val); to mimic the insert overload that doesn't take the iterator. And while you're at it, I've noticed that the member std::pair<iterator,bool> ptr_map_adapter::iterator(key_type &key, mapped_type x) takes the key as a non-const reference, is there a reason for that? Thanks and congratulations for the great library, Rodolfo Lima
Rodolfo Lima skrev:
Thorsten Ottosen escreveu:
iterator insert( iterator, ref_pair<key,T*> ).
such that we can insert an element from another ptr_map.
Would this be satisfactory?
Hi, I was thinking of something along the lines of
iterator insert(iterator, const key_type &key, std::auto_ptr<T> ptr);
and
iterator insert(iterator, const key_type &key, mapped_type val);
to mimic the insert overload that doesn't take the iterator.
Ok. I'll add those.
And while you're at it, I've noticed that the member std::pair<iterator,bool> ptr_map_adapter::iterator(key_type &key, mapped_type x)
takes the key as a non-const reference, is there a reason for that?
Yes. It provides stronger exception-safety guarantees (though not bullet-proof) since then creating a key must be done in a seperate statement. -Thorsten
participants (2)
-
Rodolfo Lima
-
Thorsten Ottosen