Re: Class Initialization

2012-02-01 Thread Vijay Nayar
The basic idea is that in D, any statically identifiable information (known at compile-time), can be used to assign class members as they are declared. Any time a new object is created, it will take those default values specified for its members. This is a small example demonstrating

Assigning to char[N]

2012-02-01 Thread Ali Çehreli
import std.stdio; void main() { char[100] a = old content; a = new content; } The program above causes an exception to be thrown: object.Exception@src/rt/arraycat.d(31): lengths don't match for array copy I admit that a fixed-length char array is not really a string. But assuming

Re: Assigning to char[N]

2012-02-01 Thread bearophile
Ali Çehreli: what is the best way of modifying that array? In your code it's the definition too that throws an exception: void main() { char[100] a = old content; } This works, but it's not nice: import std.stdio; void main() { char[100] a; string s1 = old content; a[0 ..

Re: Assigning to char[N]

2012-02-01 Thread Ali Çehreli
On 02/01/2012 03:14 PM, bearophile wrote: Ali Çehreli: what is the best way of modifying that array? In your code it's the definition too that throws an exception: Of course! I need sleep. :( I also failed to mention that the rest of the characters should be '\0' filled too but it's not a

Re: Assigning to char[N]

2012-02-01 Thread bearophile
Ali: a[one.length .. $] = '\0'; Is DMD able to optimize that string literal away? (Some assembly may be required). // copy(a, new content); // fill(a, new content); // insertInPlace(a, new content); // // Those do not work with errors similar to this:

Re: Assigning to char[N]

2012-02-01 Thread Andrej Mitrovic
OT: Just saw fill() by accident and something caught my eye: char[100] a; fill(a[], bla); // fail, ok int[100] a; fill(a[], bla); // works It could be a constraint issue. To bugzilla?

Re: Assigning to char[N]

2012-02-01 Thread Ali Çehreli
On 02/01/2012 04:34 PM, bearophile wrote: Ali: a[one.length .. $] = '\0'; Is DMD able to optimize that string literal away? (Some assembly may be required). I sure hope so. one.length should be a compile time constant. // copy(a, new content); // fill(a, new content);

Re: Assigning to char[N]

2012-02-01 Thread Ali Çehreli
On 02/01/2012 04:24 PM, Andrej Mitrovic wrote: OT: Just saw fill() by accident and something caught my eye: char[100] a; fill(a[], bla); // fail, ok int[100] a; fill(a[], bla); // works It could be a constraint issue. Although bla is an array of char, it is a range of dchar; and dchar