Before posting this question, I have already tried to fit the approaches mentioned over here, here and here. However, nothing could solve my requirement as I have an intermediate function that needs some adjustments.
Essentially,what I have is as follows. I have to construct the type T based on the arguments whose types are stored in parameter pack Args and corresponding values in the array ARGValue *ptr
However, to map the values of type from ARGValue* ptr to a type in Args... I need to do an intermediate operation which is as below.
// Specialization for 1 argument
template<typename T,typename... Args>
struct instance_helper<T,1,Args...>
{
static T invokeConstructor(const ARGValue *ptr)
{
// Intermediate operation
typedef typename std::tuple_element<0, std::tuple<Args...> >::type TT;
const auto val0 = *(someUglyCast<TT*>(ptr[0])) ;
// Return the desired type
return T(val0);
}
};
//Specialization for no argument
template<typename T,typename... Args>
struct instance_helper<T,0,Args...>
{
static T invokeConstructor(const ARGValue*)
{
return T();
}
};
// General Case
template<typename T,size_t packSize,typename... Args>
struct instance_helper
{
static T invokeConstructor(const ARGValue *ptr)
{
// Do some recursive magic here for intermediate operation
return T(//Do some recursive magic) ;
}
};
How do I solve this? How can I safely get the values for all the types in Args... from ARGValue* and then construct the type T?
I do not want to create specializations for multiple arguments as it might clutter the code.
Aucun commentaire:
Enregistrer un commentaire