C++ 促进预验证相等性测试
C++ Boost preprosessor equality testing
Boost PP 的相等性测试看起来像
# define NOT_EQUAL_I(x, y) CAT(NOT_EQUAL_CHECK_, NOT_EQUAL_ ## x(0, NOT_EQUAL_ ## y))
# define NOT_EQUAL_CHECK_NIL 1
# define NOT_EQUAL_CHECK_NOT_EQUAL_0(c, y) 0
# define NOT_EQUAL_CHECK_NOT_EQUAL_1(c, y) 0
# define NOT_EQUAL_CHECK_NOT_EQUAL_2(c, y) 0
# define NOT_EQUAL_CHECK_NOT_EQUAL_3(c, y) 0
# define NOT_EQUAL_0(c, y) IIF(c, NIL, y(1, NIL))
# define NOT_EQUAL_1(c, y) IIF(c, NIL, y(1, NIL))
# define NOT_EQUAL_2(c, y) IIF(c, NIL, y(1, NIL))
# define NOT_EQUAL_3(c, y) IIF(c, NIL, y(1, NIL))
这依赖于宏在这种情况下扩展一次的事实。
然而,另一种解决方案很容易想到,而且成本似乎更低(空间):
#define EQ_0_0 ,
#define EQ_1_1 ,
#define EQ_2_2 ,
#define EQ_3_3 ,
#define SECOND(_,x,...) x
#define PARSE(...) __VA_ARGS__
#define EQ(x,y) PARSE(SECOND PARSE() (0 EQ_##x##_##y 1, 0 ))
那么为什么Boost选择前一种形式而不是后一种形式呢?它们有什么好处和坏处?
提升考虑不允许...
的环境(BOOST_PP_VARIADICS
)。
相关文章:
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- 正在尝试了解输入验证循环
- 无法编译 rtmidi 测试 cmidiin.cpp 文件, 非法指令
- 尽管测试成功,CppUnit测试核心仍被丢弃.为什么
- 数据成员SFINAE的C++17测试:gcc vs clang
- 如何在C++中检查2D数组中负值的输入验证
- 如何使用重载的相等(==)运算符向测试用例添加描述
- 为什么二进制搜索在我的测试中不起作用
- 从父数组测试用例构造二叉树失败
- 如何测试我的谷歌身份验证器实现?
- 在C++测试家庭作业问题中的字符串输入时无法退出循环(作为数据验证)
- 如何最好地将C++中的两个数组与单元测试进行比较,以验证它们是否匹配
- C++ 促进预验证相等性测试
- 验证乘法跨流的测试
- 在单元测试中验证static_assert
- 如何测试/验证零初始化是否发生
- 使用cmake:我如何编写一个测试来验证类是抽象的?
- 编写死亡测试来验证std::set_terminate行为
- WACK测试在Windows运行时元数据验证上失败
- c++测试验证相等操作符随时间保持与结构体一致