Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > ADL woes
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 7 Topic 9510 of 9593
Post > Topic >>

ADL woes

by Kimon Hoffmann <kimon.hoffmann@[EMAIL PROTECTED] > Apr 16, 2008 at 03:45 PM

Hi all,

I have a problem overloading a function located in a namespace for a 
custom type. I have constructed the following example (emulating a 
preprocessed source file) exhibiting the problem. Although I tried to be 
concise with it, it's still quite long, so please bear with me:

----------------------------------------------------------------------

// Code included from DefaultImplementation.hpp

namespace default_impl {

   struct DefaultType { /* ... */ };

   inline void func(DefaultType const&) {
     // .. do something ...
   }

}

// Code included from Algorithm.hpp

namespace algorithm {

   template<typename T>
   void cool_algorithm_1(T const& value) {
     using default_impl::func;
     // ...
     func(value);
     // ...
   }

   template<typename T>
   void cool_algorithm_2(T const& value) {
     // ...
     default_impl::func(value);
     // ...
   }

}

// Code included from NotWorking.hpp

struct NotWorking { /* ... */ };

namespace default_impl {

   inline void func(NotWorking const&) {
     // .. do something else ...
   }

}

// Code included from HalfWorking.hpp

struct HalfWorking { /* ... */ };

inline void func(HalfWorking const&) {
   // .. do something else ...
}

// Code from Main.cpp

int main(int, char**) {

   NotWorking notWorking;
   // This does not work as the func() overload is not found
   algorithm::cool_algorithm_1(notWorking);
   // For the same reason this does not work either
   algorithm::cool_algorithm_2(notWorking);

   HalfWorking halfWorking;
   // This *does* work thanks to ADL
   algorithm::cool_algorithm_1(halfWorking);
   // This does not work because of full qualification
   algorithm::cool_algorithm_2(halfWorking);

   return 0;
}

----------------------------------------------------------------------

It is obvious why the cool_algorithm_X() functions choke when calling 
func() with a constant NotWorking reference, and it is also clear to me 
why the correct overload of func() is found from within 
cool_algorithm_1() in the HalfWorking case.

What I'd like to know is whether there is some way to make HalfWorking 
work with fully qualified calls to func() like the one in 
cool_algorithm_2(), besides the obvious solution to move HalfWorking 
together with the function overload into the default_impl namespace.

I really appreciate any help on this.

Best regards,
   Kimon

-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]




 7 Posts in Topic:
ADL woes
Kimon Hoffmann <kimon.  2008-04-16 15:45:27 
Re: ADL woes
Alberto Ganesh Barbati &l  2008-04-17 03:51:35 
Re: ADL woes
Alberto Ganesh Barbati &l  2008-04-17 16:43:14 
Re: ADL woes
Kimon Hoffmann <kimon.  2008-04-18 15:01:58 
Re: ADL woes
Kimon Hoffmann <kimon.  2008-04-18 15:02:05 
Re: ADL woes
Jiri Palecek <jpalecek  2008-04-19 01:39:31 
Re: ADL woes
Kimon Hoffmann <kimon.  2008-04-19 18:11:06 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed May 14 19:14:17 CDT 2008.