Ever feel the compiler isn't pulling its weight and your program is doing all the work? Template metaprogramming may be the answer. Source code available at: github.com/Jas...
Any questions? Fire away. See the source code at github.com/JasperKent/Template-Metaprogramming. I've added additional examples for the Fibonacci sequence and prime numbers. A video and source code for a more efficient C# version will follow, so subscribe at: ua-cam.com/channels/qWQzlUDdllnLmtgfSgYTCA.html
@@CodingTutorialsAreGo Waiiiiiit a minute, to mention C++ Template and hop onto C# is almost insulting in a way. And don't get me wrong, I use C# too, but I also enjoy C++ and to anyone who knows the ins and outs of C++, there is nothing better with so much freedom. I'm sorry, I'm VERY disappointed @Coding Tutorials~
In a word: performance. A runtime calculation executes every time you run the code. A compile time calculation only executes once. That said, IMHO, the feature is more in the category of 'interesting' than 'useful'.
@@CodingTutorialsAreGo Sir, But still we are not providing that value of 6, 100, 1000 at runtime, and providing that value also at compile time. So, only when we want to run the program for a particular value multiple times, the advantage of single time compilation is helpful. So, we have to compile the code each time we change the value. Can we take the value that goes into the TMP also at run time, and still get improvement in performance ?
I’m doing now that; but with more generalization of meaning of function that use and I put first _3Nplus1(integer type value(int, long, unsigned long ,…)) function and starting and 8 another function : And i m trying to go farther ; To use like 3Nplus1(uint k, ll x) = x%k * x/k + (x%k == 1)*(k*x+1) ; but also for arbitrary function f() and we make iteration till converge U(function f, Type value)->long long { int k;while(x < value){ x = f(x); k++} ….. return k;} … and more Thanks.
What happens if you instantiated the template with a variable? For example, if we asked the user to input a number and then tried to instantiate the template of that number, it would break, right? I couldn't get it to work that way and it makes sense to me, since we can't know which value to use at compile time.
Any questions? Fire away.
See the source code at github.com/JasperKent/Template-Metaprogramming. I've added additional examples for the Fibonacci sequence and prime numbers.
A video and source code for a more efficient C# version will follow, so subscribe at: ua-cam.com/channels/qWQzlUDdllnLmtgfSgYTCA.html
The only programmer I have who looks as if he were a very calm English Professor.lol. thanks for this
Underrated Channel!! Loved this video
Thanks - it takes a while to build up momentum and to get the word out there.
I recommend throwing C# and Java to the nearest dumpster and work only with cpp.
Steady on!
@@CodingTutorialsAreGo Waiiiiiit a minute, to mention C++ Template and hop onto C# is almost insulting in a way. And don't get me wrong, I use C# too, but I also enjoy C++ and to anyone who knows the ins and outs of C++, there is nothing better with so much freedom. I'm sorry, I'm VERY disappointed @Coding Tutorials~
Now you just need variable templates, saves needing to use the whole struct templates.
Nice idea. Know any languages that do that?
@@CodingTutorialsAreGo its this little one called c++
@@reductor_ :)
Sir, what is the use of doing everything here at compile time ? Why do we have to do at compile time and not at runtime?
In a word: performance. A runtime calculation executes every time you run the code. A compile time calculation only executes once. That said, IMHO, the feature is more in the category of 'interesting' than 'useful'.
@@CodingTutorialsAreGo Sir, But still we are not providing that value of 6, 100, 1000 at runtime, and providing that value also at compile time. So, only when we want to run the program for a particular value multiple times, the advantage of single time compilation is helpful. So, we have to compile the code each time we change the value. Can we take the value that goes into the TMP also at run time, and still get improvement in performance ?
@@kartikpodugu No. Since the calculation is done by the compiler, the input can't be provided at runtime.
I’m doing now that; but with more generalization of meaning of function that use and I put first
_3Nplus1(integer type value(int, long, unsigned long ,…)) function and starting and 8 another function :
And i m trying to go farther ; To use like 3Nplus1(uint k, ll x) = x%k * x/k + (x%k == 1)*(k*x+1) ; but also for arbitrary function f() and we make iteration till converge
U(function f, Type value)->long long { int k;while(x < value){ x = f(x); k++} ….. return k;} … and more
Thanks.
What happens if you instantiated the template with a variable? For example, if we asked the user to input a number and then tried to instantiate the template of that number, it would break, right? I couldn't get it to work that way and it makes sense to me, since we can't know which value to use at compile time.
Yep, all the work is done by the compiler, and compilers haven't yet invented time travel.
@@CodingTutorialsAreGo wtf. didn't expect that coming😂😂😂😂
@@CodingTutorialsAreGo epic
I can't figure out if the contrast is really high or the dude is wearing a lipstick
KFC++
🤣
Hey this is not even C++
he switches to C++ half way through the video