digitalmars.D.learn - looking for V[string] workarounds
- Dan (26/26) Mar 20 2013 Can the following be made to build and run, but keep the intent
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (5/31) Mar 20 2013 The code compiles with 2.062 and an earlier version of 2.063 if you
- Dan (9/12) Mar 20 2013 Thanks Ali. But, removing const there then requires non-const
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (7/18) Mar 20 2013 In that case, brute force to the rescue (nc stands for non-const): :)
- Dan (2/8) Mar 20 2013 Wow - that worked. Thanks! I hope it is safe.
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); }
Mar 20 2013
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
Mar 20 2013
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
Mar 20 2013
On 03/20/2013 10:24 AM, Dan wrote:On Wednesday, 20 March 2013 at 17:11:02 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; } AliThe 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.
Mar 20 2013
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.
Mar 20 2013