C++ Template Metaprogramming

Поділитися
Вставка
  • Опубліковано 25 сер 2024
  • 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...

КОМЕНТАРІ • 25

  • @CodingTutorialsAreGo
    @CodingTutorialsAreGo  4 роки тому +2

    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

  • @ycombinator765
    @ycombinator765 2 роки тому +2

    The only programmer I have who looks as if he were a very calm English Professor.lol. thanks for this

  • @career800
    @career800 3 роки тому +6

    Underrated Channel!! Loved this video

    • @CodingTutorialsAreGo
      @CodingTutorialsAreGo  3 роки тому +5

      Thanks - it takes a while to build up momentum and to get the word out there.

  • @lit22006
    @lit22006 3 роки тому +8

    I recommend throwing C# and Java to the nearest dumpster and work only with cpp.

    • @CodingTutorialsAreGo
      @CodingTutorialsAreGo  3 роки тому +3

      Steady on!

    • @battosaijenkins946
      @battosaijenkins946 3 роки тому +3

      @@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~

  • @reductor_
    @reductor_ 4 роки тому +2

    Now you just need variable templates, saves needing to use the whole struct templates.

  • @kartikpodugu
    @kartikpodugu 11 місяців тому +2

    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?

    • @CodingTutorialsAreGo
      @CodingTutorialsAreGo  11 місяців тому +1

      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'.

    • @kartikpodugu
      @kartikpodugu 11 місяців тому

      @@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 ?

    • @CodingTutorialsAreGo
      @CodingTutorialsAreGo  11 місяців тому

      @@kartikpodugu No. Since the calculation is done by the compiler, the input can't be provided at runtime.

  • @__hannibaal__
    @__hannibaal__ Рік тому +1

    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.

  • @alexandrepedroza9217
    @alexandrepedroza9217 3 роки тому +2

    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.

    • @CodingTutorialsAreGo
      @CodingTutorialsAreGo  3 роки тому +7

      Yep, all the work is done by the compiler, and compilers haven't yet invented time travel.

    • @ycombinator765
      @ycombinator765 2 роки тому

      @@CodingTutorialsAreGo wtf. didn't expect that coming😂😂😂😂

    • @CtrlGame
      @CtrlGame Рік тому +1

      @@CodingTutorialsAreGo epic

  • @fathersson8641
    @fathersson8641 2 роки тому +1

    I can't figure out if the contrast is really high or the dude is wearing a lipstick

  • @lightps5515
    @lightps5515 2 роки тому +5

    KFC++

  • @mfdsrax2
    @mfdsrax2 3 роки тому +1

    Hey this is not even C++

    • @ichigo_nyanko
      @ichigo_nyanko 2 роки тому +2

      he switches to C++ half way through the video