C++ 使用元类强制所有枚举类类型具有公共元素

C++ 使用元类强制所有枚举类类型具有公共元素,c++,enums,metaclass,C++,Enums,Metaclass,在我的一个库中,我有一组enum类类型,用于一些struct/类和/或成员函数模板: enum class Param { Undef, P1, P2, P3, P4 }; enum class Type { Undef, T1, T2, T3, T4 }; template<Type t> struct Container { template <Param p = Param::Un

在我的一个库中,我有一组
enum类
类型,用于一些
struct
/
和/或成员函数模板:

enum class Param
{
    Undef,
    P1,
    P2,
    P3,
    P4
};

enum class Type
{
    Undef,
    T1,
    T2,
    T3,
    T4
};
template<Type t>
struct Container
{
    template <Param p = Param::Undef>
    void func() {};
}
你明白了。我确保在每个
enum
中手动插入
unde
元素,我将其用作某些模板的默认值:

enum class Param
{
    Undef,
    P1,
    P2,
    P3,
    P4
};

enum class Type
{
    Undef,
    T1,
    T2,
    T3,
    T4
};
template<Type t>
struct Container
{
    template <Param p = Param::Undef>
    void func() {};
}
模板
结构容器
{
模板
void func(){};
}
由于我希望库中的all
enum
s具有
Undef
元素,因此能够从编译器请求该元素将非常棒。基本上,我希望能够迭代所有
enum
s,并在不存在
unde
元素的情况下注入该元素


我的问题是,在
c++20
中使用元类可以实现吗?如果是,代码会是什么样子(例如,使用建议)?

元类不是C++20的一部分。他们甚至没有被提议采用C++20。另外,由于元类的设计还没有完成,所以询问这些细节是不合理的。我知道c++20还没有完成,但我链接到的提案已经包含了一些有用的例子,可以通过使用元类实现
enum
类型。我希望我所要求的原则上是可能的,但我不确定元类是否会这样工作。我不介意把这个问题留到最终的元类设计被接受为止。