Talk About Network

Google


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 > Re: ADL woes
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 7 of 7 Topic 9510 of 10096
Post > Topic >>

Re: ADL woes

by Kimon Hoffmann <kimon.hoffmann@[EMAIL PROTECTED] > Apr 19, 2008 at 06:11 PM

Jiri Palecek wrote:
> Kimon Hoffmann wrote:
> 
>> 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.
> 
> Fully qualified no, but something similar is possible. It is quite
commonly
> used:
> 
>    using default_impl::func;
>    func(x);
> 
> This will call ::func(const HalfWorking&) for arguments of type
HalfWorking,
> and default_impl::func for anything convertible to DefaultType.

Yes, I am aware of that, but until I stumbled across the problem above I
wasn't fully aware of the implications.

> The usual use for this idiom is std::swap, because you want to use
std::swap
> for anything that doesn't have a swap function, and find the overloads
by
> ADL where there is one. Also, you should use it for all std functions
that
> operate on standard types if you want to overload them for your types
and
> find the overloads by ADL (you obviously cannot move your overloads to
> std::) For example, you can create class your_ns::matrix, which would be
> eg. a real matrix. Then, you can define a function

Thanks, this is a keeper :). And now that I learned the lesson the hard
way, I don't believe I'll ever miss this in the future ;).

> Note that you also need this if a C library leaves its definitions in
the ::
> scope. For example, abs(0.5) might call ::abs(int) which is really sad
:-(

Since the code is intended for a library, the main reasons for why I
wanted to make it work with fully qualified names were:
1. I did not want to force a particular usage pattern on the user (i.e.
not force him to use the idiom you described above).
2. I wanted to avoid matching to unexpected global overloads like
::abs(int). Although for user defined types such mismatching is highly
unlikely to happen in practice.

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 Tue Oct 14 8:39:46 CDT 2008.