C++ STL numeric - std::accumulate (fold) | Modern Cpp Series

Поділитися
Вставка
  • Опубліковано 7 кві 2024
  • ►Full C++ Series Playlist: • The C++ Programming La...
    ►Find full courses on: courses.mshah.io/
    ►Join as Member to Support the channel: / @mikeshah
    ►Lesson Description: In this lesson we take a look at std::accumulate -- which has been around since C++ 98. This is a powerful algorithm also known as 'fold' for summing up, or otherwise performing a 'fold' operation using some binary operation. One gotcha is to make s sure the initial type matches your result (as this is determined at compile-time by the template parameter type). I'll show in this example how to think about 'fold' operations, and shortly we will talk about a related operation known as 'reduce'.
    ►UA-cam Channel: / mikeshah
    ►Please like and subscribe to help the channel!
    ►Join our free community: courses.mshah.io/communities/...
  • Наука та технологія

КОМЕНТАРІ • 12

  • @Chupe_chupe
    @Chupe_chupe Місяць тому +1

    Great video

  • @GaryChike
    @GaryChike Місяць тому +3

    First!!!

    • @MikeShah
      @MikeShah  Місяць тому +1

      That was fast! 😁

  • @willofirony
    @willofirony Місяць тому +1

    Great video, Mike. I am puzzled by the algorithms. C++ is an OOP language but the algorithms and iterators all reference the type rather than elements of the type. Now, I know that a functor or a lambda function to can be used to identify the element but wouldn't it be more efficient to have an overload that allowed one to specify the element that one is operating on. Alternatively, have an iterator that pointed to a specified element (which is just a const offset). As it is the library seems to just focus on containers of native types like the array languages. Just a thought, I know you didn't design or write the STD::library..

    • @MikeShah
      @MikeShah  Місяць тому +1

      C++ has multiple paradigms, so can use procedural, functional, OOP, generic, concurrent, etc. paradigms :) There are probably ways as you have suggested to speed up special cases -- perhaps some sort of pool for various containers with known and tightly packed memory.

    • @willofirony
      @willofirony Місяць тому

      @@MikeShah There was I, thinking they came up with C++ just for me and the projects I want to do. Thanks for your reply. I promise to try and share a little more. Take care Mike

    • @MikeShah
      @MikeShah  Місяць тому

      @@willofirony Cheers, of course!

  • @Key_Capz_
    @Key_Capz_ Місяць тому +3

    Nice👍, but what happened to Yoshi and Mario😢

    • @MikeShah
      @MikeShah  Місяць тому

      They might visit again in the software design playlist ;)

  • @garthwhitelum1971
    @garthwhitelum1971 Місяць тому +1

    Could this be use in Linier Regression - AI

    • @MikeShah
      @MikeShah  Місяць тому

      Sure, as part of the computation