小编Guy*_*ton的帖子

不合格的 sort()——为什么在 std::vector 上使用而不是在 std::array 上编译,哪个编译器是正确的?

当调用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;哪个编译器是正确的?

c++ c++17

11
推荐指数
1
解决办法
465
查看次数

标签 统计

c++ ×1

c++17 ×1