I can easily capture and enumerate over the parameters of a method or function, by using a variadic template such as:
template<typename RT, typename ...Args>
class MyFunctor< RT (*)(Args ... args)>
{
//Count the number of arguments
static constexpr int const arity=sizeof ...(Args);
//Create something to store the arguments in
std::tuple<Args...> _arguments;
}
I can then create template methods that can iterate through the argument list and eventually invoke a pointer to a real function using the _agrument tuple.
I understand that constructors are nameless, but are they also typeless? Is there a way to get the 'type' of a constructor so that I can do something similar to what I can do with functions and methods?
In C++ 03 I could capture the type of a constructor with the following (using GCC 3.3):
TypeDefT< typeof( MyClass::MyClass(int i) ) *>
By placing the pointer syntax after the typeof() statement, I could then treat the constructor signature like the type of a normal function pointer.
I would then add a create method to the FunctionPointer template that could then be called with a mere list of parameters, and new MyClass( p1, p2, p3 ) could happen.
However, it seems with C++ 17 there isn't a way to get the type of a constructor like I seemed to be able to with C++ 03 nor like I can with functions in C++ 17. Is there a way to do this?
Thank you
Constructors do not have types. Have you noticed that you are not allowed to write a return type when declaring a constructor?
Unfortunately, there is no way to get something like a function pointer to a constructor. Your "C++03" solution is not standard, and GCC 3.3 is a very old compiler; back in those days, GCC had many non-portable extensions, and most of them have been removed.
You need to find a different way of doing the actual thing that you want to do. As pointed out in the comments to the question, generic code usually doesn't need to "know" a constructor's signature.