typeof alias in templates
Jarrett Billingsley
kb3ctd2 at yahoo.com
Mon Jul 21 08:45:40 PDT 2008
"JAnderson" <ask at me.com> wrote in message
news:g6286p$20q$1 at digitalmars.com...
> bearophile wrote:
>> In a template I need both the name and type of a given variable, but I
>> have found a problem that can be shown with this simple code:
>>
>> template Bar(string name) {
>> pragma(msg, name);
>> }
>> template Foo(alias A) {
>> alias Bar!(A.stringof) Foo;
>> }
>> void main() {
>> int x = 10;
>> alias Foo!(x) Nothing;
>> }
>>
>> I'd like this code to print "x" instead of "int". Is this a bug of DMD
>> V.1.033?
>>
>> (At the moment I have solved the problem giving the template the name of
>> the variable, and then finding its type with typeof(mixin("name")), but
>> it's a less elegant solution).
>>
>> Bye,
>> bearophile
>
> I imagine once x gets into the template all the compiler knows about it is
> its type.
See my post.
More information about the Digitalmars-d-learn
mailing list