Templates - deducing parameters for type B from type A when one argument is a function pointer

Started by
1 comment, last by a light breeze 5 years ago

#define DSignature									ControlClassType, RegProc, BaseClass      
    template<class ControlClassType, CClassRegProc RegProc, class BaseClass>
    class DSomeObjectBase
        : public DObjectBase<DSignature> { ... }


    template<typename DocType>
    class DPlugin
    	{
        public:
      		virtual ECBool OnLoad(IN MODIFY DocType& document) {
			// !!!!!!!!!!!!!!!!!!!!!!! 
			using DSomeObject = DSomeObjectBase<?!?!?>;
			// !!!!!!!!!!!!!!!!!!!!!!!       
			}
		};
            

What I need to do is extract template arguments from DocType, one whose parameters is a function pointer, and construct a corresponding type DSomeObjectBase<...> using those arguments.

If my template arguments were all typenames or integral types, then this would be fairly easy. However, it seems I'm encountering this limitation, which basically implies that there is no to actually store RegProc in a place which would make it accessible during compile time. Eg, the following won't work:


template<class ControlClassType, CClassRegProc RegProc, class BaseClass>
class DDocument {
	public:  
  		using _A			= ControlClassType;
  		static const _B		= RegProc; //!! ERROR
  		using _C			= BaseClass;
};
  
...  

DSomeObject = DSomeObjectBase<DocType::_A, DocType::_B, DocType::_C>;

What would be the best way to circumvent this? My objective is to minimize the word count and avoid fully templatizing DPlugin.

Advertisement

template<class ControlClassType, CClassRegProc RegProc, class BaseClass>
class DDocument {
	public:  
  		using _A			= ControlClassType;
		static constexpr CClassRegProc _B = RegProc;
  		using _C			= BaseClass;
};

 

This topic is closed to new replies.

Advertisement