Here's an example showing what I am essentially trying to do
// Example program
#include <iostream>
#include <vector>
struct base_type
{
static const uint64_t type_id = 0x0;
};
struct A : public base_type
{
static const uint64_t type_id = 0xA;
};
struct B : public base_type
{
static const uint64_t type_id = 0xB;
};
struct C : public base_type
{
static const uint64_t type_id = 0xC;
};
template <class... Args>
struct processor
{
void process(Args... args);
// NEED HELP WITH HOW THIS WOULD WORK
// Essentially I want a fucntion that can extract
// the type_id of each of the template parameters
std::vector<uint64_t> get_type_ids()
{
// What should go in here?
}
};
int main()
{
processor<A, B> my_processor;
B b;
C c;
// Here's the part that I am stuck on
// THIS IS PSEUDOCODE
if (b.type_id in my_processor.get_type_ids() and c.type_id in my_processor.get_type_ids())
{
my_processor.process(b, c);
}
else
{
std::cout << "One of the arguments to process was not the correct type" << std::endl;
}
}
And in this example this would print out the error message. Is there any way to do this? The reason that I am running into this problem is that I am receiving a number of base_type
objects which are being passed to process
but I need to check beforehand whether base_type
can be safely cast into the derived type. Everything actually does have a type_id
already so I'm hoping that can save me.