Re: const after initialization / pointers, references and values

2014-08-22 Thread Vicente via Digitalmars-d
If the foreach loop is replaced by: foreach(ref node_ref; np) Then it works like a charm!

Re: const after initialization / pointers, references and values

2014-08-22 Thread Vicente via Digitalmars-d
On Friday, 22 August 2014 at 20:12:39 UTC, Wyatt wrote: I poked it a bit and came out with this. I _think_ it's working as expected: ... auto ref opSlice(){return nodes[];}; ... -Wyatt Assuming it's working as expected, that is exactly what I was looking for! But the following cod

Re: const after initialization / pointers, references and values

2014-08-22 Thread Vicente via Digitalmars-d
Indeed the ref can be applied to the return type: http://dlang.org/function.html#ref-functions So, does the following code copy any data from "nodes"? If that is the case this solution avoids the "class" storage, avoids pointers and "nodes" is encapsulated as read-only, that's great. The progra

Re: const after initialization / pointers, references and values

2014-08-22 Thread Vicente via Digitalmars-d
First of all thanks for your replies, they are useful. @Philippe: A pure function is ok for initializing "default_nodes" but not for "nodes" because a pure function can't read a file. The "static this" has the problem it needs know the initializer at compile time but I wanted to choose the init

const after initialization / pointers, references and values

2014-08-20 Thread Vicente via Digitalmars-d
Hello, I have some questions on how to do a few things in D. Below is an example code on which the questions are based. I need read access to a big and complex (i.e.: nested) data structure of type "Node". But first it needs to be initialized. That can be done with a default initializer or from a