equivariant functions

Denis Koroskin 2korden at gmail.com
Sun Oct 12 14:32:13 PDT 2008


On Mon, 13 Oct 2008 01:27:42 +0400, Denis Koroskin <2korden at gmail.com>  
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.
>
> 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);


And also this:

class Storage
{
    sameconst(Foo) foo() sameconst(this) // const, invariant or none
    {
         return _foo;
    }

    private Foo _foo;
}

Your version?



More information about the Digitalmars-d mailing list