The following code fails as expected, because no overload of get
is found. Using std::get
would solve the problem.
#include <array>
int main()
{
std::array<int, 2> ar{2,3};
auto r = get<0>(ar);//fails, get was not declared in this scope
}
However, introducing a templated version of get
, even though it's not matching the function call, somehow makes the compiler use the std::get
version:
#include <array>
template <typename T>
void get(){};
int main()
{
std::array<int, 2> ar{2,3};
auto r = get<0>(ar);//returns 2
}
I can't find any part of the standard that explains this. Is this a bug in all 3 compilers I tested (probably not), or am I missing something?
This behaviour was tested in
- MSVC 15.9.2
- Clang 8.0.0
- GCC 9.0.0 (still an experimental version)
EDIT: I am aware of ADL. But if ADL makes the second code work, why does it not in the first part?