+ 1
Need a bit explaination of the code:
I have no clue how the code is doing whatever its doing- https://code.sololearn.com/cB5B1B6a166q/?ref=app
4 Answers
+ 5
C++ Template Meta-programming (TMP). It's like functional programming done on C++ but with the use of templates. It was discovered that the template system in C++ happened to be Turing complete on itself.
https://en.m.wikibooks.org/wiki/C%2B%2B_Programming/Templates/Template_Meta-Programming#History_of_TMP
The first time I looked it up was when Karl made the fast fib code:
https://code.sololearn.com/cYawX1B1K0zv/?ref=app
+ 3
I would argue that this is not really c++ but instead you're "programming" the compiler. (I increased your number (line 21: to 994 or something) and blew a compiler gasket :)
These pages may help you with respect to what you're doing:
https://mysticalprogramming.wordpress.com/2014/03/19/how-to-abuse-a-cpp-compiler/
A similar Factorial calculator (this is the error I caused)
https://stackoverflow.com/questions/22800245/recursive-template-instantiation-exceeded-maximum-depth-of-256
Though I haven't read them extremely carefully, they are in the 'code area' you're exploring and I've found that sometimes similar exercises have helped me.
+ 1
Thank you both for the info. Really appreciate it. It was in the "C++ programmers checklist" - (Mid level) Lesson. I have basic understanding of cpp and this just went over my head. Seems I have to continue reading a lot of books. Lol.
*The mystical programming link seems to be broken rn.
+ 1
[meta, compiler info]
Should you be interested, the "gcc" compiler has a flag you can add to see how quickly it actually does the template work:
gcc -ftime-report ...
"time report" dumps a lot of statistics about how much time the compiler is spending on various tasks (like template handling)
Since you're playing in compiler areas in the vicinity of "normal" code, you may as well know this profiling tool is available to you.
* Ref: Debugging options
https://gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html