[Issue 8882] map, filter, iota and zip in pure (and nothrow) functions

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jan 14 03:16:37 PST 2014


https://d.puremagic.com/issues/show_bug.cgi?id=8882



--- Comment #2 from bearophile_hugs at eml.cc 2014-01-14 03:16:34 PST ---
The situation has now improved:


import std.algorithm: map, filter;
import std.range: iota, zip;
void main() pure nothrow {
    foreach (_; map!q{a * a}([1, 2, 3])) {}
    foreach (_; filter!q{ a > 1 }([1, 2, 3])) {}
    foreach (_; iota(1, 10, 2)) {}
    foreach (_; zip([1, 2, 3], [10, 20, 30])) {}
}


test.d(6): Error: 'std.range.iota!(int, int, int).iota' is not nothrow
test.d(7): Error: 'std.range.Zip!(int[], int[]).Zip.empty' is not nothrow
test.d(7): Error: 'std.range.Zip!(int[], int[]).Zip.popFront' is not nothrow
test.d(3): Error: function 'D main' is nothrow yet may throw


zip can throw because of StoppingPolicy.requireSameLength, and iota(x,y,z)
throws when z can be 0. iota(x) and iota(x,y) are nothrow.

I think the problem with zip() can be solved introducing an api change, or
adding a new zip overload that takes StoppingPolicy as first template argument.

Fixing iota(x,y,z) is less easy. z is often a value known at compile time, so
in theory a new version of iota!z(x, y) can be nothrow at run-time.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list