Re: Help translating C/C++ snippet to D

2012-07-03 Thread Tongzhou Li
On Tuesday, 3 July 2012 at 02:34:04 UTC, Dustin wrote: Hello, I'm trying to follow along with a C++ tutorial and translate it to D but I don't know C/C++ well enough to understand this #Define statement: #define ARRAY_COUNT( array ) (sizeof( array ) / (sizeof( array[0] ) * (sizeof( array ) !

Re: Problem about using struct

2012-06-25 Thread Tongzhou Li
On Monday, 25 June 2012 at 10:10:56 UTC, Kenji Hara wrote: On Monday, 25 June 2012 at 06:05:34 UTC, Tongzhou Li wrote: Hello! I'm learning D, and wrote some sample codes with D. I wrote: http://ideone.com/VY7ES It failed to compile; I got 2 errors: main.d(19): Error: constructor main.

Problem about using struct

2012-06-24 Thread Tongzhou Li
Hello! I'm learning D, and wrote some sample codes with D. I wrote: http://ideone.com/VY7ES It failed to compile; I got 2 errors: main.d(19): Error: constructor main.carry!(int,int,int,int,int).carry.this (int delegate(int, int _param_0, int _param_1, int _param_2) _f) is not callable usin

Re: Problem about multi-thread programming

2012-05-06 Thread Tongzhou Li
On Sunday, 6 May 2012 at 10:39:04 UTC, Chris Cain wrote: On Sunday, 6 May 2012 at 04:52:48 UTC, Tongzhou Li wrote: Thanks. Now it works fine with gdc, but still prints nothing with dmd. It seems that "cv[0].notify()" on line 29 affects nothing at all when using dmd2 :( I'm n

Re: Problem about multi-thread programming

2012-05-05 Thread Tongzhou Li
On Saturday, 5 May 2012 at 18:46:32 UTC, David Nadlinger wrote: On Saturday, 5 May 2012 at 08:45:21 UTC, Tongzhou Li wrote: I wrote: http://codepad.org/K4xQOREZ Besides the other things mentioned, you also need to lock the monitor associated with a condition before notifying/waiting (cf. a

Re: Problem about multi-thread programming

2012-05-05 Thread Tongzhou Li
On Saturday, 5 May 2012 at 17:03:00 UTC, Chris Cain wrote: On Saturday, 5 May 2012 at 09:28:34 UTC, Tongzhou Li wrote: On Saturday, 5 May 2012 at 09:16:04 UTC, Kagamin wrote: What's in console? object.Error: Access Violation Expected output: 123412

Re: Problem about multi-thread programming

2012-05-05 Thread Tongzhou Li
On Saturday, 5 May 2012 at 09:16:04 UTC, Kagamin wrote: What's in console? object.Error: Access Violation Expected output: 12341234123 PS: Line 13 should be: write(Idx);

Problem about multi-thread programming

2012-05-05 Thread Tongzhou Li
Hello everyone! I'm learning D and trying to write some sample code in D. I wrote: http://codepad.org/K4xQOREZ It compiles well with dmd 2.0.59, but I got an error when running: object.Error: Access Violation Any one help? Thanks.

Re: Problem about lambda expressions

2012-03-28 Thread Tongzhou Li
On Wednesday, 28 March 2012 at 10:17:15 UTC, Timon Gehr wrote: On 03/28/2012 10:28 AM, Tongzhou Li wrote: On Wednesday, 28 March 2012 at 08:22:25 UTC, Tongzhou Li wrote: I understood. But why it compiles instead of giving an error? What does the complier do when I write the wrong code? Oh

Re: Problem about lambda expressions

2012-03-28 Thread Tongzhou Li
On Wednesday, 28 March 2012 at 08:22:25 UTC, Tongzhou Li wrote: I understood. But why it compiles instead of giving an error? What does the complier do when I write the wrong code? Oh, I mean if I write the wrong code, what objectcode does the compiler generate? My English is not good, sorry.

Re: Problem about lambda expressions

2012-03-28 Thread Tongzhou Li
On Tuesday, 27 March 2012 at 15:21:57 UTC, Kenji Hara wrote: On Tuesday, 27 March 2012 at 13:42:30 UTC, Tongzhou Li wrote: Hello again! I'm learning D, and I encountered a problem. I tried this code: http://ideone.com/hkpT6 It works well. (Have no idea why codepad.org failed to compile

Re: Problem about lambda expressions

2012-03-28 Thread Tongzhou Li
On Tuesday, 27 March 2012 at 14:54:11 UTC, Artur Skawina wrote: On 03/27/12 15:52, Tongzhou Li wrote: Oh, I also tried: void seq_apply(Params..., Args...)(void delegate(Params) func, Args args) But I got a error: variadic template parameter must be last Does it mean that there can

Re: Problem about lambda expressions

2012-03-28 Thread Tongzhou Li
On Tuesday, 27 March 2012 at 14:12:38 UTC, dennis luehring wrote: Am 27.03.2012 15:52, schrieb Tongzhou Li: Oh, I also tried: void seq_apply(Params..., Args...)(void delegate(Params) func, Args args) But I got a error: variadic template parameter must be last Does it mean that there

Re: Problem about lambda expressions

2012-03-27 Thread Tongzhou Li
Oh, I also tried: void seq_apply(Params..., Args...)(void delegate(Params) func, Args args) But I got a error: variadic template parameter must be last Does it mean that there can only be one variadic template parameter? How to fix it? Thanks

Problem about lambda expressions

2012-03-27 Thread Tongzhou Li
Hello again! I'm learning D, and I encountered a problem. I tried this code: http://ideone.com/hkpT6 It works well. (Have no idea why codepad.org failed to compile it) I tried to write a lambda instead of function f, but I got nothing printed. Did I make something wrong? Compiler used: DMD32 D C

Re: Problem about Tuple.opEquals, const qualifier

2012-03-18 Thread Tongzhou Li
On Sunday, 18 March 2012 at 06:15:16 UTC, Ali Çehreli wrote: Every template instantiation of a set of template parameters becomes a distinct type than any other set of template parameters. In other words, Tuple!(double, char) and Tuple!(int, char) are distinct types. For all the compiler know

Re: Problem about Tuple.opEquals, const qualifier

2012-03-17 Thread Tongzhou Li
On Saturday, 17 March 2012 at 23:05:30 UTC, Simen Kjærås wrote: As for a workaround, have you considered using a simple array instead of a linked list? Arrays in D, especially when combined with std.array, make for easy-to-use (though perhaps not particularly efficient) stacks: int[] stack; s

Re: Problem about Tuple.opEquals, const qualifier

2012-03-17 Thread Tongzhou Li
On Saturday, 17 March 2012 at 23:05:30 UTC, Simen Kjærås wrote: On Sat, 17 Mar 2012 17:27:21 +0100, Tongzhou Li wrote: I'm learning D, and trying to convert My C++ code into D: http://pastebin.com/eCz9DdZ3 I wrote: auto stack = SList!(Tuple!(double, char))(); But I got an error

Re: Problem about Tuple.opEquals, const qualifier

2012-03-17 Thread Tongzhou Li
On Saturday, 17 March 2012 at 19:49:24 UTC, Ali Çehreli wrote: On 03/17/2012 09:27 AM, Tongzhou Li wrote: I'm learning D, and trying to convert My C++ code into D: http://pastebin.com/eCz9DdZ3 I wrote: auto stack = SList!(Tuple!(double, char))(); But I got an error Error: fun

Problem about Tuple.opEquals, const qualifier

2012-03-17 Thread Tongzhou Li
I'm learning D, and trying to convert My C++ code into D: http://pastebin.com/eCz9DdZ3 I wrote: auto stack = SList!(Tuple!(double, char))(); But I got an error Error: function std.typecons.Tuple!(double,char).Tuple.opEquals!(const(Tuple!(double,char))).opEquals (const(Tuple!(double,char)) rhs) i