digitalmars.D.learn - Understanding isInfinite(Range)
- Andrej Mitrovic (11/11) Sep 03 2010 I was reading about the various range templates in std.range and I found...
- Steven Schveighoffer (8/21) Sep 03 2010 char[1+Range.empty] is a type. If Range.empty is a compile-time constan...
- Andrej Mitrovic (3/32) Sep 03 2010 Ah, you're right. Whenever I see the square brackets my brain automatica...
- Peter Alexander (7/16) Sep 04 2010 That's really ugly code :-(
- Simen kjaeraas (13/33) Sep 04 2010 template isStatic( alias T ) {
- Pelle (4/38) Sep 06 2010 enum s = "Hello";
- Philippe Sigaud (2/21) Sep 06 2010 Why? That's exactly the behavior we want, or so it seems to me.
- Andrej Mitrovic (26/81) Sep 06 2010 Apparently I can't post to D.learn from gmail without waiting for a revi...
- Stanislav Blinov (2/35) Sep 06 2010 What about __traits(compiles) ?
- Andrej Mitrovic (13/14) Sep 06 2010 Yeah, that could work:
- Andrej Mitrovic (49/68) Sep 06 2010 I'd love to see this used more in Phobos. I don't know if there are any ...
- Stanislav Blinov (4/61) Sep 06 2010 If I remember correctly, it has been discussed not long ago that those
- Stanislav Blinov (5/6) Sep 06 2010 By the way, there's no stopping writing
- Andrej Mitrovic (36/47) Sep 06 2010 That still won't work. Observe:
- Stanislav Blinov (2/4) Sep 06 2010 Oops, sorry, I was too quick to conclude.
- Philippe Sigaud (30/44) Sep 06 2010 That's because the part between the curly braces is evaluated before bei...
- Andrej Mitrovic (2/65) Sep 06 2010
- bearophile (9/10) Sep 06 2010 q{} is just a different syntax to write "" or ``
- Andrej Mitrovic (2/20) Sep 06 2010
- Andrej Mitrovic (2/25) Sep 06 2010
- Pelle (3/13) Sep 07 2010 It's not the same. Try q{\n}.
- Andrej Mitrovic (2/5) Sep 06 2010
- Stanislav Blinov (2/3) Sep 06 2010 Hush! You're spoiling it! It's a part of intergalactic obfuscation plot ...
- Mafi (9/34) Sep 06 2010 You could just let your template get a string. Then
- Pelle (4/22) Sep 06 2010 Sorry if I was unclear, that assert fails. Due to that you cannot add an...
- Andrej Mitrovic (9/45) Sep 06 2010 Is this legal?:
- bearophile (4/8) Sep 06 2010 I have two open bug reports on this (and a third one was open by Don).
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 && is(char[1 + Range.empty])) enum bool isInfinite = !Range.empty; else enum bool isInfinite = false; } What does char[1 + Range.empty] do? It looks rather cryptic..
Sep 03 2010
On Fri, 03 Sep 2010 11:12:29 -0400, Andrej Mitrovic <andrej.mitrovich test.com> 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: template isInfinite(Range) { static if (isInputRange!Range && is(char[1 + Range.empty])) enum bool isInfinite = !Range.empty; else enum bool isInfinite = false; } 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, otherwise it's not valid (the is expression results to true if the argument is a valid type). If it's valid, then Range.empty never changes. If it never changes and it's always false, then it's infinite. -Steve
Sep 03 2010
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 <andrej.mitrovich test.com> 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: template isInfinite(Range) { static if (isInputRange!Range && is(char[1 + Range.empty])) enum bool isInfinite = !Range.empty; else enum bool isInfinite = false; } 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, otherwise it's not valid (the is expression results to true if the argument is a valid type). If it's valid, then Range.empty never changes. If it never changes and it's always false, then it's infinite. -Steve
Sep 03 2010
== Quote from Steven Schveighoffer (schveiguy yahoo.com)'s articleOn Fri, 03 Sep 2010 11:12:29 -0400, Andrej Mitrovic <andrej.mitrovich test.com> wrote:That's really ugly code :-( Is there a way you could write an isStatic(expr) template? Using something like that would make the code a hell of a lot more readable. At the moment, the code itself does a very poor job of conveying what it's trying to accomplish. These SFINAE-like tricks should be black-boxed as much as possible, or (at the very least) commented so that people know what's going on.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, otherwise it's not valid (the is expression results to true if the argument is a valid type). If it's valid, then Range.empty never changes. If it never changes and it's always false, then it's infinite. -Steve
Sep 04 2010
Peter Alexander <peter.alexander.au gmail.com> wrote:== Quote from Steven Schveighoffer (schveiguy yahoo.com)'s articletemplate isStatic( alias T ) { enum isStatic = is( char[1+T] ); } unittest { int n = 3; assert( !isStatic!n ); assert( isStatic!1 ); enum r = 5; assert( isStatic!r ); } -- SimenOn Fri, 03 Sep 2010 11:12:29 -0400, Andrej Mitrovic <andrej.mitrovich test.com> wrote:That's really ugly code :-( Is there a way you could write an isStatic(expr) template? Using something like that would make the code a hell of a lot more readable. At the moment, the code itself does a very poor job of conveying what it's trying to accomplish. These SFINAE-like tricks should be black-boxed as much as possible, or (at the very least) commented so that people know what's going on.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, otherwise it's not valid (the is expression results to true if the argument is a valid type). If it's valid, then Range.empty never changes. If it never changes and it's always false, then it's infinite. -Steve
Sep 04 2010
On 09/04/2010 02:11 PM, Simen kjaeraas wrote:Peter Alexander <peter.alexander.au gmail.com> wrote:enum s = "Hello"; assert (isStatic!s); Gonna need more work than that.== Quote from Steven Schveighoffer (schveiguy yahoo.com)'s articletemplate isStatic( alias T ) { enum isStatic = is( char[1+T] ); } unittest { int n = 3; assert( !isStatic!n ); assert( isStatic!1 ); enum r = 5; assert( isStatic!r ); }On Fri, 03 Sep 2010 11:12:29 -0400, Andrej Mitrovic <andrej.mitrovich test.com> wrote:That's really ugly code :-( Is there a way you could write an isStatic(expr) template? Using something like that would make the code a hell of a lot more readable. At the moment, the code itself does a very poor job of conveying what it's trying to accomplish. These SFINAE-like tricks should be black-boxed as much as possible, or (at the very least) commented so that people know what's going on.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, otherwise it's not valid (the is expression results to true if the argument is a valid type). If it's valid, then Range.empty never changes. If it never changes and it's always false, then it's infinite. -Steve
Sep 06 2010
On Mon, Sep 6, 2010 at 18:47, Pelle <pelle.mansson gmail.com> wrote:On 09/04/2010 02:11 PM, Simen kjaeraas wrote:Why? That's exactly the behavior we want, or so it seems to me.Is there a way you could write an isStatic(expr) template? Usingenum s = "Hello"; assert (isStatic!s); Gonna need more work than that.template isStatic( alias T ) { enum isStatic = is( char[1+T] ); } unittest { int n = 3; assert( !isStatic!n ); assert( isStatic!1 ); enum r = 5; assert( isStatic!r ); }
Sep 06 2010
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(typeof( { 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 the range }())); We'd have a much cleaner call like so: enum bool isInputRange = validate!( { 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 the range }); But I haven't found a way to do it properly. If I call validate on a type R range which doesn't feature the empty() method, then no matter what the definition of validate is the compiler will error out because it sees the call to r.empty() in the function literal, and 'r' doesn't have an empty method. Philippe Sigaud Wrote:On Mon, Sep 6, 2010 at 18:47, Pelle <pelle.mansson gmail.com> wrote:On 09/04/2010 02:11 PM, Simen kjaeraas wrote:Why? That's exactly the behavior we want, or so it seems to me. <div class="gmail_quote">On Mon, Sep 6, 2010 at 18:47, Pelle <span dir="ltr"><<a href="mailto:pelle.mansson gmail.com">pelle.mansson gmai .com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"> <div><div></div><div class="h5">On 09/04/2010 02:11 PM, Simen kjaeraas wrote:<br> <blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"> Is there a way you could write an isStatic(expr) template? Using<br></blockquote> <br> template isStatic( alias T ) {<br> enum isStatic = is( char[1+T] );<br> }<br> <br> unittest {<br> int n = 3;<br> assert( !isStatic!n );<br> assert( isStatic!1 );<br> enum r = 5;<br> assert( isStatic!r );<br> }<br> </blockquote> <br></div></div> enum s = "Hello";<br> <br> assert (isStatic!s);<br> <br> Gonna need more work than that.<br> </blockquote></div><br>Why? That's exactly the behavior we want, or so it seems to me.<br><br><br>Is there a way you could write an isStatic(expr) template? Usingenum s = "Hello"; assert (isStatic!s); Gonna need more work than that.template isStatic( alias T ) { enum isStatic = is( char[1+T] ); } unittest { int n = 3; assert( !isStatic!n ); assert( isStatic!1 ); enum r = 5; assert( isStatic!r ); }
Sep 06 2010
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 bool isInputRange = is(typeof( { 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 the range }())); We'd have a much cleaner call like so: enum bool isInputRange = validate!( { 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 the range }); But I haven't found a way to do it properly. If I call validate on a type R range which doesn't feature the empty() method, then no matter what the definition of validate is the compiler will error out because it sees the call to r.empty() in the function literal, and 'r' doesn't have an empty method.What about __traits(compiles) ?
Sep 06 2010
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 the range }); } It does look nice. It would look even nicer if __traits gets renamed to meta. Stanislav Blinov Wrote:What about __traits(compiles) ?
Sep 06 2010
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 void popFront() { } property N front() { return test; } } 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 the range }); } If you uncomment some of those methods in class N, then you get back false, which is what you want. Currently isInputRange is defined like so in Phobos: template isInputRange(R) { enum bool isInputRange = is(typeof( { 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 the range }())); } It's getting close to LISP! :) Andrej Mitrovic Wrote: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 the range }); } It does look nice. It would look even nicer if __traits gets renamed to meta. Stanislav Blinov Wrote:What about __traits(compiles) ?
Sep 06 2010
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; } property void popFront() { } property N front() { return test; } } 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 the range }); } If you uncomment some of those methods in class N, then you get back false, which is what you want. Currently isInputRange is defined like so in Phobos: template isInputRange(R) { enum bool isInputRange = is(typeof( { 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 the range }())); } It's getting close to LISP! :)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 before those lovely __traits were introduced?..
Sep 06 2010
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); } :)
Sep 06 2010
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() { } property N front() { return test; } } template isInputRange(R) { enum bool isInputRange = isValidCode!( { 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 the range }); } template isValidCode(alias code) { enum bool isValidCode = __traits(compiles, code); } Instead of returning false, it will give out a compiler error. Stanislav Blinov Wrote: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); } :)
Sep 06 2010
Andrej Mitrovic wrote:That still won't work. Observe:Oops, sorry, I was too quick to conclude.
Sep 06 2010
On Mon, Sep 6, 2010 at 23:31, Andrej Mitrovic <andrej.mitrovich test.com>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.popFront; // can invoke next auto h = r.front; // can get the front of the range }); } template isValidCode(alias code) { enum bool isValidCode = __traits(compiles, code); } Instead of returning false, it will give out a compiler error.That's because the part between the curly braces is evaluated before being passed to the template. And there is no lazy alias. As Mafi said, you can use a string, it's still the best way to move code around in D. With q{ ... }, it's palatable. And no, before you try it, there is no way to pass the {...} to another template that would stringify it into a q{...} :-) Maybe, eventually, something like this: import std.stdio; template isValidCode(alias code) { template For(T) { enum bool For = __traits(compiles, code(T.init)); } } void main() { // use an anonymous templated function: alias isValidCode!((r) { if (r.empty) {} // can test for empty r.popFront; // can invoke next auto h = r.front; // c } ) isInputRange; // writeln(isInputRange.For!(int[])); } Except DMD doesn't like the commented-out line. Whaoh! Philippe
Sep 06 2010
I'm sorry, but what does q{..} mean? Philippe Sigaud Wrote:On Mon, Sep 6, 2010 at 23:31, Andrej Mitrovic <andrej.mitrovich test.com>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.popFront; // can invoke next auto h = r.front; // can get the front of the range }); } template isValidCode(alias code) { enum bool isValidCode = __traits(compiles, code); } Instead of returning false, it will give out a compiler error.That's because the part between the curly braces is evaluated before being passed to the template. And there is no lazy alias. As Mafi said, you can use a string, it's still the best way to move code around in D. With q{ ... }, it's palatable. And no, before you try it, there is no way to pass the {...} to another template that would stringify it into a q{...} :-) Maybe, eventually, something like this: import std.stdio; template isValidCode(alias code) { template For(T) { enum bool For = __traits(compiles, code(T.init)); } } void main() { // use an anonymous templated function: alias isValidCode!((r) { if (r.empty) {} // can test for empty r.popFront; // can invoke next auto h = r.front; // c } ) isInputRange; // writeln(isInputRange.For!(int[])); } Except DMD doesn't like the commented-out line. Whaoh! Philippe
Sep 06 2010
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 give a string to a higher order function like map, instead of a delegate, and you want to keep the visual illusion of a delegate: map!q{a * a}([1, 2, 3]) The problem comes straight from its purpose: is that it doesn't look like a string, so its true nature is a bit hidden; and this may cause some troubles. Another possible problem was discussed when the q{} syntax was introduced. It's not a clean syntax, it's a hack from the point of view of parsing/lexing too. It's handy, but it may cause troubles too. I am getting used to it, but it's a untidy hack and it will keep being nothing more than a hack. And sometimes hacks later come back and bite your bum. Bye, bearophile
Sep 06 2010
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 < bearophileHUGS lycos.com> 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 string. So it's a bit useful if you want to give a string to a higher order function like map, instead of a delegate, and you want to keep the visual illusion of a delegate: map!q{a * a}([1, 2, 3]) The problem comes straight from its purpose: is that it doesn't look like a string, so its true nature is a bit hidden; and this may cause some troubles. Another possible problem was discussed when the q{} syntax was introduced. It's not a clean syntax, it's a hack from the point of view of parsing/lexing too. It's handy, but it may cause troubles too. I am getting used to it, but it's a untidy hack and it will keep being nothing more than a hack. And sometimes hacks later come back and bite your bum. Bye, bearophile
Sep 06 2010
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 readable. bearophile < bearophileHUGS lycos.com> 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 string. So it's a bit useful if you want to give a string to a higher order function like map, instead of a delegate, and you want to keep the visual illusion of a delegate: map!q{a * a}([1, 2, 3]) The problem comes straight from its purpose: is that it doesn't look like a string, so its true nature is a bit hidden; and this may cause some troubles. Another possible problem was discussed when the q{} syntax was introduced. It's not a clean syntax, it's a hack from the point of view of parsing/lexing too. It's handy, but it may cause troubles too. I am getting used to it, but it's a untidy hack and it will keep being nothing more than a hack. And sometimes hacks later come back and bite your bum. Bye, bearophile
Sep 06 2010
On 09/07/2010 12:44 AM, bearophile wrote:Andrej Mitrovic:It's not the same. Try q{\n}. It's lexed like code.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 give a string to a higher order function like map, instead of a delegate, and you want to keep the visual illusion of a delegate: map!q{a * a}([1, 2, 3]) The problem comes straight from its purpose: is that it doesn't look like a string, so its true nature is a bit hidden; and this may cause some troubles. Another possible problem was discussed when the q{} syntax was introduced. It's not a clean syntax, it's a hack from the point of view of parsing/lexing too. It's handy, but it may cause troubles too. I am getting used to it, but it's a untidy hack and it will keep being nothing more than a hack. And sometimes hacks later come back and bite your bum. Bye, bearophile
Sep 07 2010
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 before those lovely __traits were introduced?..
Sep 06 2010
Andrej Mitrovic wrote:is(typeof( is used a lot in Phobos. There's some ~260 calls like that, a quick search revealed. :pHush! You're spoiling it! It's a part of intergalactic obfuscation plot ;p
Sep 06 2010
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, instead of this: enum bool isInputRange = is(typeof( { 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 the range }())); We'd have a much cleaner call like so: enum bool isInputRange = validate!( { 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 the range }); But I haven't found a way to do it properly. If I call validate on a type R range which doesn't feature the empty() method, then no matter what the definition of validate is the compiler will error out because it sees the call to r.empty() in the function literal, and 'r' doesn't have an empty method.You could just let your template get a string. Then validate!q{....} should work. It looks almost exactly the same but has a 'q'. Maybe you could even create an template overload which gets delegate which has always failing static assert with message "you forget the 'q'" but I don't know if template initialization comes before semantic analisys so I'm not sure this will work. Mafi
Sep 06 2010
On 09/06/2010 08:53 PM, Philippe Sigaud wrote:On Mon, Sep 6, 2010 at 18:47, Pelle <pelle.mansson gmail.com <mailto:pelle.mansson 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 ) { enum isStatic = is( char[1+T] ); } unittest { int n = 3; assert( !isStatic!n ); assert( isStatic!1 ); enum r = 5; assert( isStatic!r ); } enum s = "Hello"; assert (isStatic!s); Gonna need more work than that. Why? That's exactly the behavior we want, or so it seems to me.Sorry if I was unclear, that assert fails. Due to that you cannot add an integer and a string, not not that the string isn't static. It's an enum, so it definitely is static.
Sep 06 2010
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 <pelle.mansson gmail.com <mailto:pelle.mansson 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 ) { enum isStatic = is( char[1+T] ); } unittest { int n = 3; assert( !isStatic!n ); assert( isStatic!1 ); enum r = 5; assert( isStatic!r ); } enum s = "Hello"; assert (isStatic!s); Gonna need more work than that. Why? That's exactly the behavior we want, or so it seems to me.Sorry if I was unclear, that assert fails. Due to that you cannot add an integer and a string, not not that the string isn't static. It's an enum, so it definitely is static.
Sep 06 2010
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
Sep 06 2010