Adding pure to a function type
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Thu Oct 26 15:04:52 UTC 2017
So I'm trying to add "pure" to a function of which type is otherwise
deduced by the compiler:
package @property pure
T lazilyInitializedConstant(T, alias outOfBandValue, alias initializer)()
if (is(Unqual!T : T))
{
static T impl()
{
...
}
mixin("alias Fun = " ~ typeof(&impl).stringof ~ " pure;");
return (cast(Fun) &impl)();
}
The type of impl depends on T, and when converted to string is something
like e.g. "immutable(ulong) function() nothrow @nogc @system".
I tried "alias Fun = pure typeof(&impl);" which compiled (!), but didn't
work - Fun is not actually a pure type.
So I went with the hammer that will fix anything - a string mixin. Ideas
for a nicer solution?
Andrei
More information about the Digitalmars-d
mailing list