当调用std::sort()
a 时std::array
:
#include <vector>
#include <array>
#include <algorithm>
int main() {
std::vector<int> foo{4, 1, 2, 3};
sort(begin(foo), end(foo));
std::array<int, 4> foo2{4, 1, 2, 3};
sort(begin(foo2), end(foo2));
}
Run Code Online (Sandbox Code Playgroud)
gcc 和 clang 都在排序上返回错误std::array
-- clang 说
错误:使用未声明的标识符“排序”;你的意思是'标准::排序'?
更改以std::sort(begin(foo2), end(foo2))
解决问题。
MSVC 按照编写的方式编译上面的代码。
为什么std::vector
和之间的待遇不同std::array
;哪个编译器是正确的?