Re: void initialization vs alignment holes

2010-03-06 Thread strtr
BCS Wrote: > IIRC zero filling a block is likely cheaper that zero filling holes in it. > I'd avoid "=void" unless you know you will be copying structs into the space > (that will copy the holes as well). And unless you will never compare the struct, as the garbage bits will also be compared. I

Re: void initialization vs alignment holes

2010-03-06 Thread BCS
Hello Strtr, Suppose I'd still would like to use void optimizations, how do you clear the holes manually? IIRC zero filling a block is likely cheaper that zero filling holes in it. I'd avoid "=void" unless you know you will be copying structs into the space (that will copy the holes as well

Re: void initialization vs alignment holes

2010-03-06 Thread strtr
bearophile Wrote: > strtr: > > > I suspect this isn't the case for void initialization; if my struct has > > some alignment hole I better not void initialize it if ever I want to > > compare it with something. > > Is this correct? > > That has to be correct. Might this be worth an explicit men

Re: void initialization vs alignment holes

2010-03-06 Thread BCS
Hello Strtr, BCS Wrote: Hello Strtr, Would you ever have an alignment hole if all the struct contains are basic types(excluding bool)? real, char[n], byte[n] and short[m] (for n%4 != 0 and m%2 != 0) might be an issue. Sounds logical, thanks! I don't actually *know* those will be a pro

Re: void initialization vs alignment holes

2010-03-06 Thread strtr
BCS Wrote: > Hello Strtr, > > > Would you ever have an alignment hole if all the struct contains are > > basic types(excluding bool)? > > real, char[n], byte[n] and short[m] (for n%4 != 0 and m%2 != 0) might be > an issue. > Sounds logical, thanks!

Re: void initialization vs alignment holes

2010-03-06 Thread BCS
Hello Strtr, Would you ever have an alignment hole if all the struct contains are basic types(excluding bool)? real, char[n], byte[n] and short[m] (for n%4 != 0 and m%2 != 0) might be an issue. -- ... <

Re: void initialization vs alignment holes

2010-03-06 Thread bearophile
strtr: > I suspect this isn't the case for void initialization; if my struct has some > alignment hole I better not void initialize it if ever I want to compare it > with somthing. > Is this correct? That has to be correct. > Would you ever have an alignment hole if all the struct contains ar

void initialization vs alignment holes

2010-03-06 Thread strtr
This is probably going a bit above my head, but "the existence of alignment holes in the objects is accounted for, usually by setting them all to 0 upon initialization" I suspect this isn't the case for void initialization; if my struct has some alignment hole I better not void initialize it if

Re: interface problem

2010-03-06 Thread div0
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Trass3r wrote: >> Cast the instance to the base class and call the method? >> > > Surprisingly this does compile. > What are the rules for casting between classes? I don't think there are any rules as such. Casting in D is not well specified. Betwe

Re: interface problem

2010-03-06 Thread Trass3r
> Cast the instance to the base class and call the method? > Surprisingly this does compile. What are the rules for casting between classes?

Re: range properties that work in foreach

2010-03-06 Thread Jesse Phillips
Good range documentation comes from: http://digitalmars.com/d/2.0/phobos/std_range.html foreach only requires an Input Range.

Re: D2: std.algorithm.find, but get part before what you were searching for

2010-03-06 Thread Nick Sabalausky
"Lars T. Kyllingstad" wrote in message news:hmnu5l$31j...@digitalmars.com... > > 3. It's sometimes unclear which symbols are members of a class/struct > and which are module-level symbols. Tango's API documentation is better > in this regard, since it has the symbol tree on the left-hand sid

Re: opEquals among types

2010-03-06 Thread Jacob Carlborg
On 3/5/10 21:04, bearophile wrote: This D2 program compiles and works correctly: import std.c.stdio: printf; auto add(T1, T2)(T1 x, T2 y) { if (!is(T1 == T2)) printf("Different types\n"); return x + y; } void main() {} But do you know why D2 needs that is() there? Can't it b

Re: interface problem

2010-03-06 Thread Jacob Carlborg
On 3/6/10 13:39, Trass3r wrote: I got 2 classes which both (indirectly) inherit from a common base class and implement a certain interface I. Now I need to pass that interface to a function and need to call a function inherited from the base class inside. Naturally that function is not presen

Re: Static attributes aren' immutable

2010-03-06 Thread bearophile
div0: > Yeah, I *never* access static vars through an instance, > I always use the class name. > > Somebody want to post in the main group? It seems there are few people that agree with you, but Walter has not answered about this yet, so you can ask him his opinion. I like to use a tidy language

Re: interface problem

2010-03-06 Thread bearophile
Trass3r: > I got 2 classes which both (indirectly) inherit from a common base class and > implement a certain interface I. When possible show an example. You can fill/fix the following code to create an example of your problem: interface IFoo { void foo(); } class Base { void foo() {}

interface problem

2010-03-06 Thread Trass3r
I got 2 classes which both (indirectly) inherit from a common base class and implement a certain interface I. Now I need to pass that interface to a function and need to call a function inherited from the base class inside. Naturally that function is not present in the interface and thus can't

Re: range properties that work in foreach

2010-03-06 Thread Lars T. Kyllingstad
Lars T. Kyllingstad wrote: Michael Rynn wrote: On the D2 online pages (http://www.digitalmars.com/d/2.0/statement.html#ForeachStatement)there is Foreach over Structs and Classes with Ranges My question is , is there a working example of foreach ( e ; range )? Iteration over struct and cla

Re: range properties that work in foreach

2010-03-06 Thread Lars T. Kyllingstad
Michael Rynn wrote: On the D2 online pages (http://www.digitalmars.com/d/2.0/statement.html#ForeachStatement)there is Foreach over Structs and Classes with Ranges My question is , is there a working example of foreach ( e ; range )? Iteration over struct and class objects can be done wit

range properties that work in foreach

2010-03-06 Thread Michael Rynn
On the D2 online pages (http://www.digitalmars.com/d/2.0/statement.html#ForeachStatement)there is Foreach over Structs and Classes with Ranges My question is , is there a working example of foreach ( e ; range )? Iteration over struct and class objects can be done with ranges, which means