【发布时间】:2017-05-03 05:57:08
【问题描述】:
我刚刚发现标准algorithm 标头中的几种算法不需要std::。
例子:
#include <vector>
#include <algorithm>
int main() {
std::vector<int> m;
count(m.begin(), m.end(), 0);
count_if(m.begin(), m.end(), [](auto){return true;});
for_each(m.begin(), m.end(), [](auto){});
find_if(m.begin(), m.end(), [](auto){return true;});
}
有什么具体原因吗? g++ 和 clang++ 都接受上面的代码。
【问题讨论】:
-
由于ADL,最好不要依赖它,以防你重构使用自定义容器。