Blog post: What D got wrong
Petar
Petar
Wed Dec 12 06:16:08 UTC 2018
On Tuesday, 11 December 2018 at 10:45:39 UTC, Atila Neves wrote:
> A few things that have annoyed me about writing D lately:
>
> https://atilanevesoncode.wordpress.com/2018/12/11/what-d-got-wrong/
> No UFCS chain for templates.
> No template lambdas.
You can write code like this today via library that I wrote ;)
```
import std.conv : to;
auto filterMembers(alias pred, type)(type _)
{
import std.format : format;
alias MemberType(T, string name) = typeof(__traits(getMember,
T, name));
return l!(__traits(allMembers, type.get))
.staticMap!(name => π!(MemberType!(type.get, name.get),
name.get))
.staticFilter!pred
.staticMap!(t => "%s %s".format(t.get[0].stringof,
t.get[1]));
}
enum members = [ π!S.filterMembers!(t => is(t.get[0] : U[],
U)).get ];
pragma (msg, members.to!string); // Prints: ["string wxyz",
"int[4] uvwxyz"]
struct S
{
int x;
double xy;
int xyz;
string wxyz;
S* vwxyz;
int[4] uvwxyz;
}
```
Here's a full example: [2]
Though, I agree that this certainly not as elegant and
straightforward to use as what a language feature could provide.
[1]:
https://github.com/dlang/phobos/pull/5977/files#diff-33b50b4967214bfd07ca2ebb7bbc023cR1218
[2]:
https://run.dlang.io/gist/ZombineDev/a808c94857de84858accfb094c19bf77?compiler=dmd&args=-unittest%20-main
More information about the Digitalmars-d-announce
mailing list