Re: Some strange parameter deduction problems in opOpAssign and opBinary

2012-09-02 Thread Philippe Sigaud
Problem solved: alias Vec!(T, size) V; // This works fine ref V opOpAssign(string op)(V rhs) { mixin(array[] ~op~= rhs.array[];); return this; } Inside a template, you can refer to the current (local) instantiation by its name only. Try using 'Vec' instead of V.

Re: Some strange parameter deduction problems in opOpAssign and opBinary

2012-09-02 Thread Ali Çehreli
On 09/01/2012 10:08 PM, Ivan Agafonov wrote: On Sunday, 2 September 2012 at 04:10:39 UTC, Ivan Agafonov wrote: There are 3 separated versions of opOpAssign first version must be the same as the second for Vec!(sometype, 4) why it doesn't work? Simplified code: struct Vec(T, uint size) {

Re: trying setjmp or throwing from signal handler crashes on OSX

2012-09-02 Thread Jacob Carlborg
On 2012-09-02 02:37, timotheecour wrote: Is there any way to get setjmp to work in a D program on OSX? I just get a segfault whenever it is called. I'm just trying to recover from a signal handler. Related questions: why is signal handler nothrow? I saw this related thread but it seems linux

Re: Assigning global and static associative arrays

2012-09-02 Thread monarch_dodra
On Saturday, 1 September 2012 at 09:16:30 UTC, Jonathan M Davis wrote: [SNIP] so it looks like not only do all instances of the same string enum use the same memory, but another enum with the same string literal shares it as well. So, only one is allocated. And on Linux at least, as I

How to call one anonymous function from another

2012-09-02 Thread Adil
I have an SCGI server that needs to run a user defined request handler, but i can't get it to run void SCGIServer(ushort port, void function(const Request, Socket) handler) { GenericServer(port, function void(const byte[] request, Socket connection){ auto r =

Re: Some strange parameter deduction problems in opOpAssign and opBinary

2012-09-02 Thread Ivan Agafonov
On Sunday, 2 September 2012 at 07:44:12 UTC, Philippe Sigaud wrote: Problem solved: alias Vec!(T, size) V; // This works fine ref V opOpAssign(string op)(V rhs) { mixin(array[] ~op~= rhs.array[];); return this; } Inside a template, you can refer to the current

Re: Assigning global and static associative arrays

2012-09-02 Thread Timon Gehr
On 09/02/2012 03:45 PM, monarch_dodra wrote: On Saturday, 1 September 2012 at 09:16:30 UTC, Jonathan M Davis wrote: [SNIP] so it looks like not only do all instances of the same string enum use the same memory, but another enum with the same string literal shares it as well. So, only one is

Re: Assigning global and static associative arrays

2012-09-02 Thread monarch_dodra
On Sunday, 2 September 2012 at 16:20:16 UTC, Timon Gehr wrote: On 09/02/2012 03:45 PM, monarch_dodra wrote: FYI: I get the exact same behavior in Windows. Not that it matters, but it sounded like you were asking. I'm a bit confused now though: Why would someone want to use an enum when they

Re: Assigning global and static associative arrays

2012-09-02 Thread Timon Gehr
On 09/02/2012 06:26 PM, monarch_dodra wrote: On Sunday, 2 September 2012 at 16:20:16 UTC, Timon Gehr wrote: On 09/02/2012 03:45 PM, monarch_dodra wrote: FYI: I get the exact same behavior in Windows. Not that it matters, but it sounded like you were asking. I'm a bit confused now though: Why

Re: How to call one anonymous function from another

2012-09-02 Thread Adil
Answer: Read delegates! *slap on forehead* On Sunday, 2 September 2012 at 14:46:13 UTC, Adil wrote: I have an SCGI server that needs to run a user defined request handler, but i can't get it to run void SCGIServer(ushort port, void function(const Request, Socket) handler) {

Re: Assigning global and static associative arrays

2012-09-02 Thread Ali Çehreli
On 09/02/2012 06:45 AM, monarch_dodra wrote: Is there *any* scenario where one would choose the enum over the static immutable...? That's a good question. If Timon Gehr's example is the only difference, I wonder whether the guidelines that I had come up with are still valuable? I would

Re: Assigning global and static associative arrays

2012-09-02 Thread Philippe Sigaud
On Sun, Sep 2, 2012 at 8:50 PM, Ali Çehreli acehr...@yahoo.com wrote: On 09/02/2012 06:45 AM, monarch_dodra wrote: Is there *any* scenario where one would choose the enum over the static immutable...? Due to Jonathan advice, I converted a part of my code (enum = static this). At runtime, I

Re: Recipe and best practice for accessing COM

2012-09-02 Thread newToCOM
Thanks for your replies! I'm trying to accomplish this: http://msdn.microsoft.com/en-us/library/windows/apps/dd535473.aspx Using win32 and directx.d2d1, I got this far: --- ... int WinMain( ... ) { ... } int myWinMain( ... ) { ... } LRESULT WndProc ( ... ) { ... case WM_CREATE:

Re: trying setjmp or throwing from signal handler crashes on OSX

2012-09-02 Thread timotheecour
Since this is kind of low level I would guess you cannot just take a Linux guide and have it work on Mac OS X. Both are Posix but at this low level the differences between the platforms start to show up. BTW, I get Error: undefined identifier ucontext_t when compiling that file on Mac OS X.

Can i rewrite methods in one line?

2012-09-02 Thread Ivan Agafonov
struct Vector(T, uint size) { static assert(size = 2 size = 4); static assert(__traits(isFloating, T); /// Vector components union { T[size] array = 0; struct { static if(size

Re: Assigning global and static associative arrays

2012-09-02 Thread Ali Çehreli
On 09/02/2012 12:24 PM, Philippe Sigaud wrote: On Sun, Sep 2, 2012 at 8:50 PM, Ali Çehreliacehr...@yahoo.com wrote: On 09/02/2012 06:45 AM, monarch_dodra wrote: Is there *any* scenario where one would choose the enum over the static immutable...? Due to Jonathan advice, I converted a part

Re: Can i rewrite methods in one line?

2012-09-02 Thread Ali Çehreli
In general, yes, you can construct and return at the same time. As you said, in a language like D where source code is almost always visible, the compiler can apply many optimization techniques. However, some of your operators ended up having semantic differences. opOpAssign used to return a

Re: Can i rewrite methods in one line?

2012-09-02 Thread Ivan Agafonov
On Monday, 3 September 2012 at 02:40:09 UTC, Ali Çehreli wrote: In general, yes, you can construct and return at the same time. As you said, in a language like D where source code is almost always visible, the compiler can apply many optimization techniques. However, some of your operators

Re: Can i rewrite methods in one line?

2012-09-02 Thread Ivan Agafonov
Yeah! I did it! How about this solution? What do you think? static assert(size = 2 size = 4); static assert(__traits(isFloating, T)); /// Vector components union { T[size] array = 0; struct {

Re: Can i rewrite methods in one line?

2012-09-02 Thread Ali Çehreli
On 09/02/2012 07:57 PM, Ivan Agafonov wrote: ref Vector opOpAssign(string op) (T rhs) if(op == + || op == - || op == * || op == /) { mixin(array[] ~op~= rhs;); return this; } But i can't write something like this: return Vector(mixin(array[] ~op~= rhs.array[])); You meant it for

Re: Can i rewrite methods in one line?

2012-09-02 Thread Ivan Agafonov
Note that opBinary operators uses op= instead of op : Vector opBinary(string op) (Vector rhs) if(isMathOp(op)) { return Vector(mixin(array.dup[] ~op~= rhs.array[])); } Vector opBinary(string op) (T rhs) if(isMathOp(op)) { return Vector(mixin(array.dup[] ~op~= rhs)); }