Re: Understanding isInfinite(Range)

2010-09-07 Thread Pelle
On 09/07/2010 12:44 AM, bearophile wrote: Andrej Mitrovic: I'm sorry, but what does q{..} mean? q{} is just a different syntax to write "" or `` It's a controversial feature. q{} isn't recognized by editors as a string, so they colour the syntax it contains normally as code, and not as a st

Re: Understanding isInfinite(Range)

2010-09-06 Thread Andrej Mitrovic
I meant string literals. But comments as well. Andrej Mitrovic Wrote: > Heh. I'd rather want text editors to use syntax highlighting on comments as > well, but use a different background color. Then I would know it's a comment > but it would also make any embedded code in the comment actually r

Re: Understanding isInfinite(Range)

2010-09-06 Thread Andrej Mitrovic
Heh. I'd rather want text editors to use syntax highlighting on comments as well, but use a different background color. Then I would know it's a comment but it would also make any embedded code in the comment actually readable. bearophile < bearophileh...@lycos.com> Wrote: > Andrej Mitrovic: >

Re: Understanding isInfinite(Range)

2010-09-06 Thread bearophile
Andrej Mitrovic: > I'm sorry, but what does q{..} mean? q{} is just a different syntax to write "" or `` It's a controversial feature. q{} isn't recognized by editors as a string, so they colour the syntax it contains normally as code, and not as a string. So it's a bit useful if you want to g

Re: Understanding isInfinite(Range)

2010-09-06 Thread Andrej Mitrovic
I'm sorry, but what does q{..} mean? Philippe Sigaud Wrote: > On Mon, Sep 6, 2010 at 23:31, Andrej Mitrovic > wrote: > > > That still won't work. Observe: > > > > > template isInputRange(R) > > { > > enum bool isInputRange = isValidCode!( > > { > >R r;// can d

Re: Understanding isInfinite(Range)

2010-09-06 Thread bearophile
Andrej Mitrovic: > enum a = "test"; > a = "test2"; > > Because it seems to compile. But that shouldn't work afaik..? I have two open bug reports on this (and a third one was open by Don). Bye, bearophile

Re: Understanding isInfinite(Range)

2010-09-06 Thread Philippe Sigaud
On Mon, Sep 6, 2010 at 23:31, Andrej Mitrovic wrote: > That still won't work. Observe: > template isInputRange(R) > { > enum bool isInputRange = isValidCode!( > { >R r;// can define a range object >if (r.empty) {} // can test for empty >r.popF

Re: Understanding isInfinite(Range)

2010-09-06 Thread Stanislav Blinov
Andrej Mitrovic wrote: That still won't work. Observe: Oops, sorry, I was too quick to conclude.

Re: Understanding isInfinite(Range)

2010-09-06 Thread Stanislav Blinov
Andrej Mitrovic wrote: is(typeof( is used a lot in Phobos. There's some ~260 calls like that, a quick search revealed. :p Hush! You're spoiling it! It's a part of intergalactic obfuscation plot ;p

Re: Understanding isInfinite(Range)

2010-09-06 Thread Andrej Mitrovic
That still won't work. Observe: import std.stdio : writeln; void main() { writeln(isInputRange!(N)); } class N { N test; //~ bool empty() // oops, we"re not an input range anymore //~ { //~ return false; //~ } @property void popFront() { } @p

Re: Understanding isInfinite(Range)

2010-09-06 Thread Andrej Mitrovic
is(typeof( is used a lot in Phobos. There's some ~260 calls like that, a quick search revealed. :p Stanislav Blinov Wrote: > If I remember correctly, it has been discussed not long ago that those > is(typeof(...))s should really be __traits(compiles). Maybe it's just > some code was written be

Re: Understanding isInfinite(Range)

2010-09-06 Thread Stanislav Blinov
Andrej Mitrovic wrote: It does look nice. It would look even nicer if __traits gets renamed to meta. By the way, there's no stopping writing template isValidCode(alias code) { enum bool isValidCode = __traits(compiles, code); } :)

Re: Understanding isInfinite(Range)

2010-09-06 Thread Stanislav Blinov
Andrej Mitrovic wrote: I'd love to see this used more in Phobos. I don't know if there are any drawbacks, but this looks and works nicely: import std.stdio : writeln; void main() { writeln(isInputRange!(N)); } class N { N test; bool empty() { return false; }

Re: Understanding isInfinite(Range)

2010-09-06 Thread Andrej Mitrovic
Is this legal?: enum a = "test"; a = "test2"; Because it seems to compile. But that shouldn't work afaik..? I can't reassign other enum types: enum b = 4; b = 5; // error which is expected. Pelle Wrote: > On 09/06/2010 08:53 PM, Philippe Sigaud wrote: > > On Mon, Sep 6, 2010 at 18:47, Pelle

Re: Understanding isInfinite(Range)

2010-09-06 Thread Pelle
On 09/06/2010 08:53 PM, Philippe Sigaud wrote: On Mon, Sep 6, 2010 at 18:47, Pelle mailto:pelle.mans...@gmail.com>> wrote: On 09/04/2010 02:11 PM, Simen kjaeraas wrote: Is there a way you could write an isStatic(expr) template? Using template isStatic( alias T ) {

Re: Understanding isInfinite(Range)

2010-09-06 Thread Andrej Mitrovic
I'd love to see this used more in Phobos. I don't know if there are any drawbacks, but this looks and works nicely: import std.stdio : writeln; void main() { writeln(isInputRange!(N)); } class N { N test; bool empty() { return false; } @property voi

Re: Understanding isInfinite(Range)

2010-09-06 Thread Andrej Mitrovic
Yeah, that could work: template isInputRange(R) { enum bool isInputRange = __traits(compiles, { R r; // can define a range object if (r.empty) {} // can test for empty r.popFront; // can invoke next auto h = r.front; // can get the front of t

Re: Understanding isInfinite(Range)

2010-09-06 Thread Mafi
Am 06.09.2010 21:24, schrieb Andrej Mitrovic: Apparently I can't post to D.learn from gmail without waiting for a review? What the..? Anyway, I've posted this: On a related note, I always wanted to make a template to replace the dreaded is(typeof('delegate literal'())); calls. For example, in

Re: Understanding isInfinite(Range)

2010-09-06 Thread Stanislav Blinov
Andrej Mitrovic wrote: Apparently I can't post to D.learn from gmail without waiting for a review? What the..? Anyway, I've posted this: On a related note, I always wanted to make a template to replace the dreaded is(typeof('delegate literal'())); calls. For example, instead of this: enum bo

Re: Understanding isInfinite(Range)

2010-09-06 Thread Andrej Mitrovic
Apparently I can't post to D.learn from gmail without waiting for a review? What the..? Anyway, I've posted this: On a related note, I always wanted to make a template to replace the dreaded is(typeof('delegate literal'())); calls. For example, instead of this: enum bool isInputRange = is(type

Re: Understanding isInfinite(Range)

2010-09-06 Thread Philippe Sigaud
On Mon, Sep 6, 2010 at 18:47, Pelle wrote: > On 09/04/2010 02:11 PM, Simen kjaeraas wrote: > >> Is there a way you could write an isStatic(expr) template? Using >>> >> >> template isStatic( alias T ) { >> enum isStatic = is( char[1+T] ); >> } >> >> unittest { >> int n = 3; >> assert( !isStatic!n

Re: Understanding isInfinite(Range)

2010-09-06 Thread Pelle
On 09/04/2010 02:11 PM, Simen kjaeraas wrote: Peter Alexander wrote: == Quote from Steven Schveighoffer (schvei...@yahoo.com)'s article On Fri, 03 Sep 2010 11:12:29 -0400, Andrej Mitrovic wrote: > What does char[1 + Range.empty] do? It looks rather cryptic.. char[1+Range.empty] is a type. If

Re: Understanding isInfinite(Range)

2010-09-04 Thread Simen kjaeraas
Peter Alexander wrote: == Quote from Steven Schveighoffer (schvei...@yahoo.com)'s article On Fri, 03 Sep 2010 11:12:29 -0400, Andrej Mitrovic wrote: > What does char[1 + Range.empty] do? It looks rather cryptic.. char[1+Range.empty] is a type. If Range.empty is a compile-time constant, th

Re: Understanding isInfinite(Range)

2010-09-04 Thread Peter Alexander
== Quote from Steven Schveighoffer (schvei...@yahoo.com)'s article > On Fri, 03 Sep 2010 11:12:29 -0400, Andrej Mitrovic > wrote: > > What does char[1 + Range.empty] do? It looks rather cryptic.. > char[1+Range.empty] is a type. If Range.empty is a compile-time constant, > then this type is valid

Re: Understanding isInfinite(Range)

2010-09-03 Thread Andrej Mitrovic
Ah, you're right. Whenever I see the square brackets my brain automatically things "we're indexing something". I'll blame that on C. :p Thanks. Steven Schveighoffer Wrote: > On Fri, 03 Sep 2010 11:12:29 -0400, Andrej Mitrovic > wrote: > > > I was reading about the various range templates in

Re: Understanding isInfinite(Range)

2010-09-03 Thread Steven Schveighoffer
On Fri, 03 Sep 2010 11:12:29 -0400, Andrej Mitrovic wrote: I was reading about the various range templates in std.range and I found this: http://www.digitalmars.com/d/2.0/phobos/std_range.html#isInfinite Seems simple enough. But I dont understand it's implementation, this from range.d:

Understanding isInfinite(Range)

2010-09-03 Thread Andrej Mitrovic
I was reading about the various range templates in std.range and I found this: http://www.digitalmars.com/d/2.0/phobos/std_range.html#isInfinite Seems simple enough. But I dont understand it's implementation, this from range.d: template isInfinite(Range) { static if (isInputRange!Range && i