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

preview_player
Показать описание

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

►Please like and subscribe to help the channel!
Рекомендации по теме
Комментарии
Автор

Really, really good. But it also shows, that C++ sometimes overuse the template library. From a semantic point of view, having an init value, does not bring any "value" to the semantic meaning of accumulate. It just satisfies the algorithm (the way it is programmed). And you showed, how easy it is to make mistakes (0 vs 0.0).
I guess using templates all over the place in C++ Std lib is the reason, that C++ has still has no international usable string class for utf-8. I think, it is difficult to do this with templates, when a char could be one to four bytes depending on the natural language. What do you think?
I am finding your series on algorithms exceptionally good. It shows the benefits but also the pitfalls of templates/algorithms in C++. And also the confusing compiler messages, when there is a little mistake in the syntax.

manfredkernMK
Автор

thank you so much for this great video!

gurashimozmel
Автор

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

willofirony
Автор

Could this be use in Linier Regression - AI

garthwhitelum
Автор

Nice👍, but what happened to Yoshi and Mario😢

Key_Capz_
join shbcf.ru