Potential abuse of .stringof

Meta via Digitalmars-d digitalmars-d at puremagic.com
Wed Jun 10 11:37:18 PDT 2015


On Wednesday, 10 June 2015 at 15:39:51 UTC, Andrei Alexandrescu 
wrote:
> On 6/9/15 11:59 PM, Mike wrote:
>> Seems to return the correct result, although it 
>> "TheUnnameable" cannot
>> be cut and pasted outside of the createVoldemortType scope.  
>> Perhaps
>> that's the limitation you are referring to.
>
> Yah, and the problem here is that outside createVoldemort, the 
> same typename could refer to a different type. -- Andrei

import std.stdio;
import std.traits;

auto createVoldemortType(int value)
{
     struct TheUnnameable
     {
         int getValue() { return value; }
     }
     return TheUnnameable();
}

void main()
{
	auto voldemort = createVoldemortType(123);
         //f57.main.voldemort
	writeln(fullyQualifiedName!voldemort);
}

fullyQualifiedName doesn't work for Voldemort types; is there a 
way that we could change this? Then at least you could do:

fullyQualifiedName!voldemort ~ typeof(voldemort).stringof


More information about the Digitalmars-d mailing list