可以写这样的东西"f<N> can compile only when N>0"吗?
Is possible to write something like that "f<N> can compile only when N>0"?
例如,我可以在编译时检查N是否> 0,如下所示:
#include <stdio.h>
template<int N>
struct Is{
enum{Positive=N>0?1:0};
};
template<>
struct Is<0>{
};
int main(){
printf("%dn",Is<3>::Positive);
printf("%dn",Is<-3>::Positive);
return 0;
};
通过强制Is<0>::Positive过滤0不能编译,但是是否有任何方法(例如:template,macro....)强制Is<当N不> 0时,N>::Positive不能编译?当N不>
static_assert(N > 0, "N must be greater than zero")
相关文章:
- EASTL矢量<向量<int>>连续的
- 如何修复输出日志中的"EnableInput can only be specified on a Pawn for its Controller"错误
- _BitScanForward64 can not be found
- 如何使用CAPL的诊断功能获取CAN传输的数据(256字节)?
- 为什么在 C++ 中说"can't find constructor"?
- OpenCV 和 C++:"Can't resolve variable 'Mat`"
- 有没有办法有效地更新QML中的CAN数据?
- CAN套接字读取帧较晚
- 在C++通过CAN发送部分数据
- 解决方法:'can not be used when making a shared object; recompile with -fPIC'使用Cmake。使用普通的 g++ 工作
- How can I std::sqrt(boost::lambda::placeholder1_type)?
- Protobuf 生成的C++类无法针对 iOS 进行编译,并显示错误"Only virtual member functions can be marked 'final'"
- C - 创建矢量&lt; vector&lt; double&gt;&gt;矩阵具有分配而不是inizializ
- CAN模板类型推理考虑原始操作类型转换
- C 字符串比较“祝您好运”&gt;“再见”
- 在创建完整对象之前编写 if-can-add check 方法的正确方法?
- 如何修复警告"the compiler can assume that the address of 'object' will never be NULL"
- 为什么这句话"The expression can be used only as the left-hand operand of a member function call"在 [expr.re
- 为什么将此对向量&lt; map&lt; int,int&gt;&gt;中的地图进行更新.失败
- 由mpglib输出的"hip: Can't rewind stream by 74 bits"到底意味着什么?