On Wednesday, 4 June 2014 at 00:07:35 UTC, Jesse Phillips wrote:
On Tuesday, 3 June 2014 at 22:10:06 UTC, bioinfornatics wrote:
I do not see why it fail in debug output we see that tuple
have a
field with given name.
Your generated output (short and formatted)
alias TL = Tuple!(int,"x", bool function( const ref string
),
"xStartsWith ", bool function( const ref string ), "xEndsWith ",
int,"y", bool function( const ref string ), "yStartsWith ",
bool
function( const ref string ), "yEndsWith ");
TL.xStartsWith...
TL is a type.
TL variable;
variable.xStartsWith...
after a tmeplate update
--------------------------------
template toTuple(T){
static string maker(){
string assignFunction = "TL tl; ";
string statement = "alias TL = Tuple!(";
foreach(const memberName; __traits(allMembers, T)){
mixin(`alias f = Filter!(isSection,
__traits(getAttributes, T.` ~ memberName ~ `));`);
if( f.length == 1 )
{
statement ~= typeof(__traits(getMember, T,
memberName)).stringof ~ ",\"" ~ memberName ~ "\", "
~ " bool function( const ref string
), \"" ~ memberName ~ "StartsWith\","
~ " bool function( const ref string
), \"" ~ memberName ~ "EndsWith\", " ;
assignFunction ~= "tl." ~ memberName ~
"StartsWith = __traits(getAttributes, T." ~ memberName ~
")[0].startsWith; "
~ "tl." ~ memberName ~ "EndsWith
= __traits(getAttributes, T." ~ memberName ~ ")[0].endsWith; ";
}
}
statement = statement[0..$-2] ~ ") ;" ; // $-2 to remove
extra comma
return statement~assignFunction~ "alias toTuple = tl;";
}
pragma( msg, maker() );
mixin( maker() );
}
--------------------------------
which generate this string:
alias TL = Tuple!(int,"x", bool function( const ref string ),
"xStartsWith", bool function( const ref string ), "xEndsWith",
int,"y", bool function( const ref string ), "yStartsWith", bool
function( const ref string ), "yEndsWith") ;
TL tl;
tl.xStartsWith = __traits(getAttributes, T.x)[0].startsWith;
tl.xEndsWith = __traits(getAttributes, T.x)[0].endsWith;
tl.yStartsWith = __traits(getAttributes, T.y)[0].startsWith;
tl.yEndsWith = __traits(getAttributes, T.y)[0].endsWith;
alias toTuple = tl;
This produce an error at mixin step:
attribute.d-mixin-62(62): Error: no identifier for declarator
tl.xStartsWith
attribute.d-mixin-62(62): Error: Declaration expected, not '='
attribute.d-mixin-62(62): Error: no identifier for declarator
tl.xEndsWith
attribute.d-mixin-62(62): Error: Declaration expected, not '='
attribute.d-mixin-62(62): Error: no identifier for declarator
tl.yStartsWith
attribute.d-mixin-62(62): Error: Declaration expected, not '='
attribute.d-mixin-62(62): Error: no identifier for declarator
tl.yEndsWith
attribute.d-mixin-62(62): Error: Declaration expected, not '='
;