Re: Should the 2.054 feature about warning on implicit fallthrough

2011-09-15 Thread Christophe
bearophile , dans le message (digitalmars.D.learn:29532), a écrit : Well, I don't understand the error it gives :-) Are you able to explain it to me? import std.stdio; void main() { int i = 1; switch(i) { case 0: writeln(case 0); goto

port c macro to D

2011-09-15 Thread Matthias Pleh
When porting c-code to D, I come consitently to the problem, how to convert such a c-macro: #define V(a,b,c) glVertex3d( a size, b size, c size ); #define N(a,b,c) glNormal3d( a, b, c ); N( 1.0, 0.0, 0.0); V(+,-,+); V(+,-,-); V(+,+,-); V(+,+,+); ... Ok, I could just write it out, but that's not

Re: port c macro to D

2011-09-15 Thread Trass3r
Am 15.09.2011, 13:37 Uhr, schrieb Matthias Pleh u...@example.net: When porting c-code to D, I come consitently to the problem, how to convert such a c-macro: #define V(a,b,c) glVertex3d( a size, b size, c size ); #define N(a,b,c) glNormal3d( a, b, c ); N( 1.0, 0.0, 0.0); V(+,-,+); V(+,-,-);

Re: port c macro to D

2011-09-15 Thread Matthias Pleh
On 15.09.2011 13:48, Trass3r wrote: If you are willing to write V(+1,-1,+1) instead you can just turn them into functions. really a good point! :) Also by static function you probably mean private in D. No, I meant for mixin I nead static functions, but I just realized, it also works without

Why can't templates with default arguments be instantiated without the bang syntax?

2011-09-15 Thread Andrej Mitrovic
struct Foo(T = int) {} void main() { Foo foo; // fail Foo!() bar; // ok } It would be very convenient to be able to default to one type like this. For example, in CairoD there's a Point structure which takes doubles as its storage type, and then there's PointInt that takes ints. The

Re: Why can't templates with default arguments be instantiated without the bang syntax?

2011-09-15 Thread Simen Kjaeraas
On Thu, 15 Sep 2011 16:46:24 +0200, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: struct Foo(T = int) {} void main() { Foo foo; // fail Foo!() bar; // ok } It would be very convenient to be able to default to one type like this. For example, in CairoD there's a Point

Re: Why can't templates with default arguments be instantiated without the bang syntax?

2011-09-15 Thread Christophe
Simen Kjaeraas , dans le message (digitalmars.D.learn:29539), a écrit : On Thu, 15 Sep 2011 16:46:24 +0200, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: struct Foo(T = int) {} void main() { Foo foo; // fail Foo!() bar; // ok } It would be very convenient to be able

Re: Why can't templates with default arguments be instantiated without the bang syntax?

2011-09-15 Thread Jonathan M Davis
On Thursday, September 15, 2011 16:46:24 Andrej Mitrovic wrote: struct Foo(T = int) {} void main() { Foo foo; // fail Foo!() bar; // ok } It would be very convenient to be able to default to one type like this. For example, in CairoD there's a Point structure which takes

Re: Why can't templates with default arguments be instantiated without the bang syntax?

2011-09-15 Thread Steven Schveighoffer
On Thu, 15 Sep 2011 10:46:24 -0400, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: struct Foo(T = int) {} void main() { Foo foo; // fail Foo!() bar; // ok } It would be very convenient to be able to default to one type like this. For example, in CairoD there's a Point

Re: Why can't templates with default arguments be instantiated without the bang syntax?

2011-09-15 Thread Jacob Carlborg
On 2011-09-15 16:46, Andrej Mitrovic wrote: struct Foo(T = int) {} void main() { Foo foo; // fail Foo!() bar; // ok } It would be very convenient to be able to default to one type like this. For example, in CairoD there's a Point structure which takes doubles as its storage type,

Re: Why can't templates with default arguments be instantiated without the bang syntax?

2011-09-15 Thread Simen Kjaeraas
On Thu, 15 Sep 2011 17:54:19 +0200, Christophe trav...@phare.normalesup.org wrote: Simen Kjaeraas , dans le message (digitalmars.D.learn:29539), a écrit : On Thu, 15 Sep 2011 16:46:24 +0200, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: struct Foo(T = int) {} void main() { Foo

Re: port c macro to D

2011-09-15 Thread Trass3r
Also by static function you probably mean private in D. No, I meant for mixin I nead static functions, but I just realized, it also works without the static keyword. I think static has no meaning in global scope, only in function scope where it tells the compiler you don't want a closure.

Re: std.datetime impenetrable

2011-09-15 Thread Jonathan M Davis
On Thursday, September 15, 2011 10:48 Steve Teale wrote: Looking at the documentation makes my head hurt, especially if I have consumed some beer, when I am not pure and immutable. For an overview, check out http://d-programming-language.org/intro-to- datetime.html I'd _love_ to fix the links

Re: std.datetime impenetrable

2011-09-15 Thread Steve Teale
Oh, so it is difficult after all! I thought it was just me. So I am probably going to have to ask. Then the interesting question will be which way around will offend fewest people. I have installed it as ISO, then have to ask US users if they would prefer Letter Size, or the other way round

Re: std.datetime impenetrable

2011-09-15 Thread Jonathan M Davis
On Thursday, September 15, 2011 19:30:24 Steve Teale wrote: Oh, so it is difficult after all! I thought it was just me. No. It's hard. The best that you can get by asking Posix functions is the std and DST abbreviations for the current time zone - and those are non-unique. You'd have to do

Is it possible to check if a type is an instance of a template?

2011-09-15 Thread Andrej Mitrovic
I can do this: struct Foo(T) { } template bar(T : Foo!int) { } I can check if T is a specific instantiation of Foo. But I want to check whether T is *any* instantiation of Foo. Is this possible to do? Otherwise I'm currently having to hardcode via: template bar(T) if (isOneOf!(T, Foo!int,

Re: Is it possible to check if a type is an instance of a template?

2011-09-15 Thread Simen Kjaeraas
On Thu, 15 Sep 2011 22:24:50 +0200, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: I can do this: struct Foo(T) { } template bar(T : Foo!int) { } I can check if T is a specific instantiation of Foo. But I want to check whether T is *any* instantiation of Foo. Is this possible to do?

Re: Is it possible to check if a type is an instance of a template?

2011-09-15 Thread Timon Gehr
On 09/15/2011 10:24 PM, Andrej Mitrovic wrote: I can do this: struct Foo(T) { } template bar(T : Foo!int) { } I can check if T is a specific instantiation of Foo. But I want to check whether T is *any* instantiation of Foo. Is this possible to do? Otherwise I'm currently having to hardcode

Re: Is it possible to check if a type is an instance of a template?

2011-09-15 Thread Andrej Mitrovic
Cool, that works, thanks. Is this in Phobos by any chance? Otherwise I'll just use a more flexible version of that.

Re: Is it possible to check if a type is an instance of a template?

2011-09-15 Thread Jonathan M Davis
On Thursday, September 15, 2011 13:24 Andrej Mitrovic wrote: I can do this: struct Foo(T) { } template bar(T : Foo!int) { } I can check if T is a specific instantiation of Foo. But I want to check whether T is *any* instantiation of Foo. Is this possible to do? Otherwise I'm currently

Re: Is it possible to check if a type is an instance of a template?

2011-09-15 Thread Andrej Mitrovic
On 9/15/11, Timon Gehr timon.g...@gmx.ch wrote: template bar(T : Foo!S,S){ } Yeah, that should do it too. Thanks.

Re: Is it possible to check if a type is an instance of a template?

2011-09-15 Thread Jonathan M Davis
On Thursday, September 15, 2011 13:45 Andrej Mitrovic wrote: Cool, that works, thanks. Is this in Phobos by any chance? How could it be? It's specific to the template that you're testing. - Jonathan M Davis

Re: std.datetime impenetrable

2011-09-15 Thread Mike Wey
On 09/15/2011 07:48 PM, Steve Teale wrote: Alternatively, let me explain my desire. When my program first runs, I want to hazard a guess as to what size of paper the user is likely to use - US Letter Size, or A4/inches or metric. GTK does not seem to want to tell me about the default printer

Re: Is it possible to check if a type is an instance of a template?

2011-09-15 Thread Andrej Mitrovic
On 9/15/11, Jonathan M Davis jmdavisp...@gmx.com wrote: Every template instantiation is a new set of code with _zero_ assocation with any other template instantation. Yeah, I know. But I don't think this has to be set in stone. Having some specific compile-time type information about a

Re: Is it possible to check if a type is an instance of a template?

2011-09-15 Thread Simen Kjaeraas
On Thu, 15 Sep 2011 22:45:21 +0200, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: Cool, that works, thanks. Is this in Phobos by any chance? Otherwise I'll just use a more flexible version of that. No more flexible version available, sadly. I wish this worked (I think it's in Bugzilla

Re: Is it possible to check if a type is an instance of a template?

2011-09-15 Thread Jonathan M Davis
On Thursday, September 15, 2011 14:17 Andrej Mitrovic wrote: On 9/15/11, Jonathan M Davis jmdavisp...@gmx.com wrote: Every template instantiation is a new set of code with _zero_ assocation with any other template instantation. Yeah, I know. But I don't think this has to be set in stone.

How to filter an array so the result is an array again?

2011-09-15 Thread Cheng Wei
The standard library std.algorithm is based on Range. So if a = [1, 2, 3, 4]; auto r = filter!(a 2)(a); Here, r is a range. How about I want an new array? Is there any easy way to convert the result to array? If we have to do like: int[] b; for (v; r) { b ~= v; } Then maybe it is easier to

Re: How to filter an array so the result is an array again?

2011-09-15 Thread Cheng Wei
Sorry, the 'for' should be 'foreach'.

Re: How to filter an array so the result is an array again?

2011-09-15 Thread Jonathan M Davis
On Friday, September 16, 2011 04:04:39 Cheng Wei wrote: The standard library std.algorithm is based on Range. So if a = [1, 2, 3, 4]; auto r = filter!(a 2)(a); Here, r is a range. How about I want an new array? Is there any easy way to convert the result to array? If we have to do