是否可以在C++中使用具有浮点值的XOR交换算法?
然而,维基百科说:
XOR按位运算以交换具有相同数据类型的不同变量的值
但我有点困惑.使用此代码:
void xorSwap (int* x, int* y) {
*x ^= *y;
*y ^= *x;
*x ^= *y;
}
int main() {
float a = 255.33333f;
float b = 0.123023f;
xorSwap(reinterpret_cast<int*>(&a), reinterpret_cast<int*>(&b));
std::cout << a << ", " << b << "\n";
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它似乎工作(至少在gcc下),但我担心如果需要这样的做法?
可以使用 boost 程序选项库:http : //www.boost.org/doc/libs/1_64_0/doc/html/program_options.html
在这里读取 json 格式的文件作为输入文件?
或者,如果我在 json 文件中有一些配置,我需要自己解析它,例如:http : //www.boost.org/doc/libs/1_64_0/doc/html/property_tree.html