[ptr_container] ptr_multimap insert and transfer functions
Hello, All! I have a couple of questions about ptr_container library. Specificaly 1) Why ptr_multimap_adapter::insert has non const key_type argument? 2) Why ptr_multimap_adapter::transfer( iterator object, ptr_multimap_adapter& from ) has void return type instead of iterator? PS I use 1.33.1 but this is true for 1.34 too. With best regards, Konstantin Litvinenko.
Konstantin Litvinenko wrote:
Hello, All!
I have a couple of questions about ptr_container library. Specificaly
1) Why ptr_multimap_adapter::insert has non const key_type argument?
This is due to exception-safety concerns. If the construction of the key can throw, the heap allocated object can throw.
2) Why ptr_multimap_adapter::transfer( iterator object, ptr_multimap_adapter& from ) has void return type instead of iterator?
Why do you think it should return an iterator? -Thorsten
Hello, Thorsten! You wrote on Thu, 01 Jun 2006 18:49:17 +0200: KL>> 2) Why ptr_multimap_adapter::transfer( iterator object, KL>> ptr_multimap_adapter& from ) has void return type instead of iterator? TO> Why do you think it should return an iterator? ptr_multimap<std::string, int> a1; ptr_multimap<std::string, int> a2; typedef ptr_multimap<std::string, int>::iterator iterator; a1.insert("a", 1); a1.insert("a", 2); a2.insert("a", 1); a2.insert("a", 2); iterator i = a1.insert("a", 3); iterator r = a2.transfer(i, a1); /// Will not work return r; How can I do this with current interface in a simple way? With best regards, Konstantin Litvinenko
Konstantin Litvinenko wrote:
Hello, Thorsten! You wrote on Thu, 01 Jun 2006 18:49:17 +0200:
KL>> 2) Why ptr_multimap_adapter::transfer( iterator object, KL>> ptr_multimap_adapter& from ) has void return type instead of iterator?
TO> Why do you think it should return an iterator?
ptr_multimap<std::string, int> a1; ptr_multimap<std::string, int> a2; typedef ptr_multimap<std::string, int>::iterator iterator;
a1.insert("a", 1); a1.insert("a", 2); a2.insert("a", 1); a2.insert("a", 2);
iterator i = a1.insert("a", 3); iterator r = a2.transfer(i, a1); /// Will not work return r;
I see. The return value has been a little different than the usual ones. For example, insert() in ptr_set<> returns bool.
How can I do this with current interface in a simple way?
I'm afraid there is no simple way to do it. If you're not afraid of using the main cvs, I can update that. Do you agree that for ptr_set/ptr_map the return value should be single object transfer: std::pair<iterator,size_type> multi object transfer: std::pair<iterator,size_type> and for ptr_multiset/ptr_multimap the return value should be the same too? I'm not saying this is the only options. Just a suggestion. -Thorsten
Hello, Thorsten! You wrote on Wed, 07 Jun 2006 00:58:55 +0200: TO> If you're not afraid of using the main cvs, I can update that. I use 1.33.1 and can't switch to main trunc. TO> Do you agree that for ptr_set/ptr_map the return value should be TO> single object transfer: std::pair<iterator,size_type> Why not std::pair<iterator,bool> as std::set/std::map return? TO> multi object transfer: std::pair<iterator,size_type> May be only size_type? TO> and for ptr_multiset/ptr_multimap the return value should be the same TO> too? I think for these two should be single object transfer: iterator // this operation always insert key/value pair multi object transfer: void // this operation always insert all key/value pairs With best regards, Konstantin Litvinenko.
Konstantin Litvinenko wrote:
Hello, Thorsten! You wrote on Wed, 07 Jun 2006 00:58:55 +0200:
TO> If you're not afraid of using the main cvs, I can update that.
I use 1.33.1 and can't switch to main trunc.
TO> Do you agree that for ptr_set/ptr_map the return value should be TO> single object transfer: std::pair<iterator,size_type>
Why not std::pair<iterator,bool> as std::set/std::map return?
TO> multi object transfer: std::pair<iterator,size_type>
May be only size_type?
Why do you need the iterator for single element transfer, but not for multi element transfer?
TO> and for ptr_multiset/ptr_multimap the return value should be the same TO> too?
I think for these two should be
single object transfer: iterator // this operation always insert key/value pair multi object transfer: void // this operation always insert all key/value pairs
I have come to dislike variations in return-type, even for different containers. It makes them less interchangeable. Do you disagree? -Thorsten
Hello, Thorsten! You wrote on Thu, 08 Jun 2006 23:57:32 +0200: TO>>> Do you agree that for ptr_set/ptr_map the return value should be TO>>> single object transfer: std::pair<iterator,size_type> KL>> KL>> Why not std::pair<iterator,bool> as std::set/std::map return? KL>> TO>>> multi object transfer: std::pair<iterator,size_type> KL>> KL>> May be only size_type? TO> Why do you need the iterator for single element transfer, but not for TO> multi element transfer? Because I don't know what to do with returned iterator for multi object transfer. Where this iterator will be pointed to? On first inserted element? Last? I think we need an usecase. KL>> KL>> I think for these two should be KL>> KL>> single object transfer: iterator // this operation always KL>> insert key/value pair multi object transfer: void // this KL>> operation always insert all key/value pairs TO> I have come to dislike variations in return-type, even for different TO> containers. It makes them less interchangeable. Do you disagree? Yes, I disagree :) Never seen easy way to change map on set or multimap on multiset. Such changes always require more modification than just replacing container type. std::set.insert(key) return pair std::set.insert(first, last) return void std::multiset.insert(key) return iterator std::multiset.insert(first, last) return void Why not to do the same, exept fo (first, last) return size to indicate how many insertion happens? With best regards, Konstantin Litvinenko.
Konstantin Litvinenko wrote:
iterator i = a1.insert("a", 3); iterator r = a2.transfer(i, a1); /// Will not work return r;
How can I do this with current interface in a simple way?
A hack could be iterator r = a2.insert( "a", a1.release(i).release() ); -Thorsten
Hello, Thorsten! You wrote on Wed, 07 Jun 2006 16:00:21 +0200: TO> Konstantin Litvinenko wrote: KL>> iterator i = a1.insert("a", 3); KL>> iterator r = a2.transfer(i, a1); /// Will not work KL>> return r; KL>> KL>> How can I do this with current interface in a simple way? TO> A hack could be TO> iterator r = a2.insert( "a", a1.release(i).release() ); Hmm, interesting... But you know, this is a HACK ;) Can we change interface into more logical form, according to you proposal and my comments? With best regards, Konstantin Litvinenko.
participants (2)
-
Konstantin Litvinenko
-
Thorsten Ottosen