Using in as a parameter qualifier

Ali Çehreli acehreli at yahoo.com
Fri May 31 18:15:07 PDT 2013


On 05/31/2013 04:45 PM, Shriramana Sharma wrote:

 > And again, sorry if I'm being dumb, but is the proposed inout syntax
 > intended to fix this problem or some other problem?

Think of 'inout' as a placeholder for one of the following three:

- const
- immutable
- (no const, nor immutable)

inout is deduced at call time and all of the inouts inside a function 
and even the return type become the qualifier of the argument:

inout(int)[] firstHalf(inout(int)[] a)
{
     return a[0..$/2];
}

void main()
{
     int[] m;
     const(int)[] c;
     immutable(int)[] i;

     assert(is (typeof(firstHalf(m)) == int[]));
     assert(is (typeof(firstHalf(c)) == const(int)[]));
     assert(is (typeof(firstHalf(i)) == immutable(int)[]));
}

That is a very handy feature for exactly situations like the above.

 > why did DConf *this year* have a talk on this issue?!

The previous DConf was in 2007. It will be a yearly event from now on.

Ali



More information about the Digitalmars-d-learn mailing list