I have a class which has a variadic member function:
class class_name {
template<ArgTypes.. args>
some_return_type memberMethod(ArgTypes... args) {
//stuff...
}
}
I need to force instantiation of this method inside the class definition block. I loose the method name outside of the class definition block because the class is generated by a bunch of macros.
I try to force the instantiation by copying a pointer to a specialised member function (pseudo code):
template<typename Self, typename RetType, typename... ArgTypes>
struct force_instantation_imlp<Self, RetType, type_placeholder, type_placeholder<ArgTypes...>> {
force_instantation_imlp() {
using instate = RetType (Self::*)(ArgTypes...);
instate force = &Self::memberMethod<ArgTypes...>;
}
};
class class_name {
template<ArgTypes.. args>
some_return_type memberMethod(ArgTypes... args) {
//stuff...
}
force_instantation_imlp<class_name, some_return_type, rest_of_types_deduced_from_context> force_virtual_instantation;
}
type_placeholder is just a helper template to "freeze" parameter pack.
This unfortunately gives me a compile error
error: expected primary-expression before ‘...’ token instate force = &Self::memberMethod<ArgTypes...>;
I guess that this error results from teh fact that the member function is a variadic template.
Is there any way to force variadic template member function instantiation inside the class definition block?
autoinstead ofinstate:auto force = &Self::memberMethod<ArgTypes...>;. That saves you from writing theusingto define a type. - Nawazinstate force = &Self::memberMethod<ArgTypes...>;? - dyptemplate:&Self::template memberMethod<ArgTypes...>;- dypinstate force = &Self::memberMethod;works is that the compiler can select the overload based on the required type (type ofinstate) in that context. That of course isn't possible fordecltype. So inside decltype you'd need either a cast or explicitly specify the overload (e.g. using explicit template arguments). This of course is useless as you could directly specify the function type w/odecltypeif you can access those parameter types. - dyp