Can this be done?
enum A
{
enum B
{
SOMETHING1,
SOMETHING2
};
enum C
{
SOMETHING3,
SOMETHING4
};
};
MESONS pi = PI();
MATTER mat = pi;
assert (pi == mat);
Do you mind a little C++11 template magic?
template
struct is_defined_in : std::false_type {};
template
struct is_defined_in : is_defined_in {};
template
struct is_defined_in : std::true_type {};
template struct helper {
friend bool operator==(helper a, helper b)
{ return a.id == b.id; }
friend bool operator!=(helper a, helper b)
{ return a.id != b.id; }
int id=ID;
};
template struct category {
int id;
template ::value>::type>
category(T t) : id(t.id) {}
friend bool operator==(category a, category b)
{ return a.id == b.id; }
friend bool operator!=(category a, category b)
{ return a.id != b.id; }
};
enum class ElementaryParticleTypesID
{ PI, PROTON, NEUTRON, ELECTRON };
struct PI : helper<(int)ElementaryParticleTypesID::PI> {};
struct PROTON : helper<(int)ElementaryParticleTypesID::PROTON> {};
struct NEUTRON : helper<(int)ElementaryParticleTypesID::NEUTRON> {};
struct ELECTRON : helper<(int)ElementaryParticleTypesID::ELECTRON> {};
using MESONS = category;
using BARYONS = category;
using LEPTONS = category;
using MATTER = category;
(the static_assert
currently doesn't work beyond two hierarchies, but this can be added if you want to)