I have a situation where I have an enum that defines a list of jobs.
enum class job_t
{
a,
b,
c,
};
Elsewhere I have classes that subclass an interface like
class job_interface
{
public:
virtual job_t get_job_type(void) const = 0;
/* ... other methods snipped for simplicity */
}
What I want to do is verify for each value of the job_t enum that a class exists that subclasses job_interface with the same name. I have access to magic_enum so I am wondering if it's possible to translate the enum values to compile time strings and then detect if they're valid typenames via static_assert. It would also be nice if I could verify those classes were decendants of job_interface
Any suggestions on how I might achieve this?
Identifier names can't be obtained from strings, even if they're compile time. The best you can do is macros, e.g. with X macros
To define the enum
Checking for existence is a bit hard. Checking for completeness is easier, which should suffice for your case. To check for completeness of a type
T, we SFINAE onsizeof(T)Then bundle the completeness check together with the base class check
Finally, we abuse the fact that
struct a*is valid regardless of whetherais defined or notLive.