Matt Hurst
Matt Hurst

Reputation: 11

Argument-dependent Name Lookup: add extra namespace to look into

I would like to exploit the ADL rules to check for the function in an extra namespace:

Say we have a class X.

class X
 {
 ...
 };

In A call

X x;
f(x);

I'd like the compiler to look into namespace funky, that is until now unrelated to class X. But I don't want to clutter the coded by putting funky::f whenever calling f.

One way to achieve this is to define class X as a template class with an argument coming from namespace funky.

template <typename Fake = funky::someClassFromFunky>
class X
 {
 ...
 };

For a call f(x), now, the compiler will indeed look for funky::f.

Is there a cleaner / simpler way of achieving the same behavior? (In particular, referring to some arbitrary class someClassFromFunky in the declaration of class X is awkward.)

Upvotes: 1

Views: 128

Answers (1)

Vaughn Cato
Vaughn Cato

Reputation: 64308

You can import f into your namespace like this:

using funky::f;

Upvotes: 3

Related Questions