如何检测是否有一个函数。是constexpr?并标记其他功能。 Constexpr取决于它? [英] How to detect if a func. Is a constexpr? And mark other func. Constexpr depending on it?
本文介绍了如何检测是否有一个函数。是constexpr?并标记其他功能。 Constexpr取决于它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一些功能模板f1:
Assuming i have some function template f1:
template<typename f2>
int f1(int i, int j) throw() {
return i + j + f2(i, j);
}
有办法确定'f2(i,j)'是否可以成为constexpr。 (无论它是函数还是函子)都将'f1'标记为constexpr。也是这样吗?
我尝试了什么:
我在考虑在这里使用SFINAE有些怎么样,但是没有找到如何检测constexpr。使用输入特征。
推荐答案
As了解 constexpr 它是一个编译时限定符,所以你必须声明f2也作为constexpr。
As Is understand the constexpr it is a compile time qualifier, so you MUST declare f2 also as constexpr.
template <constexpr typename="" f2="">
constexpr int f1(int i, int j) throw() {
return i + j + f2(i, j);
}</constexpr>
这篇关于如何检测是否有一个函数。是constexpr?并标记其他功能。 Constexpr取决于它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文