Why does arguement dependent lookup not work for type aliasing in c++?

  argument-dependent-lookup, c++, typedef, using

Considering the following minimal example, function is not found for Option 1, while it is found for Option 2. Argument dependent lookup seems to fail for Option 1. Why?

#include <iostream>
#include <array>

namespace foo {
//    // Option 1
//    using Values = std::array<int, 2>;
//    void function(const Values& v) {std::cout << v[0] << " " << v[1] << 'n';}

    // Option 2
    struct Values{
        int a;
        int b;
    };
    void function(const Values& v) {std::cout << v.a << " " << v.b << 'n';}
}

int main() {
    foo::Values v{1,2};
    function(v);
    return 0;
}

A possible solution is to import function by placing using foo::function; above main. Is there an alternative to avoid this using statement for Option 1?

Source: Windows Questions C++

LEAVE A COMMENT