Inplace lambda execution
Salih Dincer
salihdb at hotmail.com
Fri Mar 28 23:12:41 UTC 2025
On Friday, 28 March 2025 at 12:12:45 UTC, confuzzled wrote:
> I currently get this error:
>
> sumtype.d(61): Error: cannot implicitly convert expression
> `(int T) => "int"` of type `string function(int T) pure nothrow
> @nogc @safe` to `immutable(string)`
> private static immutable string[] typeNames = [staticMap!(T
> => typeof(T).stringof, TypeSeq)];
In your original code, `typeof(T).stringof` was potentially
unnecessary, as `T` itself already refers to the type. The
`.stringof` property will convert the type directly to its string
representation.
```d
alias strADLANIM = strRepresent;
template strRepresent(T) {
enum strRepresent = T.stringof;
}
void main() {
import std.meta : AliasSeq, staticMap;
alias seq = AliasSeq!(int, string, double);
auto typeNames = [staticMap!(strRepresent, seq)];
import std.stdio : prn = writefln;
typeNames.prn!"%(%s\n%)";
// Will output something like:
// "int"
// "string"
// "double"
}
```
This will give you an array of type names as strings.
SDB at 79
More information about the Digitalmars-d-learn
mailing list