So I am essentially trying to shove the rtti of a parameter pack into a list of type_info*. But for some reason, it doesn't seem to compile (or rather the compiler gives up half way through). Either way I can't seem to figure it out. Does anyone have a method to fix this, or better yet, know why it's breaking? Anywho, here's the code:
#pragma once
#include <typeinfo>
#include <vector>
class ParamChecker
{
public:
typedef std::vector<const type_info*> Types;
template <typename T> void PushType()
{
types.push_back(&typeid(T));
}
template <typename Head, typename... Tail> void PushTypes()
{
PushType<Head>();
PushTypes<Tail...>();
}
void PushTypes() {}
private:
Types types;
};
Thanks in advance!
I don't have Visual Studio to test, but I see the problem in your code so I'll tell you about that, and you can test on Visual Studio.
The problem is that, when you recurse into
PushTypes<Tail...>();
andTail...
is empty, you're calling,PushTypes<>();
. Notice that your base case,void PushTypes() {}
is not a template function, i.e. you can't call it viaPushTypes<>();
.Also note that you'll need a class template as a helper because we don't have partial specializations for function templates yet (hopefully it'll be coming soon).
But here's what you can do.
EDIT: The following is an alternative approach using
type_list
and passing it as an argument.NOTE: The use of
type_list<>
here instead oftuple<>
is because constructing an empty tuple requires that all of the types be default-constructable, and even if they were all default-constructable, we don't want to default-construct them for no reason.