Thread overview
aliases and .stringof
Apr 15, 2014
evilrat
Apr 15, 2014
Dicebot
Apr 15, 2014
Andrej Mitrovic
April 14, 2014
I noticed something odd with code of mine with recent D builds (recent from-git dmd, 2.065-branch ldc2).  I have a loop in my graph library which goes:

    foreach (G; TypeTuple!(IndexedEdgeList, CachedEdgeList))
    {
        foreach (directed; TypeTuple!(false, true))
        {
            alias Graph = G!directed;
            StopWatch watch;


            writeln("Graph type: ", (Graph.directed) ? "directed " : "undirected ", Graph.stringof);
            // ... etc.
        }
    }

Now, with earlier compiler versions, that would have resulted in output,

    Graph type: undirected IndexedEdgeList
    Graph type: directed IndexedEdgeList
    Graph type: undirected CachedEdgeList
    Graph type: directed CachedEdgeList

But with more recent compiler versions, what I'm seeing instead is:

    Graph type: undirected G!(false)
    Graph type: directed G!(true)
    Graph type: undirected G!(false)
    Graph type: directed G!(true)

Is this a bug, or an intended change in behaviour with respect to aliases?  I have to say that in this case at least it feels very problematic, as it completely obfuscates the actual types being used, and the whole point of what's being output is to display the type.
April 15, 2014
On Monday, 14 April 2014 at 19:01:22 UTC, Joseph Rushton Wakeling wrote:
>             alias Graph = G!directed;
>...
>             writeln("Graph type: ", (Graph.directed) ? "directed " : "undirected ", Graph.stringof);
>             // ... etc.

isn't this should be Graph.typeof.stringof ?
April 15, 2014
In general .stringof output is not defined by spec and is not guaranteed to stay same between releases. This specific change may be related to relatively recent consolidation of const-evaluation to use CTFE consistently, I remember Don and Kenji arguing on a very similar snippet.
April 15, 2014
On 4/15/14, Dicebot <public@dicebot.lv> wrote:
> In general .stringof output is not defined by spec and is not guaranteed to stay same between releases.

The spec mentions this as well: http://dlang.org/property.html#stringof

Quote:

-----
Note: Using .stringof for code generation is not recommended, as the internal representation of a type or expression can change between different compiler versions.

Instead you should prefer to use the identifier trait, or one of the Phobos helper functions such as fullyQualifiedName.
-----