digitalmars.D - How much to do
- bearophile (15/15) Oct 06 2011 Recently lot of work has being done about "inout", and I think it is now...
- kennytm (3/28) Oct 06 2011 Allow a template argument to treat a const(T[]) as a const(T)[] is a
- bearophile (4/6) Oct 07 2011 I don't fully understand the meaning of your answer, but I didn't want t...
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
Oct 06 2011
bearophile <bearophileHUGS 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, bearophileAllow a template argument to treat a const(T[]) as a const(T)[] is a different and a known problem IIRC.
Oct 06 2011
kennytm:Allow a template argument to treat a const(T[]) as a const(T)[] is a different and a known problem IIRC.I don't fully understand the meaning of your answer, but I didn't want to imply that those two problems are new or unknown. Bye, bearophile
Oct 07 2011