How much to do

kennytm kennytm at gmail.com
Thu Oct 6 23:58:36 PDT 2011


bearophile <bearophileHUGS at lycos.com> wrote:
> Recently lot of work has being done about "inout", and I think it is now usable in D2.
> 
> So this has made me ask how much needs to be done (in D language and/or
> Phobos) to allow the correct compilation of exactly this useless demo
> program (I think it is correct):
> 
> 
> import std.algorithm, std.range, std.array;
> auto foo(in int[] data) pure {
>     immutable int n = count!q{ a % 2 == 1 }(data);
>     return map!q{ a * 2 }([n, n+1, n+2]);
> }
> void main() {
>     auto a = array(iota(10));
>     assert(equal(foo(a), [10, 12, 14]));
> }
> 
> 
> Currently count can't digest a const array and that map isn't pure. It
> runs if you remove "in" and "pure".
> 
> Once this program compiles I think std.algorithm becomes significantly more usable.
> 
> Bye,
> bearophile

Allow a template argument to treat a const(T[]) as a const(T)[] is a
different and a known problem IIRC.


More information about the Digitalmars-d mailing list