ADL
Andrei Alexandrescu via Digitalmars-d
digitalmars-d at puremagic.com
Sat Sep 3 09:24:03 PDT 2016
On 9/3/16 5:57 PM, Manu via Digitalmars-d wrote:
> On 3 September 2016 at 22:42, Andrei Alexandrescu via Digitalmars-d
> <digitalmars-d at puremagic.com> wrote:
>> On 9/3/16 1:51 AM, Manu via Digitalmars-d wrote:
>>>
>>> I've
>>> never thought about this problem in C++, or had any problems with ADL.
>>
>>
>> How do you swap two objects of a generic type that may or may not define its
>> own swap? -- Andrei
>
> It's not a problem I've ever had.
A problem you didn't know you have. It's a classic C++ conundrum
combining theory and practice.
> I'm not actually quite sure I
> understand your question...
The task is to swap two objects of generic type T. If T's namespace
defines an overload of swap with the appropriate signature, use it.
Otherwise, fall back to std::swap.
For bonus points: if T defines swap as a _member_ function, use that.
> I guess this is sort of like the issue I
> was alluding to in my other thread though; there exists a generic
> implementation, but some type requires to specialise for itself, which
> then needs to trump the otherwise ambiguous conflict with the
> catch-all? I think that's an interesting problem, but it's quite easy
> to solve with an (ugly) forwarding template; but that forwawrding
> template leads right back here, where the worker `doThingImpl()` as
> implemented for each type that supports 'doThing' depends on ADL to be
> callable from the master `doThing()` function.
Post the code.
Andrei
More information about the Digitalmars-d
mailing list