Comment #0 by bearophile_hugs — 2012-12-17T21:56:35Z
This works correctly:
import std.algorithm;
void main() {
auto array = [40, 20, 10, 30];
array = remove!"a <= 20"(array); // OK
assert(array == [40, 30]);
}
This doesn't compile:
import std.algorithm;
void main() {
auto array = [40, 20, 10, 30];
auto p = (int x) => x <= 20;
array = remove!p(array); // Error.
assert(array == [40, 30]);
}
DMD 2.061alpha gives:
test.d(5): Error: variable p cannot be read at compile time
While a module-level function:
import std.algorithm;
bool p(int x) { return x <= 20; }
void main() {
auto array = [40, 20, 10, 30];
array = remove!p(array);
assert(array == [40, 30]);
}
DMD gives:
...\dmd2\src\phobos\std\algorithm.d(6843): Error: not a property p
...\dmd2\src\phobos\std\algorithm.d(6949): Error: not a property p
Comment #1 by lt.infiltrator — 2015-12-02T16:08:51Z
The last example works in 2.069.
The second example looks to be a compiler issue rather than a phobos issue, so I'm changing the component to dmd.
Comment #2 by trikkuz — 2019-09-17T15:05:10Z
In my opinion the second example correctly fails.
Indeed p can't be read at compile time. If you replace auto with enum or immutable the example works fine.
The third example works correctly so I guess we can close this issue.