Yes, C++ has been catching up since C++11.
One thing C++ will never have is D's `static if`, which allows injecting declarations into scopes. Bjarne Stroustrup and others closed that door: https://isocpp.org/files/papers/n3613.pdf
One thing C++ will never have is D's `static if`, which allows injecting declarations into scopes. Bjarne Stroustrup and others closed that door: https://isocpp.org/files/papers/n3613.pdf
don't be so sure
https://github.com/lock3/meta/wiki/Metaprogramming-Introduct...
a lot of it is already implemented: https://cppx.godbolt.org/z/4arx6T
The following example is similar to C macros because it generates code as string and mixes it in as code but you can combine templates as well. This example generates a struct definition.
(Edit: formatting)
import std; // Entire package for brevity
auto memberDef(string type, string name) {
return format!" %s %s;"(type, name);
}
auto memberDefs(string[] members...) {
return (members
.chunks(2)
.map!(pair => memberDef(pair[0], pair[1])));
}
auto structDef(string name, string[] members...) {
return format!q{
struct %s {
%-(%s%)
}
}(name, memberDefs(members));
}
unittest {
mixin (structDef("Foo", "int", "i", "double", "d"));
auto f = Foo(42, 1.5);
assert((f.i == 42) && (f.d == 1.5));
}
void main() {
}See e.g. https://youtu.be/8c6BAQcYF_E