Thread overview | ||||||
---|---|---|---|---|---|---|
|
April 13, 2020 std.algorithm.sort with copy constructors | ||||
---|---|---|---|---|
| ||||
Hi! Consider the following code: --- import std; struct S { pure this(ref return scope const S rhs) nothrow @nogc { this.x = x; } int x; } void main() { S[] array = new S[10]; array.sort!("a.x < b.x", SwapStrategy.stable); } --- In this program, sort compiles only if the copy constructor is decorated with pure, nothrow and @nogc. This is very limiting. Is there a way to get rid of nothrow and @nogc on the copy constructor and still use sort? My actual use case, inefficient as it may be, is to sort structs that use copy constructors to enforce deep copies of their contents. So there's liberal use of .dup in them, which obviously is neither nothrow nor @nogc. Cheers, Gregor |
April 13, 2020 Re: std.algorithm.sort with copy constructors | ||||
---|---|---|---|---|
| ||||
Posted in reply to Gregor Mückl | On 4/13/20 9:27 AM, Gregor Mückl wrote: > import std; > > struct S { > pure this(ref return scope const S rhs) nothrow @nogc { > this.x = x; > } > > int x; > } > > void main() > { > S[] array = new S[10]; > array.sort!("a.x < b.x", SwapStrategy.stable); > } This is a bug in phobos. https://issues.dlang.org/show_bug.cgi?id=20732 Also went down a rabbit hole due to this: https://issues.dlang.org/show_bug.cgi?id=20733 -Steve |
April 13, 2020 Re: std.algorithm.sort with copy constructors | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On 4/13/20 10:24 AM, Steven Schveighoffer wrote: > This is a bug in phobos. > > https://issues.dlang.org/show_bug.cgi?id=20732 https://github.com/dlang/phobos/pull/7442 -Steve |
April 15, 2020 Re: std.algorithm.sort with copy constructors | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Monday, 13 April 2020 at 15:38:33 UTC, Steven Schveighoffer wrote:
> On 4/13/20 10:24 AM, Steven Schveighoffer wrote:
>> This is a bug in phobos.
>>
>> https://issues.dlang.org/show_bug.cgi?id=20732
>
> https://github.com/dlang/phobos/pull/7442
>
> -Steve
Sorry for sending you down that particular rabbit hole. And a big thank you for following through!
I worked around that problem in my use case, but it's good to see one a couple of bugs squashed. :)
|
Copyright © 1999-2021 by the D Language Foundation