looking for V[string] workarounds
Can the following be made to build and run, but keep the intent of what is shown. I realize it touches on several bugs related to const, postblit, and map - but I'm having trouble finding the magic combination. The idea is simply have assets store multiple series of data in a map indexed by the asset name. Thanks, Dan import std.stdio; struct Series { // REQUIRED - need to have no aliasing this(this) { data = data.dup; } private double[] data; } struct Assets { this(this) { itemToSeries.dup; } // REQUIRED - want ctor to dup arg to ensure no aliasing this(const(Series[string]) source) { itemToSeries = source.dup; } private Series[string] itemToSeries; } void main() { auto data = [ house : Series([1,2,3.0])]; auto assets = Assets(data); writeln(assets); }
Re: looking for V[string] workarounds
On 03/20/2013 07:34 AM, Dan wrote: Can the following be made to build and run, but keep the intent of what is shown. I realize it touches on several bugs related to const, postblit, and map - but I'm having trouble finding the magic combination. The idea is simply have assets store multiple series of data in a map indexed by the asset name. Thanks, Dan import std.stdio; struct Series { // REQUIRED - need to have no aliasing this(this) { data = data.dup; } private double[] data; } struct Assets { this(this) { itemToSeries.dup; } // REQUIRED - want ctor to dup arg to ensure no aliasing this(const(Series[string]) source) { The code compiles with 2.062 and an earlier version of 2.063 if you accept letting go of const-correctness there: this(Series[string] source) { itemToSeries = source.dup; } private Series[string] itemToSeries; } void main() { auto data = [ house : Series([1,2,3.0])]; auto assets = Assets(data); writeln(assets); } Ali
Re: looking for V[string] workarounds
On Wednesday, 20 March 2013 at 17:11:02 UTC, Ali Çehreli wrote: The code compiles with 2.062 and an earlier version of 2.063 if you accept letting go of const-correctness there: this(Series[string] source) { Thanks Ali. But, removing const there then requires non-const instances to be passed in, due to const transitivity. So that requirement would ripple a change to all already const correct instances to now need to flip to non-const. I'm looking for a const correct solution. It should be doable ... I just have had no luck with it. Thanks Dan
Re: looking for V[string] workarounds
On 03/20/2013 10:24 AM, Dan wrote: On Wednesday, 20 March 2013 at 17:11:02 UTC, Ali Çehreli wrote: The code compiles with 2.062 and an earlier version of 2.063 if you accept letting go of const-correctness there: this(Series[string] source) { Thanks Ali. But, removing const there then requires non-const instances to be passed in, due to const transitivity. So that requirement would ripple a change to all already const correct instances to now need to flip to non-const. I'm looking for a const correct solution. It should be doable ... I just have had no luck with it. In that case, brute force to the rescue (nc stands for non-const): :) this(const(Series[string]) source) { auto nc_source = cast(Series[string])source; itemToSeries = nc_source.dup; } Ali
Re: looking for V[string] workarounds
On Wednesday, 20 March 2013 at 17:44:16 UTC, Ali Çehreli wrote: In that case, brute force to the rescue (nc stands for non-const): :) this(const(Series[string]) source) { auto nc_source = cast(Series[string])source; itemToSeries = nc_source.dup; } Wow - that worked. Thanks! I hope it is safe.