digitalmars.D.learn - Inplace lambda execution
- confuzzled (16/16) Mar 28 I apologize for the newbie question but how do I get the lambda
- monkyyy (5/21) Mar 28 static map cant take a lamda; the syntax of templates are all
- Salih Dincer (24/30) Mar 28 In your original code, `typeof(T).stringof` was potentially
I apologize for the newbie question but how do I get the lambda the following to execute and return a string instead of the function pointer?: private static immutable string[] typeNames = [staticMap!(T => typeof(T).stringof, TypeSeq)]; I currently get this error: ```D 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)]; ^ ``` Thanks in advance. -- confuzzled
Mar 28
On Friday, 28 March 2025 at 12:12:45 UTC, confuzzled wrote:I apologize for the newbie question but how do I get the lambda the following to execute and return a string instead of the function pointer?: private static immutable string[] typeNames = [staticMap!(T => typeof(T).stringof, TypeSeq)]; I currently get this error: ```D 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)]; ^ ``` Thanks in advance. -- confuzzledstatic map cant take a lamda; the syntax of templates are all uglier `enum F(T)=T.stringof; enum typeNames = [staticMap!(F, TypeSeq)];` or something
Mar 28
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 79
Mar 28