iota
函数以前在 <algorithm>
中 header 。已改为<numeric>
.
我需要保留旧方法以实现向后兼容性,因此我想使用预处理器选项来选择要包含的正确 header 。
这什么时候改变了,我应该使用哪个预处理器选项?
最佳答案
iota
从未从 <algorithm>
中“移动” . C++03 没有 std::iota
在任何 header 中,没有符合要求的实现可以提供它,因为 iota
不是保留名称,这是工作所必需的:
#define iota arbitrary preprocessing token sequence like this and *that and "!" and \
-13833rfa231fn7or.other.line.noise.that.happens.to.be.a.pp.number
#include <every-standard-header-here>
它被添加到 <numeric>
在 C++11 中并且在 the SGI STL 中的 <numeric>
也作为扩展。它从来没有出现在<algorithm>
因此不可能从中移动。
现在,因为允许标准库头文件以任意方式相互包含,所以 GCC <= 5's <algorithm>
发生了。在 C++11 模式中包含 <random>
偶然,其中包括<numeric>
偶然。这只是一个您不应该依赖的实现细节,GCC 6 不再那样做。解决方法是简单地包含正确的 header ,它一直是 <numeric>
。 .
关于c++ - STL iota 包含文件更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42959812/