Jump to content
  • Advertisement
irreversible

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

Recommended Posts

Posted (edited)
#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.

Edited by irreversible

Share this post


Link to post
Share on other sites
Advertisement
template<class ControlClassType, CClassRegProc RegProc, class BaseClass>
class DDocument {
	public:  
  		using _A			= ControlClassType;
		static constexpr CClassRegProc _B = RegProc;
  		using _C			= BaseClass;
};

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!