Re: type of if statement used for operator overloading?

2013-02-05 Thread Jonathan M Davis
On Wednesday, February 06, 2013 08:41:14 Jeremy DeHaan wrote: > Out of curiosity, what exactly happens when we don't constrain > what operators are being overloaded? Is it undefined behavior or > will the program just not compile? With no template constraint, a template will match anything with th

Re: type of if statement used for operator overloading?

2013-02-05 Thread Jeremy DeHaan
On Wednesday, 6 February 2013 at 06:38:11 UTC, Jonathan M Davis wrote: On Wednesday, February 06, 2013 07:24:10 Jeremy DeHaan wrote: I've seen operator overloading done 3 different ways. In the examples I provide they all compile and work as far as I can tell. Is there any major difference betwe

Re: best D way to port C style array of void*

2013-02-05 Thread Jacob Carlborg
On 2013-02-06 06:49, estew wrote: Thanks for your help, much appreciated. I'm using the delegates now for the callbacks. At your suggestion I'm looking for a good way to change the design. I agree, the D type system is way superior to that of C. I would suggest you try to replace the array wit

Re: type of if statement used for operator overloading?

2013-02-05 Thread Jonathan M Davis
On Wednesday, February 06, 2013 07:24:10 Jeremy DeHaan wrote: > I've seen operator overloading done 3 different ways. In the > examples I provide they all compile and work as far as I can > tell. Is there any major difference between using a static if vs > a regular if, or any situation that one wo

type of if statement used for operator overloading?

2013-02-05 Thread Jeremy DeHaan
I've seen operator overloading done 3 different ways. In the examples I provide they all compile and work as far as I can tell. Is there any major difference between using a static if vs a regular if, or any situation that one would be better than the other? struct Something1 { Something1

Re: Regarding isSorted

2013-02-05 Thread Jos van Uden
On 6-2-2013 1:33, bearophile wrote: Maybe this line: https://github.com/D-Programming-Language/phobos/blob/master/std/algorithm.d#L9237 for (; !ahead.empty; ahead.popFront(), ++i) Should be: for (; !ahead.empty; ahead.popFront(), r.popFront(), ++i) Thought that line loo

Re: best D way to port C style array of void*

2013-02-05 Thread estew
Thanks for your help, much appreciated. I'm using the delegates now for the callbacks. At your suggestion I'm looking for a good way to change the design. I agree, the D type system is way superior to that of C. Starting to get into mixins too, although I'm a bit wary of them. I know they're

Re: best D way to port C style array of void*

2013-02-05 Thread Steven Schveighoffer
On Tue, 05 Feb 2013 23:17:59 -0500, Steven Schveighoffer wrote: e.g.: import std.stdio; void callit(void delegate() dg) { // call delegate with context pointer dg(); } void main() { int x; auto dg = ()=>writeln(++x); // create a delegate using a lambda function

Re: best D way to port C style array of void*

2013-02-05 Thread Steven Schveighoffer
On Tue, 05 Feb 2013 22:16:17 -0500, estew wrote: Hi All, I've some old C code which I'm porting to D. It's a learning exercise so I don't want to just wrap the C lib. I have an array of void* and an array of callbacks that take void* pointers for user data. I'm wondering what is a good

best D way to port C style array of void*

2013-02-05 Thread estew
Hi All, I've some old C code which I'm porting to D. It's a learning exercise so I don't want to just wrap the C lib. I have an array of void* and an array of callbacks that take void* pointers for user data. I'm wondering what is a good way to port this into D and avoid the void*. My C++

Re: Regarding isSorted

2013-02-05 Thread bearophile
Jonathan M Davis: That definitely looks like a bug. "acbd" _isn't_ sorted. OK. Thank you. http://d.puremagic.com/issues/show_bug.cgi?id=9457 Brad Anderson: Have a GitHub account, bearophile? Not yet, but probably I will have one. Just hit Edit at the top of that

Re: Regarding isSorted

2013-02-05 Thread Brad Anderson
Have a GitHub account, bearophile? Just hit Edit at the top of that link you gave, make the change, and click "Proposal File Change" and it'll roll up a pull request. Should take less than a minute. I use this for almost every minor pull requests I do. The autotester takes care of the rest. Looks

Re: Regarding isSorted

2013-02-05 Thread Jonathan M Davis
On Wednesday, February 06, 2013 01:33:29 bearophile wrote: > This used to print true-false, now prints true-true. Is this a > bug? > > > import std.stdio, std.algorithm; > void main() { > auto x = "abcd"; > writeln(isSorted(x)); > auto y = "acbd"; > writeln(isSorted(y)); > } >

Regarding isSorted

2013-02-05 Thread bearophile
This used to print true-false, now prints true-true. Is this a bug? import std.stdio, std.algorithm; void main() { auto x = "abcd"; writeln(isSorted(x)); auto y = "acbd"; writeln(isSorted(y)); } Maybe this line: https://github.com/D-Programming-Language/phobos/blob/master/std

Re: A little of coordination for Rosettacode

2013-02-05 Thread bearophile
Jos van Uden: How do we avoid working on the same thing? With a little coordination :-) Partial translation of rcrpg-Python: http://codepad.org/SflrKqbT Partial translation of permutations_rank_of_a_permutation-Python: http://codepad.org/El9SQwOE The 2 above, I could try. Plus a bett

Re: new T[size] vs .reserve - alloca

2013-02-05 Thread monarch_dodra
On Tuesday, 5 February 2013 at 21:14:32 UTC, Nick Treleaven wrote: On 05/02/2013 21:13, Nick Treleaven wrote: I've just tried it with dmd 2.059 (haven't upgraded yet) sorry, 2.060 Right, it's "alias" being finicky, because "args.length" isn't an actual variable (it's a property). The proble

Re: GtkD button size

2013-02-05 Thread Mike Wey
On 02/05/2013 08:48 PM, SaltySugar wrote: Thank you, Mike. One more question. Can I use hbox.add(btn); instead of hbox.packStart (btn,false,false,5); What difference between them? Sorry, for my bad English. hbox.add would call packStart with the defaults, witch would be packStart(btn, true, t

Re: new T[size] vs .reserve - alloca

2013-02-05 Thread Nick Treleaven
On 05/02/2013 21:13, Nick Treleaven wrote: I've just tried it with dmd 2.059 (haven't upgraded yet) sorry, 2.060

Re: new T[size] vs .reserve - alloca

2013-02-05 Thread Nick Treleaven
On 05/02/2013 21:02, monarch_dodra wrote: On Tuesday, 5 February 2013 at 20:47:46 UTC, Nick Treleaven wrote: On 05/02/2013 16:47, monarch_dodra wrote: T[] stack(T, alias N)(void* m = alloca(T.sizeof * N)) { return (cast(T*)m)[0 .. N]; } This works if you know N at compile-time. But there

Re: new T[size] vs .reserve - alloca

2013-02-05 Thread monarch_dodra
On Tuesday, 5 February 2013 at 20:47:46 UTC, Nick Treleaven wrote: On 05/02/2013 16:47, monarch_dodra wrote: On Tuesday, 5 February 2013 at 16:37:41 UTC, Nick Treleaven wrote: I've just realized this doesn't work for variable-length allocation: T[] stack(T)(size_t N, void* m = alloca(T.sizeof

Re: new T[size] vs .reserve - alloca

2013-02-05 Thread Nick Treleaven
On 05/02/2013 16:47, monarch_dodra wrote: On Tuesday, 5 February 2013 at 16:37:41 UTC, Nick Treleaven wrote: I've just realized this doesn't work for variable-length allocation: T[] stack(T)(size_t N, void* m = alloca(T.sizeof * N)) Error: undefined identifier N, did you mean alias T? N is no

Re: A little of coordination for Rosettacode

2013-02-05 Thread Jos van Uden
On 5-2-2013 21:10, bearophile wrote: How do we avoid working on the same thing? Partial translation of rcrpg-Python: http://codepad.org/SflrKqbT Partial translation of permutations_rank_of_a_permutation-Python: http://codepad.org/El9SQwOE The 2 above, I could try. Plus a better Perl implem

Re: GtkD button size

2013-02-05 Thread FG
On 2013-02-05 20:48, SaltySugar wrote: Can I use hbox.add(btn); instead of hbox.packStart (btn,false,false,5); What difference between them? Using add(btn) you would probably end up with a stretched button again. :) hbox.packStart(child, expand, fill, padding) It was explicitly said that ex

Re: A little of coordination for Rosettacode

2013-02-05 Thread bearophile
Jos van Uden: I'll give it a shot if you like. The RCRPG I'd like to try first. I have already partially written those: Partial translation of rcrpg-Python: http://codepad.org/SflrKqbT Partial translation of permutations_rank_of_a_permutation-Python: http://codepad.org/El9SQwOE Plus a better

Re: new T[size] vs .reserve - alloca

2013-02-05 Thread Namespace
Why not: [code] T[] stack(T, const size_t N)(void* m = alloca(T.sizeof * N)) { return (cast(T*)m)[0 .. N]; } [/code] ?

Re: GtkD button size

2013-02-05 Thread SaltySugar
On Tuesday, 5 February 2013 at 19:31:01 UTC, Mike Wey wrote: On 02/05/2013 06:33 PM, SaltySugar wrote: I can't find any tutorials about buttonboxes. Can you write how to use it? Here is a small example: import gtk.MainWindow; import gtk.Button; import gtk.Main; import gtk.HButtonBox; class A

Re: A little of coordination for Rosettacode

2013-02-05 Thread Jos van Uden
On 5-2-2013 0:55, bearophile wrote: Is the Fwend user of Rosettacode (or some other interested person) around here? I have written partial D implementations for three tasks, maybe a little of coordination will speedup the work: http://rosettacode.org/wiki/Permutations/Rank_of_a_permutation http

Re: GtkD button size

2013-02-05 Thread Mike Wey
On 02/05/2013 06:33 PM, SaltySugar wrote: I can't find any tutorials about buttonboxes. Can you write how to use it? Here is a small example: import gtk.MainWindow; import gtk.Button; import gtk.Main; import gtk.HButtonBox; class Application : MainWindow { this() { super("GtkD

Re: Allocating large 2D array in D

2013-02-05 Thread H. S. Teoh
On Tue, Feb 05, 2013 at 07:38:40PM +0100, bearophile wrote: > H. S. Teoh: > > >Added to wiki: http://wiki.dlang.org/Dense_multidimensional_arrays > > It contains: > > enum columns = 100; > int rows = 100; > double[gridSize][] gridInfo = new double[columns][](rows); > > > gridSize is undefined.

Re: Allocating large 2D array in D

2013-02-05 Thread bearophile
H. S. Teoh: Added to wiki: http://wiki.dlang.org/Dense_multidimensional_arrays It contains: enum columns = 100; int rows = 100; double[gridSize][] gridInfo = new double[columns][](rows); gridSize is undefined. I suggest to write something like: enum nColumns = 100; int nRows = 120; double[

Re: x.RC.__postblit () is not callable using argument types () const

2013-02-05 Thread Maxim Fomin
On Tuesday, 5 February 2013 at 17:05:23 UTC, Dan wrote: But why does this even code work? I would have thought const guarantee would prevent calls to non-const postblit function. I was under impression this(this) const does not work - but maybe that has changed with 2.061. Forgot to mention,

Re: Allocating large 2D array in D

2013-02-05 Thread H. S. Teoh
On Mon, Feb 04, 2013 at 04:58:36PM +0100, bearophile wrote: > monarch_dodra: > > >If all (but last of) the dimensions are known at compile time, > >then you can dynamically allocate an array of fixed sized arrays: > > > >// > >enum size_t gridSize = 4_000; > >enum size_t total = gridSize * g

Re: GtkD button size

2013-02-05 Thread SaltySugar
On Monday, 4 February 2013 at 21:55:24 UTC, Mike Wey wrote: On 02/04/2013 03:03 PM, SaltySugar wrote: On Sunday, 3 February 2013 at 16:07:06 UTC, Artur Skawina wrote: On 02/03/13 16:53, SaltySugar wrote: GTKD. Can someone explain me how to change button size in vbox, hbox? setSizeRequest (70,

Re: x.RC.__postblit () is not callable using argument types () const

2013-02-05 Thread Dan
On Tuesday, 5 February 2013 at 16:36:16 UTC, Maxim Fomin wrote: This does not imply such situation, simply there is a problem. You can workaround by [snip] struct RC { int i; void postblit() { i = -5; } this(this) const { void delegate() dg = &postblit; dg();

Re: new T[size] vs .reserve - alloca

2013-02-05 Thread monarch_dodra
On Tuesday, 5 February 2013 at 16:37:41 UTC, Nick Treleaven wrote: On 05/02/2013 16:17, Nick Treleaven wrote: On 03/02/2013 13:22, bearophile wrote: Era Scarecrow: On Sunday, 3 February 2013 at 09:11:59 UTC, Namespace wrote: Sure, but alloca has the same ugly interface as malloc. :/ You me

Re: new T[size] vs .reserve - alloca

2013-02-05 Thread bearophile
Nick Treleaven: ^ I know you're aware of this, but maybe others might not know the default-argument alloca wrapping trick: For some usages it's an improvement over raw usage of alloca. I did see this in past, but sometimes I forget. Bye, bearophile

Re: new T[size] vs .reserve - alloca

2013-02-05 Thread Nick Treleaven
On 05/02/2013 16:17, Nick Treleaven wrote: On 03/02/2013 13:22, bearophile wrote: Era Scarecrow: On Sunday, 3 February 2013 at 09:11:59 UTC, Namespace wrote: Sure, but alloca has the same ugly interface as malloc. :/ You mean that you have to specify how many raw bytes you want, then cast

Re: x.RC.__postblit () is not callable using argument types () const

2013-02-05 Thread Maxim Fomin
On Tuesday, 5 February 2013 at 15:49:59 UTC, Dan wrote: - Wouldn't the scenario be exactly the same without ValuationHistory? That is, if I comment out the member _valuationHistory, the goo member is not changed in structure at all, and yet it compiles just fine. Scenario is the same if the

Re: new T[size] vs .reserve - alloca

2013-02-05 Thread Nick Treleaven
On 03/02/2013 13:22, bearophile wrote: Era Scarecrow: On Sunday, 3 February 2013 at 09:11:59 UTC, Namespace wrote: Sure, but alloca has the same ugly interface as malloc. :/ You mean that you have to specify how many raw bytes you want, then cast it to what you need? I never thought alloca

Re: x.RC.__postblit () is not callable using argument types () const

2013-02-05 Thread Dan
On Tuesday, 5 February 2013 at 15:06:47 UTC, Maxim Fomin wrote: The root of the problem is in: struct DAssociativeArray(Key, Value) { struct Slot { Value value; } } struct RC { this(this) { } } void main() { DAssociativeArray!(int, const(RC)) goo; } which doesn't co

Re: x.RC.__postblit () is not callable using argument types () const

2013-02-05 Thread Maxim Fomin
On Tuesday, 5 February 2013 at 12:35:25 UTC, Dan wrote: Is it the case that this is a D compiler (or library) problem and there is no issue with the code? Or is there really a problem with it that I am not seeing? I gather from the responses the code looks fine, otherwise any misunderstanding

Re: x.RC.__postblit () is not callable using argument types () const

2013-02-05 Thread Dan
On Tuesday, 5 February 2013 at 11:51:40 UTC, Maxim Fomin wrote: On Tuesday, 5 February 2013 at 04:03:06 UTC, Andrej Mitrovic wrote: Yeah, it's still not very helpful. And I have no idea where "Slot" comes from. This is sub struct inside object.AssociativeArray. Is it the case that this is a

Re: x.RC.__postblit () is not callable using argument types () const

2013-02-05 Thread Maxim Fomin
On Tuesday, 5 February 2013 at 01:15:28 UTC, Dan wrote: I've seen these type of errors often and usually the cause kind of jumps out. In this case I'm totally confused. Just trying to move from 2.06 to 2.061. The code is: http://dpaste.dzfl.pl/f40e4d6f and fails with the error in subject line.

Re: x.RC.__postblit () is not callable using argument types () const

2013-02-05 Thread Maxim Fomin
On Tuesday, 5 February 2013 at 04:03:06 UTC, Andrej Mitrovic wrote: Yeah, it's still not very helpful. And I have no idea where "Slot" comes from. This is sub struct inside object.AssociativeArray.