【发布时间】:2021-02-27 15:57:12
【问题描述】:
我正在学习概念,我想不出一种方法来限制非类型模板参数的值(不是类型)。
Example 编译的代码,虽然我希望它没有(由于失败的要求):
#include <cassert>
enum Bla{
Lol,
Haha
};
template<Bla b>
requires requires{
// my guess is that this just checks that this is valid expression, not
// that it is true
b>1;
}
void f(){
assert(b>1);
}
int main() {
f<Lol>(); // compiles, not funny ;)
}
注意:
这是一个简化的例子(我想要“模板重载”)所以static_assert 对我不好,我试图避免std::enable_if 因为语法很可怕。
【问题讨论】:
-
static_assert会使其失败,但我想这只是简化示例 -
@idclev463035818 我想要它用于重载,所以是的。
标签: c++ c++20 c++-concepts non-type-template-parameter