Re: Forwarding constructor arguments to super
pillsy: Is there a good way to forward constructor arguments to a superclass constructor? This seems to work for simple situations, but maybe it doesn't work in more complex cases: import std.traits: ParameterTypeTuple; mixin template This() { this(ParameterTypeTuple!(super.__ctor) args) { super(args); } } class Foo { int _x; float _f; this(int x, float f) { this._x = x; this._f = f; } } class Bar : Foo { mixin This; } void main() { auto b = new Bar(10, 1.5); } Bye, bearophile
Re: Minimize lock time
On Thu, 10 Jun 2010 02:54:37 -0400, Kagamin s...@here.lot wrote: Let's consider the following code: synchronized(syncRoot) { if(condition)opSuccess(); else writeln(possibly,slow); } Suppose the else close doesn't need to be executed in lock domain and can be slow. How to minimize lock time here? synchronized(syncRoot) { if(condition)opSuccess(); else goto Lwrite; } Lwrite: writeln(possibly,slow); We can do this... but... What about using a Mutex object? mut.lock(); if(condition) { scope(exit) mut.unlock(); opSuccess(); } else { mut.unlock(); writeln(possibly, slow); } I think it's in core.sync or something like that. Mutex can even take over the standard monitor element of another object, so for instance you could assign it as the monitor of your syncRoot, so your other code that uses syncRoot and synchronized still works. -Steve
Re: Arithmetic conversions and a surprise with 'max'
On Fri, 11 Jun 2010 15:00:19 -0400, Ali Çehreli acehr...@yahoo.com wrote: The following program demonstrates a problem that I just hit. It is a known gotcha of arithmetic conversion rules. The program is trying to center some text around an index of a char array. To avoid negative index values, it calls 'max' to limit the starting offset at 0. import std.algorithm; void main() { // An empty line char[10] line = ' '; // We want to center some text around the first quarter mark int center_of_text = line.length / 4; string text = 01234567; // To be safe, we want to limit the starting index at 0. // (No negative index please!) int start = max(0, center_of_text - text.length / 2); assert(start = 0); // FAILS! } The problem is due to converting the second argument of max to unsigned. These kinds of things can typically be converted into a different form that removes the subtraction, or uses it in a safe way: int start = center_of_text - min(center_of_text, text.length / 2); -Steve
Re: undefined identifier with scope statement?
I'm going to guess that the given case is an accepts-invalid bug caused by scope getting re written as a try/finally with the writeln at the bottom of some scope containing res and the other cases put it outside the scope. File a bug and see what happens. http://d.puremagic.com/issues/show_bug.cgi?id=4313
Re: Yet more OPTLINK woes
On 13.05.2010 21:07, torhu wrote: On 13.05.2010 10:39, Daniel Keep wrote: Attached both regular and decaffeinated^Hgutted versions. Most likely DMD turns VisitorCtfe.d into an invalid object file. But since you don't need to link with objects that contain only ctfe functions... http://d.puremagic.com/issues/show_bug.cgi?id=4315