Re: constructor instead of opCall for an instance of a template alias

2012-11-24 Thread Rob T
On Saturday, 24 November 2012 at 20:34:39 UTC, comco wrote: I have the following snippet: struct A(alias Method) { string s; this(Method method) { method(s); // 5 } } struct B { this(int i) { } void opCall(string s) { } } void main() { A!B(B(0)); } This code

Re: Returning const ref (structs) in D

2012-11-24 Thread Rob T
On Saturday, 24 November 2012 at 22:01:32 UTC, Stian wrote: Is the compiler sophisticated enough that is it able to avoid the copying. For instance, if i have a struct Matrix4x4 a = node.getTransformation() and use a for whatever, but never alter it, will it be able to avoid the copy? What if i

Re: Can I call the default opAssign after overloading opAssign?

2012-11-24 Thread Rob T
On Saturday, 24 November 2012 at 20:47:17 UTC, Era Scarecrow wrote: This kind of behavior *really* needs to be documented in precise detail, it's rather critical to know. It IS documented. TDPL - pg. 248 [quote] Thanks for pointing out where the postblit stuff is documented. When I first st

Re: Can I call the default opAssign after overloading opAssign?

2012-11-24 Thread Dan
On Saturday, 24 November 2012 at 20:47:17 UTC, Era Scarecrow wrote: On Friday, 23 November 2012 at 22:31:46 UTC, Rob T wrote: That's VERY interesting indeed and originally I had no idea it would do this without a custom opAssign at each level. This kind of behavior *really* needs to be documen

Re: Returning const ref (structs) in D

2012-11-24 Thread Dan
On Saturday, 24 November 2012 at 22:01:32 UTC, Stian wrote: After reading that a couple of times it is a bit clearer, thank you. I need to wrap my head around this. I am working on a simple render/game engine, where, of course, vectors and matrices are flying around. Is the compiler sophistic

Re: Returning const ref (structs) in D

2012-11-24 Thread Stian
After reading that a couple of times it is a bit clearer, thank you. I need to wrap my head around this. I am working on a simple render/game engine, where, of course, vectors and matrices are flying around. Is the compiler sophisticated enough that is it able to avoid the copying. For instan

Re: Returning const ref (structs) in D

2012-11-24 Thread Jonathan M Davis
On Saturday, November 24, 2012 21:46:41 Stian wrote: > Okay, Im trying to wrap my head around how i can return a > reference from a class. > Lets say I have some class Foo that stores a struct Bar that > stores many bytes. > > In C, i would have a function > > const Bar & getBar(){return bar;} >

Re: Can I call the default opAssign after overloading opAssign?

2012-11-24 Thread Era Scarecrow
On Friday, 23 November 2012 at 22:31:46 UTC, Rob T wrote: That's VERY interesting indeed and originally I had no idea it would do this without a custom opAssign at each level. This kind of behavior *really* needs to be documented in precise detail, it's rather critical to know. It IS docume

Returning const ref (structs) in D

2012-11-24 Thread Stian
Okay, Im trying to wrap my head around how i can return a reference from a class. Lets say I have some class Foo that stores a struct Bar that stores many bytes. In C, i would have a function const Bar & getBar(){return bar;} In code, i could get a (const) reference to bar using const Bar & v

constructor instead of opCall for an instance of a template alias

2012-11-24 Thread comco
I have the following snippet: struct A(alias Method) { string s; this(Method method) { method(s); // 5 } } struct B { this(int i) { } void opCall(string s) { } } void main() { A!B(B(0)); } This code fails to compile with the following errors: test.d(5): Error:

Re: Converting a number to complex

2012-11-24 Thread Artur Skawina
On 11/24/12 12:30, Philippe Sigaud wrote: > > Unfortunately the is-expressions don't handle aliases properly, at least > with my old compiler here. So this does not work: > >template isTempInst(alias TEMPL, T) { > static if (is(T _ == TEMPL!CT, CT)) > enum i

Re: Converting a number to complex

2012-11-24 Thread Philippe Sigaud
On Sat, Nov 24, 2012 at 11:30 AM, Artur Skawina wrote: > On 11/24/12 08:27, Philippe Sigaud wrote: > > What's even nicer with an is() expr is that the introspection info is > accessible when used inside a static if. So with Artur's code, CT can be > seen inside the true branch of the static if. >

Re: Converting a number to complex

2012-11-24 Thread Artur Skawina
On 11/24/12 08:27, Philippe Sigaud wrote: > What's even nicer with an is() expr is that the introspection info is > accessible when used inside a static if. So with Artur's code, CT can be seen > inside the true branch of the static if. Actually, static-ifs do not create a scope, so 'CT' leaks a

Re: passing struct literals by reference (dmd 2.060, Windows)

2012-11-24 Thread Jonathan M Davis
On Saturday, November 24, 2012 02:11:23 Jonathan M Davis wrote: > On Saturday, November 24, 2012 10:59:24 Jack Applegame wrote: > > struct Foo { > > > >int a; > > > > } > > void modify(ref Foo foo) { > > > >foo.a++; > > > > } > > void main() { > > > >modify(Foo(1)); > > > > } > >

Re: passing struct literals by reference (dmd 2.060, Windows)

2012-11-24 Thread Jonathan M Davis
On Saturday, November 24, 2012 10:59:24 Jack Applegame wrote: > struct Foo { >int a; > } > void modify(ref Foo foo) { >foo.a++; > } > void main() { >modify(Foo(1)); > } > > Why compiler doesn't report error? So as struct literal "Foo()" > isn't a lvalue, it's impossible to pass it by r

passing struct literals by reference (dmd 2.060, Windows)

2012-11-24 Thread Jack Applegame
struct Foo { int a; } void modify(ref Foo foo) { foo.a++; } void main() { modify(Foo(1)); } Why compiler doesn't report error? So as struct literal "Foo()" isn't a lvalue, it's impossible to pass it by reference. Isn't it? Just like string or numeric literals.