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
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
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 ..
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
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:
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?
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);
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