小编m.z*_*unt的帖子

浮点值的C++ XOR交换

是否可以在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下),但我担心如果需要这样的做法?

c++ floating-point swap xor

2
推荐指数
1
解决办法
2101
查看次数

带有 json 文件的 C++ Boost 程序选项

可以使用 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

c++ json boost boost-program-options

2
推荐指数
1
解决办法
1416
查看次数

标签 统计

c++ ×2

boost ×1

boost-program-options ×1

floating-point ×1

json ×1

swap ×1

xor ×1