inout based on this reference?

Steven Schveighoffer schveiguy at yahoo.com
Mon Aug 30 11:32:18 PDT 2010


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

> Steven Schveighoffer <schveiguy at yahoo.com> wrote:
> 0123456789012345678901234567890123456789012345678901234567890123456789012
>> On Sun, 29 Aug 2010 17:36:24 -0400, Simen kjaeraas  
>> <simen.kjaras at 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


More information about the Digitalmars-d-learn mailing list