AMDG Surya Kiran Gullapalli wrote:
I've a class with multiple boost signals like this
class A { private: boost::signal
m_voidSignal ; boost::signal m_stringSignal ; public: boost::signal & voidSignal() { return m_voidSignal ; } boost::signal & stringSignal { return m_stringSignal ; } } ; when i'm connecting signals to slots, I do some thing like this.
A a; a.voidSignal().connect (...) ;
This works fine. But I've many signals with different signatures. what I want to achieve is a single interface where I want to map every signal to enums and access signal from the enums like this.
class A { public: typedef enum { VoidSignal, StringSignal ... } ; SignalIds ;
// return type should be deducted automatically from the enum ReturnType& getSignal (SignalId) ; ... } ;
So that I can do some thing like this
A a; a.getSignal (A::VoidSignal).connect (...) ; a.getSignal (A::StringSignal).connect (...) ;
Basically with a single interface, I want to change the return type automatically. Can I achieve something like this with any of the boost libraries (mpl, fusion etc) ? Any pointers on this would be of great help.
You can't make the return type change based on a runtime condition. The best that you can do with a runtime id is: template<class Args...> void A::connect(SignalIds id, const Args& args...) { switch(id) { case VoidSignal: m_voidSignal.connect(args...); break; case StringSignal: m_stringSignal.connect(args...); break; } } If you can use compile time constants instead of runtime values, you can use indices into a fusion::vector. In Christ, Steven Watanabe