I'm using inheritance with a set of classes. One of the child classes takes in an std::function(ReturnTy<ParamTypes...>), along with the ParamTypes arguments. The class signature and constructor look like:
template<class ReturnTy, class... ParamTypes> class Child : public Interface { public: Child(ReturnTy default_value, ParamTypes... args) : func_set_(false) , m_Args(std::make_tuple(std::forward<ParamTypes>(args)...)) , m_ReturnValue(default_value) {} private: bool func_set_; std::function<ReturnTy(ParamTypes...)> m_Funciton; std::tuple<ParamTypes...> m_Args; ReturnTy m_ReturnValue; }; My issue is when I want to specialize for the case where there are no parameters. Furthermore, I also want to specialize for the case which ReturnTy=void and there are parameters. I found an answer that is close to what I'm looking for here, but it doesn't exactly cover what I'm trying to do because that question uses compile-time integers as template parameters, where I'm using types. It also concerns functions instead of classes. I feel like I'm close, but I just need some help to make my code work.
For reference, here is what I have for the other specializations (shortened):
template<class ReturnTy> class Child<ReturnTy> : public Interface { public: Child(ReturnTy default_value) : // The same as first class without m_Args {} private: // Same as first class without m_Args }; template<class... ParamTypes> class Child<void, ParamTypes...> : public Interface { public: Child(ParamTypes... args) : // Same as first class without m_ReturnValue private: // Same as first class without m_ReturnValue };
Edit
Specifically, the issue comes from something like the following line of code:
Child<void> obj1(5);
set_function()method that will initialize thestd::function, and there is a virtualrun()function from the interface that doesm_ReturnValue = std::apply(m_Function, m_Args).Child<void>, which specialization should be selected? The one withReturnTyonly or the one withvoidin first place?voidto be selected, but I'm not sure how to tell the compiler to select that one.class Child<void, ParamTypes...>?