15 ms·
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
by acehreli 6y ago
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 https://isocpp.org/files/papers/n3613.pdf
- jcelerier 6y ago> One thing C++ will never have is D's `static if`, which allows injecting declarations into scope don't be so sure https://github.com/lock3/meta/wiki/Metaprogramming-Introductory-Tutorial https://github.com/lock3/meta/wiki/Metaprogramming-Introduct... a lot of it is already implemented: https://cppx.godbolt.org/z/4arx6T https://cppx.godbolt.org/z/4arx6T
- mhh__ 6y agoSeems horrifically complicated?
- jcelerier 6y agoit allows to generate code at basically every scope and to create your own "base language elements" like "struct", "class". AFAIK D does not allow for this, does it ?
- acehreli 6y agoD's templates has always been very strong and useful compared to C++'s. 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() { }
- uhhhhhhhhhhhhhh 6y agothink they'll ever get any good intellisense/autocomplete out of programs constructed like this? Templates are already pretty rough. Also need `constbreakpoint`s for compile time debugging.
- acehreli 6y agoThanks for letting me know. This seems to be far from being adopted into C++, if at all, right? Is the C++ community behind this effort?
- jcelerier 6y agoIt has been proposed by Herb Sutter a few years ago and has been worked on since by Andrew Dutton, so yes the c++ community is definitely behind it. See e.g. https://youtu.be/8c6BAQcYF_E https://youtu.be/8c6BAQcYF_E
- lionkor 6y agoSounds like something `if constexpr ()` comes close to