digitalmars.D.learn - CTFE toUpper/toLower
- cal (17/17) Aug 29 2012 Given this code for CTFE on a string array:
- Philippe Sigaud (2/19) Aug 29 2012 And with no UFCS ? Did you try s ~= toUpper(field) ~ ", ";
- cal (3/4) Aug 29 2012 Yeah with or without UFCS, the second one fails.
- Jacob Carlborg (4/21) Aug 29 2012 It works for me. DMD 2.060 Mac OS X.
- Jacob Carlborg (8/9) Aug 29 2012 Oh, it does not. If I replace:
Given this code for CTFE on a string array:
enum E {one, two}
enum string[] fields = [EnumMembers!E].to!(string[]);
string print(string[] fields)
{
string s;
foreach(string field; fields)
{
s ~= field.toUpper ~ ", ";
}
return s;
}
pragma(msg, print(["one", "two"]));
pragma(msg, print(fields));
I am trying to understand why the first pragma produces correct
output but the second one fails in std.string.toUpper (cannot
interpret result ~= c at compile-time)?
Aug 29 2012
On Thu, Aug 30, 2012 at 2:13 AM, cal <callumenator gmail.com> wrote:
Given this code for CTFE on a string array:
enum E {one, two}
enum string[] fields = [EnumMembers!E].to!(string[]);
string print(string[] fields)
{
string s;
foreach(string field; fields)
{
s ~= field.toUpper ~ ", ";
}
return s;
}
pragma(msg, print(["one", "two"]));
pragma(msg, print(fields));
I am trying to understand why the first pragma produces correct output but
the second one fails in std.string.toUpper (cannot interpret result ~= c at
compile-time)?
And with no UFCS ? Did you try s ~= toUpper(field) ~ ", ";
Aug 29 2012
On Thursday, 30 August 2012 at 05:26:52 UTC, Philippe Sigaud wrote:And with no UFCS ? Did you try s ~= toUpper(field) ~ ", ";Yeah with or without UFCS, the second one fails.
Aug 29 2012
On 2012-08-30 02:13, cal wrote:
Given this code for CTFE on a string array:
enum E {one, two}
enum string[] fields = [EnumMembers!E].to!(string[]);
string print(string[] fields)
{
string s;
foreach(string field; fields)
{
s ~= field.toUpper ~ ", ";
}
return s;
}
pragma(msg, print(["one", "two"]));
pragma(msg, print(fields));
I am trying to understand why the first pragma produces correct output
but the second one fails in std.string.toUpper (cannot interpret result
~= c at compile-time)?
It works for me. DMD 2.060 Mac OS X.
--
/Jacob Carlborg
Aug 29 2012
On 2012-08-30 08:28, Jacob Carlborg wrote:It works for me. DMD 2.060 Mac OS X.Oh, it does not. If I replace: enum string[] fields = [EnumMembers!E].to!(string[]); With: enum string[] fields = ["one", "two"]; It works. -- /Jacob Carlborg
Aug 29 2012
On Thursday, 30 August 2012 at 06:30:50 UTC, Jacob Carlborg wrote:On 2012-08-30 08:28, Jacob Carlborg wrote:Yeah its weird because: enum string[] literalFields = ["one", "two"]; enum string[] enumFields = [EnumMembers!E].to!(string[]); pragma(msg, literalFields[0] == enumFields[0]); prints true, but toUpper works on the first and not the secondIt works for me. DMD 2.060 Mac OS X.Oh, it does not. If I replace: enum string[] fields = [EnumMembers!E].to!(string[]); With: enum string[] fields = ["one", "two"]; It works.
Aug 30 2012
On Thursday, 30 August 2012 at 17:38:48 UTC, cal wrote:On Thursday, 30 August 2012 at 06:30:50 UTC, Jacob Carlborg wrote:Replacing string[] with dstring[] for EnumMembers triggers a DMD bug, so I guess the CTFE interpreter is buggy even in the string[] case. Filed http://d.puremagic.com/issues/show_bug.cgi?id=8601
Aug 30 2012









"cal" <callumenator gmail.com> 