www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Problem with take(map())

reply bearophile <bearophileHUGS lycos.com> writes:
D2 code:


import std.stdio, std.algorithm, std.range;
auto foo(int p) {
    return map!((int n){ return p; })(iota(3));
}
void main() {
    writeln(take(foo(2), 20));
}


To me it prints:
[4221068, 4221068, 4221068]

Do you know if this is a known bug/problem?

Bye,
bearophile
Jul 29 2011
parent "Daniel Murphy" <yebblies nospamgmail.com> writes:
The problem is the parameter p is not being heap allocated.  I'm fairly sure 
it's already in bugzilla, something about failing to detect escaping 
references with alias parameters.

"bearophile" <bearophileHUGS lycos.com> wrote in message 
news:j0vhod$t87$1 digitalmars.com...
 D2 code:


 import std.stdio, std.algorithm, std.range;
 auto foo(int p) {
    return map!((int n){ return p; })(iota(3));
 }
 void main() {
    writeln(take(foo(2), 20));
 }


 To me it prints:
 [4221068, 4221068, 4221068]

 Do you know if this is a known bug/problem?

 Bye,
 bearophile 

Jul 30 2011