[ptr_container] more operators?

Thorsten, So we're going to have comparison operators in ptr_container, despite possible polymorphism-related errors. Let me show you some problems with them: e.g. class Base{}; class Derived : public Base {}; bool operator == (const Base &, const Base &); //Handles correctly Base and Derived //then user add class DerivedAgain : public Derived {}; and forget update operator == then all operations == on DerivedAgain objects will use Derived operator ==. And AFAIK user just can't automate reminder about forgotten operator == without registering DerivedAgain somewhere, so all DerivedAgain wrong comparasions will get green light. And I do believe it's undesirable behavior. My vision of the problem: provide all comparison operators, but with compile-time checking that ensures user defined specialization of some traits class: template<> struct has_proper_polymorphic_equal_operator<Base> { enum { value = true; } }; while by default has_proper_polymorphic_equal_operator<T>::value returns false. Second if you provide comparasion operators (with concept checking or not) it's quite strange that ptr_containers aren't CopyConstructible and Assignable. Using the same technique we can provide them: template<> struct is_clonable<Base> { enum { value = true }; }; template<> struct clone<Base> { Base * do_clone(Base * pb) { return pb->CloneMe(pb); //or any other name } }; And I believe that operator = is much needed than comparison operators in real-life applications. So what do you think? P.S. What do you think about my post Proposal: is_swapable, is_nothrow_swapable, nothrow_swap,swap dated 04/12? -- Pavel Chikulaev

"Pavel Chikulaev" <pavel.chikulaev@gmail.com> wrote in message news:d48duh$7oj$1@sea.gmane.org... | Thorsten, | | So we're going to have comparison operators in ptr_container, despite | possible polymorphism-related errors. | Let me show you some problems with them: | e.g. | class Base{}; | class Derived : public Base {}; | bool operator == (const Base &, const Base &); //Handles correctly Base | and Derived | //then user add | class DerivedAgain : public Derived {}; | and forget update operator == | | then all operations == on DerivedAgain objects will use Derived operator ==. | And AFAIK user just can't automate reminder about forgotten operator == | without registering DerivedAgain somewhere, so all DerivedAgain | wrong comparasions will get green light. And I do believe it's undesirable | behavior. base::operator==(...) should delegate to a protected or public function. | Second if you provide comparasion operators (with concept checking or not) | it's quite strange that ptr_containers aren't CopyConstructible and Assignable. not at all. copying by cloning is vastly different from copying; so different that those two things should not be interchangeable. | P.S. What do you think about my post | Proposal: is_swapable, is_nothrow_swapable, nothrow_swap,swap dated | 04/12? I looked briefly at it; I recall to think that it was not worth the effort. I talked with Howard Hinnant about the issue and I think we concluded that the introduction of move-semantics and changes to the standard algorithms would allow us to write a proxy reference for the iterators in pointer containers so we can call sort() etc. in the usual manner. -Thorsten

"Thorsten Ottosen" <nesotto@cs.auc.dk> wrote in message news:d48kcf$ta$1@sea.gmane.org...
base::operator==(...) should delegate to a protected or public function. That won't solve the problem.
| Second if you provide comparasion operators (with concept checking or not) | it's quite strange that ptr_containers aren't CopyConstructible and Assignable.
not at all. copying by cloning is vastly different from copying; so different that those two things should not be interchangeable.
I know. But how else could polymorphic objects to be copied correctly?
I looked briefly at it; I recall to think that it was not worth the effort. I don't think so, but ok.
I talked with Howard Hinnant about the issue and I think we concluded that the introduction of move-semantics and changes to the standard algorithms would allow us to write a proxy reference for the iterators in pointer containers so we can call sort() etc. in the usual manner. I'm really like it. but when? right now we should use em as members anyway.
-- Pavel Chikulaev

"Pavel Chikulaev" <pavel.chikulaev@gmail.com> wrote in message news:d48n9s$b75$1@sea.gmane.org... | "Thorsten Ottosen" <nesotto@cs.auc.dk> wrote in message | news:d48kcf$ta$1@sea.gmane.org... | > base::operator==(...) should delegate to a protected or public function. | That won't solve the problem. | > | > | Second if you provide comparasion operators (with concept checking or not) | > | it's quite strange that ptr_containers aren't CopyConstructible and | > Assignable. | > | > not at all. copying by cloning is vastly different from copying; so different | > that those | > two things should not be interchangeable. | | I know. But how else could polymorphic objects to be copied correctly? not understood. | > I looked briefly at it; I recall to think that it was not worth the | > effort. | I don't think so, but ok. | | > I talked with Howard Hinnant about the issue and I think we concluded that | > the introduction of move-semantics and changes to the standard algorithms | > would | > allow us to write a proxy reference for the iterators in pointer containers so | > we can call | > sort() etc. in the usual manner. | I'm really like it. | but when? C++0x. | right now we should use em as members anyway. yes. -Thorsten
participants (2)
-
Pavel Chikulaev
-
Thorsten Ottosen