equivariant functions

KennyTM~ kennytm at gmail.com
Mon Oct 13 07:15:47 PDT 2008


Andrei Alexandrescu wrote:
> Denis Koroskin wrote:
>> On Mon, 13 Oct 2008 01:52:25 +0400, Andrei Alexandrescu 
>> <SeeWebsiteForEmail at erdani.org> wrote:
>>
>>> Denis Koroskin wrote:
>>>> Sorry to hit a dead horse but...
>>>>  auto dg = &stripl; // what is the type of dg?
>>>
>>> stripl is three overloads. You must use a precise type on the 
>>> receiving side to get a pointer to function, as with any overloaded 
>>> symbol.
>>>
>>>> string z = dg("foo");
>>>> char[] x = dg("foo".dup);
>>>>  It is great that you brought the issue to discussion, but I think 
>>>> this solution is a miss.
>>>
>>> I'm glad you're trying to dent it, this is the best way to find bugs 
>>> in it. But let me note that so far you haven't gotten even near :o).
>>>
>>>
>>> Andrei
>>
>> Ok, I'll try harder. Here is a common used pattern:
>>
>> interface IMaybeBar
>> {
>>     Bar isBar();
>>     const(Bar) isBar();
>>     invariant(Bar) isBar();
>> }
>>
>> class Foo : IMaybeBar
>> {
>>     Bar isBar() { return null; }
>>     const(Bar) isBar() const { return null; }
>>     invariant(Bar) isBar() invariant { return null; }
>> }
>>
>> class Bar : Foo
>> {
>>     Bar isBar() { return this; }
>>     const(Bar) isBar() const { return this; }
>>     invariant(Bar) isBar() invariant { return this; }
>> }
>>
>> let's change it into one.
>>
>> interface IMaybeBar
>> {
>>     same(Bar) isBar() same(this); // same is shorter than sameconst 
>> and as descriptive as sameconst
>> }
>>
>> class Foo
>> {
>>     same(Bar) isBar() same(this) { return null; }
>> }
>>
>> class Bar : Foo
>> {
>>     same(Bar) isBar() same(this) { return this; }
>> }
>>
>> Your solution? Note that it shouldn't conflict with your clone example:
>>
>>> class S
>>> {
>>>      typeof(this) clone();
>>> }
> 
> Walter found an answer last night.
> 
> interface IMaybeBar
> {
>     Bar isBar();
>     const(Bar) isBar() const;
>     invariant(Bar) isBar() invariant;
> }
> 
> class Foo : IMaybeBar
> {
>     PassQual!(typeof(this), Bar) isBar() const { return null; }
> }
> 
> class Bar : Foo
> {
>     typeof(this) isBar() const { return this; }
> }
> 
> 
> Andrei

What is PassQual!() ?_?



More information about the Digitalmars-d mailing list