reflection over templates

simendsjo simendsjo at gmail.com
Wed Mar 19 12:32:57 PDT 2014


On 03/19/2014 05:34 PM, Adam D. Ruppe wrote:
> On Wednesday, 19 March 2014 at 16:10:52 UTC, Dicebot wrote:
>> Wait just a bit more
>> https://github.com/D-Programming-Language/dmd/pull/3380 :)
>
> megarox. Make it so.

Nice. I have some ugly hacks that's probably full of bugs for this (look 
at the bottom):

template isLValue(T)
{
     enum isLValue = false;
}
/// ditto
template isLValue(alias T)
{
     enum isLValue = !isType!T && isAddressable!T && __traits(compiles, 
{ Unqual!(TypeOf!T) t = TypeOf!(T).init; });
}
/// ditto
template isRValue(T)
{
     enum isRValue = false;
}
/// ditto
template isRValue(alias T)
{
     static if(isType!T)
         enum isRValue = false;
     else
         enum isRValue = __traits(compiles, { typeof(T) t = T; }) && 
!isAddressable!T;
}

template isValue(T)
{
     enum isValue = false;
}
/// ditto
template isValue(alias T)
{
     enum isValue = isLValue!T || isRValue!T;
}
/// ditto
template isType(T)
{
     enum isType = is(T);
}
/// ditto
template isType(alias T)
{
     enum isType = is(T) || isCallable!T;
}
template isTemplate(T)
{
     enum isTemplate = !(isValue!T || isType!T);
}
template isTemplate(alias T)
{
     enum isTemplate = !(isValue!T || isType!T);
}



More information about the Digitalmars-d-learn mailing list