Bug 8879 – std.range function should to be usable in a pure (and sometimes nothrow) situations
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-10-23T15:32:00Z
Last change time
2012-10-24T11:16:24Z
Assigned to
nobody
Creator
bioinfornatics
Comments
Comment #0 by bioinfornatics — 2012-10-23T15:32:40Z
Code below fail when using pure with both dmd/ldc dmdfe 2.060
___________________________________________
This gives:
/home/c135/c554.d(6): Error: pure function 'square' cannot call impure function 'zip'
/home/c135/c554.d(6): Error: pure function 'square' cannot call impure function 'empty'
/home/c135/c554.d(6): Error: pure function 'square' cannot call impure function 'popFront'
/home/c135/c554.d(6): Error: pure function 'square' cannot call impure function 'front'
---------
import std.range;
import std.stdio;
pure uint square( in int[] x, in int[] y ){
uint result = 0;
foreach( item; zip( x, y ) )
result += item[0] * item[1];
return result;
}
int main(){
int[3] a = [0,1,2];
int[3] b = [1,2,3];
writefln( "Square of %s with %s give %u", a, b, square( a, b ) );
return 0;
}
___________________________________________
Bearophile code
___________________________________________
This gives:
test.d(3): Error: pure function 'main' cannot call impure function 'iota'
---------
import std.range: iota;
void main() pure {
iota(10);
}
___________________________________________
This gives:
test.d(4): Error: pure function 'main' cannot call impure function 'map'
test.d(4): Error: map is not nothrow
test.d(2): Error: function D main 'main' is nothrow yet may throw
---------
import std.algorithm: map;
void main() pure nothrow {
int[] data = [1, 2, 3];
auto r = map!q{a * a}(data);
}
___________________________________________
Comment #1 by bioinfornatics — 2012-10-24T11:16:24Z
*** This issue has been marked as a duplicate of issue 8882 ***