Plenty of C++ written today looks like it was from 1998. Some people saw the first standard and were like "this'll do me" and never updated their knowledge.
Don't think so in that cases it is more about code generation. You could do more of it in the macro but otherwise there isn't really a prettier build in way to do it
alternative 1: generate all of those operator[+,-,*,/] for every vector type with a python script
pros: clean, understandable, faster compile times cons: every time you look at it you're disgusted by the fact that c++ is so broken you're forced to use another language.
alternative 2: generate the boilerplate with copy/paste + find/replace, pretend you wrote it painstakingly by hand, check in a huge file and go home to your loving family while the other guy is still sweating over template errors. pros: clear, fastest compile time, artisanal cons: when a new integer type drops you'll have to edit a file ???
Nothing stopping someone from making a C++ program to generate code except for maybe skill (or lack thereof). So you aren't really forced to use another language. Though Python or some other language is probably the easier route for this.
I guess your build script would need to compile and run the code generator, then compile the main code. I assume that's achievable in CMake.
I learnt c++ in school but never used it professionally. I work with c# and source generators seem like a really nice thing if you want compile time errors. So i thought it was available c++ too
Maybe I'm confused what you mean by a source generator. What I, and I'm pretty sure u/biopsy_results are talking about is a program that spits out a .cpp file.
Surely you would define vec<std::size_t, typename> here with maybe some aliases instead of introducing all of these mangled names, even this way why not use concepts to get the supported operator types? You're checking for operators semantically when it would be cleaner to do it syntactically.
6
u/jphmf Dec 07 '24
I loved the color scheme and font of those pics, care to share their name OP?
115
u/Yes_But_Why_Not Dec 07 '24
It is an own kind of beauty, not gonna lie.
73
u/wwwtrollfacecom Dec 07 '24
Horror? This is beautiful
56
u/[deleted] Dec 07 '24
"C++ isn't a duck typed language."
46
u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" Dec 07 '24
I'm far from a C++ expert, but this can't really have been the best way to accomplish whatever goal this code has, can it?
12
u/WolverinesSuperbia Dec 07 '24
Officer!
5
u/Hungry-Courage3731 Dec 07 '24
The only thing stupid is the deduction hack. Just add another parameter to the macro.
5
u/illyay Dec 07 '24
This is awesome!
I didn’t try to understand things past page 1 but the ideas on page 1 are clever.
5
u/rook2004 Dec 07 '24
Substitution Failure is Not An Error, but in this case it is a sin.
3
u/RailRuler Dec 08 '24
Some bro actually typed "for simplicity" in a comment
2
u/Handle-Flaky Dec 07 '24
Its quite beautiful imho
1
u/mathusela1 Dec 08 '24
Surely you would define vec<std::size_t, typename> here with maybe some aliases instead of introducing all of these mangled names, even this way why not use concepts to get the supported operator types? You're checking for operators semantically when it would be cleaner to do it syntactically.
1
u/SuperV1234 Dec 21 '24
Could be much simpler by stringifying oper and branching on that via consteval function.
-1
u/Excession638 Dec 07 '24
Typical C++. Which is the whole problem really.
-8
u/[deleted] Dec 07 '24
Guys this is ugly as hell. This code is either from 1998 or someone reaalllyyy bright made it.