Why typedef's shouldn't have been removed :(

Andrej Mitrovic andrej.mitrovich at gmail.com
Sun May 6 09:51:43 PDT 2012


On 5/6/12, John Campbell <je at campbe.ll> wrote:
> Since I don't see it discussed in this thread: Which problems do
> you have with http://dlang.org/phobos/std_typecons.html#Typedef?

Here's one:
struct Class
{
    mixin CompositeFields;
    SymID[] baseIDs;  // indexed base class IDs
}

alias std.typecons.Typedef!Class Struct;
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\typecons.d(3030): Error:
struct dgen.types.Class no size yet for forward reference

Another problem is generics. I've got a function that creates a string
mixin. It returns hash fields with various value types, e.g. it
generates code like this:
File[string] FileMap;
Namespace[string] NamespaceMap;
Class[string] ClassMap;

It basically generates the name of each field like so:
%s[string] %sMap

Where %s is the type name, picked up by either .stringof or to!string().
However it can't pick up the name of the alias itself, the hash field
for the Struct type would end up looking like this:
Typedef!(Class,Class(null))[string] Typedef!(Class,Class(null))Map;

That's an invalid field name there ("Typedef!(Class,Class(null))Map").
What I really need is the name of the alias itself, so it would pick
"Struct" from here:
alias std.typecons.Typedef!Class Struct;

and generate the field as:
Struct[string] StructMap;

A workaround is to have a mangle function. Since I use a helper
function to access individual fields the name of the fields doesn't
matter much so mangling would be ok for my needs. But even though
there's a demangle function in druntime, there's no mangle function..


More information about the Digitalmars-d mailing list