digitalmars.D.learn - Implicit conversion from const to mutable
- Balagopal Komarath (11/11) Aug 17 2017 Is it possible to make structs containing slices support implicit
- Steven Schveighoffer (22/24) Aug 17 2017 This should "work". I don't think your static assert will pass, but the
- Balagopal Komarath (3/5) Aug 17 2017 Thanks. But, isn't my static assert testing for exactly this?
- Steven Schveighoffer (7/14) Aug 17 2017 I might be wrong. It's hard to tell, because the compiler doesn't work
Is it possible to make structs containing slices support implicit conversion from const to mutable? I tried adding a postblit that dupes the member 'a'. That didn't work. struct A { int[] a; } void main() { static assert (is(const(A) : A)); // fails }
Aug 17 2017
On 8/17/17 3:24 PM, Balagopal Komarath wrote:Is it possible to make structs containing slices support implicit conversion from const to mutable?This should "work". I don't think your static assert will pass, but the main function below should run. struct A { int[] a; A dup() const { return A(a.dup); } alias dup this; } void main() { const A a; A a2 = a; } However, this results in a segfault as far back as 2.064, and 2.063 doesn't seem to like it (but maybe because alias this wasn't supported? I'm not sure). https://issues.dlang.org/show_bug.cgi?id=17759 -Steve
Aug 17 2017
On Thursday, 17 August 2017 at 20:22:09 UTC, Steven Schveighoffer wrote:This should "work". I don't think your static assert will pass, but the main function below should run.Thanks. But, isn't my static assert testing for exactly this?
Aug 17 2017
On 8/17/17 5:28 PM, Balagopal Komarath wrote:On Thursday, 17 August 2017 at 20:22:09 UTC, Steven Schveighoffer wrote:I might be wrong. It's hard to tell, because the compiler doesn't work with the struct itself. If I change the alias this to something else, your form of conversion does work. But the compiler may recognize that specific form and still disallow it. IMO, that would be a further bug. -SteveThis should "work". I don't think your static assert will pass, but the main function below should run.Thanks. But, isn't my static assert testing for exactly this?
Aug 17 2017