equivariant functions

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Oct 12 14:44:59 PDT 2008


Denis Koroskin wrote:
> On Mon, 13 Oct 2008 01:17:36 +0400, Andrei Alexandrescu 
> <SeeWebsiteForEmail at erdani.org> wrote:
> 
>> Denis Koroskin wrote:
>>> May I suggest one of my personal preference? Here it is:
>>>  sameconst(char)* strstr(sameconst(char)* str1, const(char)* str2)
>>> {
>>>     return str2; // compile-time error. Can't cast const(char)* to 
>>> sameconst(char)* implicitly
>>> }
>>
>> I prefer my solution because it's more general and addresses more 
>> issues than passing the qualifier out.
>>
>> Andrei
> 
> Yes, my solution doesn't address clone() method return type, but I think 
> they aren't related.

I just showed how they are related. You can't "think" they aren't 
related. Feel free to believe they aren't related, but that means you 
need to work around some facts.

> Besides, your solution can't implement the following example, so mine is 
> more flexible: :)
> 
> sameconst(char)[] findPatternInS1OrS2(sameconst(char)[] s1,
>     sameconst(char)[] s2, string needle);

This can be easily worked out with a template. There are some 
limitations of the solution I suggested. If we're able to address most 
problems, we can leave the occasional straggler to a template solution.


Andrei



More information about the Digitalmars-d mailing list