[Issue 4571] Non-null class references/pointers
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Oct 1 14:26:04 PDT 2012
http://d.puremagic.com/issues/show_bug.cgi?id=4571
--- Comment #6 from bearophile_hugs at eml.cc 2012-10-01 14:26:20 PDT ---
A small program that shows three important things std.typecons.Nullable isn't
able to do:
import std.stdio, std.algorithm, std.typecons;
alias Nullable!(int, -1) Position;
void foo(int[] a, Position pos) /*nothrow*/ { // allow this to be nothrow
if (pos.isNull) {
return;
} else {
a[pos] = 10; // perform no nullness test here, optimization
}
}
void bar(int[] a, Position pos) {
a[pos] = 10; // compile-time error here?
}
void main() {
auto data = [1, 2, 3, 4, 5];
auto p = Position(countUntil(data, 7));
foo(data, p);
writeln(data);
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list