dgruending
dgruending

Reputation: 1123

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

Considering the following minimal example, function is not found. Argument dependent lookup seems to fail. Why?

#include <iostream>
#include <array

namespace foo {
    using Values = std::array<int, 2>;
    void function(const Values& v) {std::cout << v[0] << " " << v[1] << '\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?

Upvotes: 0

Views: 104

Answers (1)

Not a real meerkat
Not a real meerkat

Reputation: 5729

A type alias is just that: an alias. It's not a separate type, and as such it can't really affect ADL rules.

You could in your example, change the declaration of v to std::array<int, 2> v{1,1} and it would have the same effect.

Upvotes: 1

Related Questions