我正在尝试在static constexpr
模板类中定义一个 lambda 模板变量 ()。模板变量接受一个 NTTP,我希望它是一个size_t
.
在某些情况下,我可以这样做,例如 NTTPauto
不是size_t
. 如果类本身不是模板类,我也可以这样做。但是,如果我尝试size_t
在模板类中对 lambda 使用 NTTP (),我会得到:
internal compiler error: unexpected expression ‘<enumerator>’ of kind template_parm_index
现场示例:https ://onlinegdb.com/Sk3wC7nyP
下面的代码:
template<size_t>
struct Foo{
// internal compiler error: unexpected expression ‘<enumerator>’ of kind template_parm_index
template<size_t>
static constexpr auto foo = [](){};
};
template<size_t>
struct Bar{
// OK
template<auto>
static constexpr auto foo = [](){};
};
struct Baz{
// OK
template<size_t>
static constexpr auto bar = [](){};
};