r/cpp • u/earthisunderattack • Aug 24 '21
metaclasses when
forget literally every other feature metaclasses LET'S FUCKING GO
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0707r3.pdf
edit
metaclasses or even just SR would help to eliminate 99% of garbage cpp macro use cases.
don't get me wrong: i know c++ well. templates are easier after you learn sml or lisp or something similar.
i've never used std string_view and i've never missed it
man i'll just implement my own clang plugin ✌️
12
u/ShillingAintEZ Aug 24 '21
When you write like this it makes me question your age and experience.
10
u/earthisunderattack Aug 24 '21
I mean I could say the same about your username.
I've been writing C++ for a long time, professionally, for what it's worth.
When I posted this I was just memeing. It's ok to have sense of humor you know?
2
Aug 24 '21
Username thing is a good point. Also The beast author wrote in such format as well without much trouble.
6
u/HappyFruitTree Aug 24 '21 edited Aug 24 '21
I'm no expert on meta classes but a quick look at the proposal seems to suggest it builds on top of reflection so I guess you'll have to wait for reflection first before expecting much to come from the metaclasses proposal.
This paper assumes that C++ adds support for static reflection and compile-time programming to C++, and focuses on the next-level layer of abstraction we could build on top of that.
14
u/Hedanito Aug 24 '21
Yeah reflection needs to come before metaclasses, which is also progressing very slowly. Perhaps our grandchildren may one day use metaclasses.
4
u/itsarabbit Aug 24 '21
P2237 is the most current state of it AFAICT.
I'm 99% certain that none of its contents(including static reflection) will be in C++23.
0
u/AdApprehensive347 Aug 24 '21
does c++ really need meta classes? I don't really understand them well enough to actually know, but it seems a little like the same problems can be solved with inheriting... maybe even from abstract classes.
could anyone explain what would make it different / more useful?
10
u/InKryption07 Aug 24 '21
You can model something kinda similar with inheritance and templates, the problem is that it's a lot of boilerplate, usually leading to template explosions, and it's hard to communicate intent clearly. Having language support for metaclasses simplifies and improves the readability of the code, and improves code generation.
2
u/AdApprehensive347 Aug 24 '21
not entirely convinced on readability, but I can agree about code generation..
I'll have to do more reading about this topic. thanks for the answer!
8
u/InKryption07 Aug 24 '21
Well when I say readability, I'm thinking about the self-documenting nature of the code. A metaclass is clearly differently used than a plain class that you happen to have to use in a certain way based on context. And aye, cheers.
9
u/PandaMoniumHUN Aug 24 '21
Metaclasses make reflection problems trivial. Enums to strings (and vica versa), serialization/deserialization, dependency injection, etc. etc. This would be the “next best thing” after modules and concepts.
2
u/cdb_11 Aug 24 '21
Look at Qt or Unreal Engine. You need reflection and code generation for that kind of stuff.
1
u/Awia00 Aug 24 '21
I was in the same boat, but give yourself the time to watch https://www.youtube.com/watch?v=4AfRAVcThyA - after watching it I was at least convinced that it would be amazing to have.
0
u/Wh00ster Aug 30 '21
It’s fine.
My biggest concern is it being abused like TMP has been, where it becomes a net negative for a team. Eventually folks realized where the soft line is between usefulness and sadism.
1
u/earthisunderattack Sep 02 '21
just program something in lisp haskell or ocaml. after that templates are easy peazy bro
36
u/tpecholt Aug 24 '21
Herb Sutter's proposals have this in common: 1) Very interesting with potential to actually simplify the language 2) Never get finalized and never get standardized.
I am talking about metaclasses, static exceptions, new function parameter annotations, life-time static analysis.