专门用于布尔值的真假
Specializing both true and false for bool
为什么C++允许对true
和false
参数进行类型专用化?
template<bool> struct omg { /* can't access anything declared here */ };
template<> struct omg<true> { };
template<> struct omg<false> { };
是否有任何情况是有意义/有用的?
我认为
没有这种情况。但标准对模板非类型参数没有任何限制,即适合条件。顺便说一下,这样的限制应该是,它应该适用于所有类型。做这样的事情是不正确的
enum A { first, second };
template<A> struct omg {};
template<> struct omg<first> {};
template<> struct omg<second> {};
恕我直言,这太复杂了。
相关文章:
- 在没有定义返回类型的函数中返回布尔值,并将结果保存在无错误的char编译中-为什么
- 变量定义到C++布尔值转换
- 如何确保在使用基于布尔值的两个方法之一调用方法时避免分支预测错误
- 不能将方法返回的值用于另一个方法
- 重载更少,则运算符返回相反的布尔值
- 将此布尔值传递给此函数的最有效方法是什么?
- 如何设置 c++ 类的布尔值?
- 使用 MAKEWORD / MAKEWPARAM 使用布尔值而不是布尔值
- 将 10 个线程与原子布尔值同步
- 创建类似于布尔值的变量类型
- 布尔值向量的基于范围 for 循环
- 零点和布尔值之间的比较
- 简化对两个布尔值的 4 个 if/else 检查
- 无法创建带有布尔值和矢量的地图
- 对于完成布尔值设置为 true 后未停止的循环
- 我无法将'2D array whit bool'转换为"空 2D 数组布尔值"(用于生命游戏)
- 专门用于布尔值的真假
- Lua toString 异常用于布尔值
- CRITICAL_SECTION用于设置和获取单个布尔值
- 哪个操作符重载被用于ifstream对象求值为布尔值