Re: Why does * cause my tiny regextester program to crash?

2011-01-31 Thread Alex Folland
On 2011-01-31 2:28, Alex Folland wrote: scope(failure){writeln(Bad regex);break;} Oh, that resets the program rather than continuing from where that line was placed. The continue statement is what I wanted.

volatile deprecated, yet still in Phobos?

2011-01-31 Thread %u
Hi, I've tried to compile programs and Phobos without deprecated features on, and yet I've come across a problem: Volatile statements are deprecated. So, for example, in thread.switchOut(), these statements are invalid: volatile tobj.m_lock = true; fiber_switchContext( oldp, newp );

Partially instantiating templates?

2011-01-31 Thread Magnus Lie Hetland
I'm building a function (or template or whatever, really) that is related to map and minPos in std.algorithm. Basically, it's the standard mathematical argmin, except that it also returns min. It looks something like this: auto minArg(alias fun, Range, T)(Range range, out T minVal) {

Re: Partially instantiating templates?

2011-01-31 Thread Simen kjaeraas
Magnus Lie Hetland mag...@hetland.org wrote: I'm building a function (or template or whatever, really) that is related to map and minPos in std.algorithm. Basically, it's the standard mathematical argmin, except that it also returns min. It looks something like this: auto minArg(alias

Re: Partially instantiating templates?

2011-01-31 Thread Magnus Lie Hetland
On 2011-01-31 12:55:07 +0100, Simen kjaeraas said: ElementType!Range minArg( alias fun, Range )( Range range, out ReturnType!fun ) { ... } Aaaah. I guess I tried ElementType(Range), forgetting to make it a compile-time parameter. Thanks. (Hadn't seen ReturnType; makes sense :) Might

Re: Why does * cause my tiny regextester program to crash?

2011-01-31 Thread Vladimir Panteleev
On Mon, 31 Jan 2011 09:28:25 +0200, Alex Folland lexlex...@gmail.com wrote: scope(failure){writeln(Bad regex);break;} I think the proper construct here is a try/catch block. -- Best regards, Vladimirmailto:vladi...@thecybershadow.net

Re: Partially instantiating templates?

2011-01-31 Thread Simen kjaeraas
Magnus Lie Hetland mag...@hetland.org wrote: Might I also ask why you use an out parameter instead of a tuple return? Well... I had a tuple return at first, but one of the advantages of returning multiple values that I'm accustomed to is the ability to assign to multiple variables, such

Re: Partially instantiating templates?

2011-01-31 Thread Magnus Lie Hetland
On 2011-01-31 15:50:41 +0100, Simen kjaeraas said: You might want to try more from dranges - the reftuple: _(arg,val) = minArg(...); [snip] This is also a possible implementation (coded in about 5 minutes, gives no nice error messages, but it seems to work :p ): Thanks :) Yeah. D has the

Re: Partially instantiating templates?

2011-01-31 Thread Andrej Mitrovic
On 1/31/11, Simen kjaeraas simen.kja...@gmail.com wrote: module foo; import std.typecons; import std.functional; import std.array; template optArg( alias pred ) { template optArg( alias fn ) { auto optArg( Range )( Range r ) { alias binaryFun!pred predicate;

ANSI to UTF8

2011-01-31 Thread Janusch
Hello! I'm trying to convert ANSI characters to UTF8 that but it doesn't work correctly. I used the following: void main() { writeln(convertToUTF8(�)); } string convertToUTF8(string text) { string result; for (uint i=0; itext.length; i++) { char ch =

Re: Partially instantiating templates?

2011-01-31 Thread Simen kjaeraas
Andrej Mitrovic andrej.mitrov...@gmail.com wrote: On 1/31/11, Simen kjaeraas simen.kja...@gmail.com wrote: module foo; import std.typecons; import std.functional; import std.array; template optArg( alias pred ) { template optArg( alias fn ) { auto optArg( Range )( Range r ) {

Re: Partially instantiating templates?

2011-01-31 Thread Magnus Lie Hetland
Hm. Using code quite similar to you, supplying a lambda in the second aliasing, I get this error: something.d(93): Error: template instance cannot use local '__dgliteral2(__T3)' as parameter to non-global template optArg(alias fun) It seems it's explicitly objecting to what I want it to

Re: Partially instantiating templates?

2011-01-31 Thread Simen kjaeraas
Magnus Lie Hetland mag...@hetland.org wrote: Hm. Using code quite similar to you, supplying a lambda in the second aliasing, I get this error: something.d(93): Error: template instance cannot use local '__dgliteral2(__T3)' as parameter to non-global template optArg(alias fun) It seems

Re: Partially instantiating templates?

2011-01-31 Thread Andrej Mitrovic
On 1/31/11, Simen kjaeraas simen.kja...@gmail.com wrote: You can only do that using aliases. Yeah. I was just experimenting for the last half hour. I was hoping to make it easier to make an alias to a nested template using the eponymous trick. But it doesn't work at all. All I could come up

Re: General unicode category

2011-01-31 Thread spir
On 01/30/2011 02:49 PM, Tomek Sowiński wrote: spir spir napisał: DUnicode has such functionality: https://bitbucket.org/stephan/dunicode/src Watch inside unicodedata.d, search for general category. Thanks. Any word of moving some of it into Phobos? It's jarring to see a Unicode-compliant

Re: array of elements of various sybtypes

2011-01-31 Thread Steven Schveighoffer
On Fri, 28 Jan 2011 16:59:20 -0500, Don nos...@nospam.com wrote: spir wrote: Hello, This fails: class T0 {} class T1 : T0 {} class T2 : T0 {} unittest { auto t1 = new T1(); auto t2 = new T2(); T0[] ts = [t1, t2]; } Error: cannot implicitly convert expression (t1) of type

Re: Why does * cause my tiny regextester program to crash?

2011-01-31 Thread Dmitry Olshansky
On 31.01.2011 4:57, Alex Folland wrote: I wrote this little program to test for regular expression matches. I compiled it with in Windows with DMD 2.051 through Visual Studio 2010 with Visual D. It crashes if regexbuf is just the single character, *. Why? Shouldn't it match the entire

Re: array of elements of various sybtypes

2011-01-31 Thread spir
On 01/31/2011 09:06 PM, Steven Schveighoffer wrote: On Fri, 28 Jan 2011 16:59:20 -0500, Don nos...@nospam.com wrote: spir wrote: Hello, This fails: class T0 {} class T1 : T0 {} class T2 : T0 {} unittest { auto t1 = new T1(); auto t2 = new T2(); T0[] ts = [t1, t2]; } Error: cannot implicitly

Re: Why does * cause my tiny regextester program to crash?

2011-01-31 Thread Alex Folland
On 2011-01-31 15:43, Dmitry Olshansky wrote: On 31.01.2011 4:57, Alex Folland wrote: I wrote this little program to test for regular expression matches. I compiled it with in Windows with DMD 2.051 through Visual Studio 2010 with Visual D. It crashes if regexbuf is just the single character, *.

Re: Partially instantiating templates?

2011-01-31 Thread bearophile
Magnus Lie Hetland: Well... I had a tuple return at first, but one of the advantages of returning multiple values that I'm accustomed to is the ability to assign to multiple variables, such as arg, val = minArg(...) (Yeah, I'm a Python guy... ;) I will eventually add a detailed