Thread overview
inout based on this reference?
Aug 29, 2010
Simen kjaeraas
Aug 30, 2010
Simen kjaeraas
August 29, 2010
Is it possible to make a function return dependent upon the constancy of the this reference?

i.e. this:

struct foo {
   int n;
   inout( ref int ) getn( ) inout {
       return n;
   }
}


-- 
Simen
August 30, 2010
On Sun, 29 Aug 2010 17:36:24 -0400, Simen kjaeraas <simen.kjaras@gmail.com> wrote:

> Is it possible to make a function return dependent upon the constancy of the this reference?
>
> i.e. this:
>
> struct foo {
>     int n;
>     inout( ref int ) getn( ) inout {
>         return n;
>     }
> }

Yes.  That is the bread-and-butter usage for inout.

Although inout is currently horribly broken.

-Steve
August 30, 2010
On Mon, 30 Aug 2010 09:08:11 -0400, Steven Schveighoffer <schveiguy@yahoo.com> wrote:

> On Sun, 29 Aug 2010 17:36:24 -0400, Simen kjaeraas <simen.kjaras@gmail.com> wrote:
>
>> Is it possible to make a function return dependent upon the constancy of the this reference?
>>
>> i.e. this:
>>
>> struct foo {
>>     int n;
>>     inout( ref int ) getn( ) inout {
>>         return n;
>>     }
>> }
>
> Yes.  That is the bread-and-butter usage for inout.
>
> Although inout is currently horribly broken.

I should point out, the function sig should be:

ref inout(int) getn() inout

inout is a type modifier, ref is a storage class.

-Steve
August 30, 2010
Steven Schveighoffer <schveiguy@yahoo.com> wrote:
0123456789012345678901234567890123456789012345678901234567890123456789012
> On Sun, 29 Aug 2010 17:36:24 -0400, Simen kjaeraas <simen.kjaras@gmail.com> wrote:
>
>> Is it possible to make a function return dependent upon the constancy of the this reference?
>>
>> i.e. this:
>>
>> struct foo {
>>     int n;
>>     inout( ref int ) getn( ) inout {
>>         return n;
>>     }
>> }
>
> Yes.  That is the bread-and-butter usage for inout.
>
> Although inout is currently horribly broken.

So horribly broken that example does not work at all, or is that just me?

This is my code, verbatim:

//////////////////////////
module foo;

struct bar {
    int n;
    ref inout( int ) getN( ) inout {
        return n;
    }
}

void main( ) {
}
//////////////////////////

And it gives this message:

foo.d(5): Error: inout on return means inout must be on a parameter as
well for inout inout(int)()

-- 
Simen
August 30, 2010
On Mon, 30 Aug 2010 13:49:20 -0400, Simen kjaeraas <simen.kjaras@gmail.com> wrote:

> Steven Schveighoffer <schveiguy@yahoo.com> wrote:
> 0123456789012345678901234567890123456789012345678901234567890123456789012
>> On Sun, 29 Aug 2010 17:36:24 -0400, Simen kjaeraas <simen.kjaras@gmail.com> wrote:
>>
>>> Is it possible to make a function return dependent upon the constancy of the this reference?
>>>
>>> i.e. this:
>>>
>>> struct foo {
>>>     int n;
>>>     inout( ref int ) getn( ) inout {
>>>         return n;
>>>     }
>>> }
>>
>> Yes.  That is the bread-and-butter usage for inout.
>>
>> Although inout is currently horribly broken.
>
> So horribly broken that example does not work at all, or is that just me?
>
> This is my code, verbatim:
>
> //////////////////////////
> module foo;
>
> struct bar {
>      int n;
>      ref inout( int ) getN( ) inout {
>          return n;
>      }
> }
>
> void main( ) {
> }
> //////////////////////////
>
> And it gives this message:
>
> foo.d(5): Error: inout on return means inout must be on a parameter as
> well for inout inout(int)()

Yes, horribly broken means does not work in almost all cases :)  You should defer using inout until it is fixed.  As of now, it's unusable (Walter is aware and has it on his TODO list).

Please vote for bug http://d.puremagic.com/issues/show_bug.cgi?id=3748

-Steve