Bug 12742 – @nogc @safe std.algorithm.remove

Status
RESOLVED
Resolution
WORKSFORME
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-05-13T10:17:00Z
Last change time
2016-06-08T04:52:38Z
Keywords
safe
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2014-05-13T10:17:20Z
void main() @nogc { import std.algorithm; int[3] a = [1, 2, 3]; int[] b = a[].remove!(SwapStrategy.unstable)(0); } DMD 2.066alpha gives: temp.d(4,49): Error: @nogc function 'D main' cannot call non-@nogc function 'std.algorithm.remove!(cast(SwapStrategy)0, int[], int).remove'
Comment #1 by sinkuupump — 2014-12-06T11:06:57Z
Seems to work in DMD 2.066.0 or later.
Comment #2 by bearophile_hugs — 2014-12-06T11:47:50Z
import std.algorithm: remove; auto a = [1]; void main() @nogc { a = a.remove(0); } dmd 2.067alpha: test.d(4,17): Error: @nogc function 'D main' cannot call non-@nogc function 'std.algorithm.remove!(cast(SwapStrategy)2, int[], int).remove'
Comment #3 by bearophile_hugs — 2014-12-06T12:02:14Z
It's also not @safe: import std.algorithm: remove, SwapStrategy; struct Foo {} void main() @safe { Foo[] foos; foos.remove!(x => true, SwapStrategy.unstable); foos.remove!(x => true); } test.d(5,9): Error: safe function 'D main' cannot call system function 'test.main.remove!((x) => true, cast(SwapStrategy)0, Foo[]).remove' test.d(6,9): Error: safe function 'D main' cannot call system function 'test.main.remove!((x) => true, cast(SwapStrategy)2, Foo[]).remove'
Comment #4 by bugzilla — 2016-06-08T04:52:38Z
Both the @nogc and @safe attributes work in the current version.