Date: Fri, 25 Nov 2022 18:33:55 +0400
Hello Frederick,Let me summarize your problem and the solutions proposed from other members so far.So you have a set of derived classes, sharing at least one base class.Given this, you want to apply a set of operations on these derived classes, using a pointer to the most common base class.(polymorphism)But some of these operations diverge when you climb up the inheritance tree closer to the leaf object, which is the derived class it self.So your goal is to be, at the same time, agnostic to the set of base classes of each derived class, but also be specific when calling certain operation.Well, to be agnostic to the type you are using, is called "type erasure", and std::variant, is an implementation of type erasure.The problem with std::variant is that all the member variants should share the set of the called member functions, at std::visit call site, otherwise it won't work.So one solution, as suggested by some, is to write a compile time "if constexpr", switching between either calling or not calling the member function if it exists.But this solution is not practical in case you want to call many member functions, which are not common to the variants type. It will be a forest of "if/else".But one moment, if we go back one step, to analyze the problem.The member functions you want to call are known at compile time, and calling or not calling also can be decided at compile time.So the solution is definitely a template meta-programing technique. Using SFINAE and other artifacts.I have faced the same problem with Qt signals and slots, and I'm using template meta-programing to solve it.But in your PDF, you said you don't want to use template meta-programing , so can I know why?RegardsNadirSent from my Galaxy
-------- Original message --------From: Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]> Date: 11/25/22 2:46 AM (GMT+04:00) To: std-proposals <std-proposals_at_[hidden]> Cc: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]> Subject: [std-proposals] Chimeric Pointer I've written a 2-page PDF file to describe my new idea of chimericpointers. I've tried to attach it to this email, and also you candownload it from my webspace here: http://www.virjacode.com/download/chimeric_pointer.pdfHere's a excerpt from the PDF:"When you apply the ‘->’ operator to a chimeric pointer and then tryto access a member object or a member function, the compiler tries tofind the member in all the base classes"
-------- Original message --------From: Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]> Date: 11/25/22 2:46 AM (GMT+04:00) To: std-proposals <std-proposals_at_[hidden]> Cc: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]> Subject: [std-proposals] Chimeric Pointer I've written a 2-page PDF file to describe my new idea of chimericpointers. I've tried to attach it to this email, and also you candownload it from my webspace here: http://www.virjacode.com/download/chimeric_pointer.pdfHere's a excerpt from the PDF:"When you apply the ‘->’ operator to a chimeric pointer and then tryto access a member object or a member function, the compiler tries tofind the member in all the base classes"
Received on 2022-11-25 14:34:08