When calling std::sort()
on 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));
}
Both gcc and clang return an error on the sort on the std::array
-- clang says
error: use of undeclared identifier 'sort'; did you mean 'std::sort'?
Changing to std::sort(begin(foo2), end(foo2))
fixes the problem.
MSVC compiles the code above as written.
Why the difference in treatment between std::vector
and std::array
; and which compiler is correct?