Functors() - Function objects - functions with state | Modern Cpp Series Ep. 99

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

►Lesson Description: In this lesson we learn about a concept that probably sounds scarier than it really should be -- functors. These are 'function objects' in which we can 'hold state' (because they are a class), but use exactly like a function. Where functors() really shine is by allowing us to compose or partially compose results, and we're soon going to find out that lambda's (unnamed functions) are essentially functors behind the scenes, but both lambda's and functors are incredibly useful tools for using with the STL.

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

Your modern Cpp series is a hidden gem. Will for sure get more views!!

kenk
Автор

"A functor is an instance of type T whose call operator () is overloaded". This implies state.

bsdooby
Автор

I guess this is not the same as functors from category theory, where functors are a mapping from one category to another while preserving structure. So for example transforming one container into another. This feels more like a monad in which you wrap some object in another.

alexanderwhillas
Автор

Thank you very much for the video, Its really amazing !!! These videos really help me clear my concepts ! Everything is clearly or smoothly explained with perfect pace. Loved it😀😀

jtgywsu
Автор

You literally solved the problem I had with writing a better version of std::vector that would filter data. 3 lines of code and couple hours of work spared

michapawlik
Автор

Hi mike in sort function third parameter we are calling goblincomparator and then our functor gets called, but is this right way to called functor, because whenever we write goblincomparator() it should called constructor not functor

kirandhegaskar
Автор

Thanks for the vid! Is the comparator callable object more like a general function since it’s not storing any state? You could swap it out with a lambda and have the same effect right?

PaulFromMalta
Автор

Than you for the excellent teaching. If I may, I'd like to know how this works internally.

smarthumanism
Автор

I want to use one function from other cpp file in other cpp file without include. I mean I want to use functor here. The functor will be a callable function and I am going to use it in curl. Do you have any idea?

sumitpatil
Автор

Hi Mike, thank you for another great video! I do have one question: when you mention "we can take advantage of move assignment" at 10:15 by using the initializer list for the constructor, what do you mean exactly?

mamariomiamo
Автор

As always thanks Mike. Do you have any videos on std::function?

Vibratebalance
Автор

Yes very clear examples but one doubt - why are you returning NewResult which is passed in - instead of m_result1 and m_result2?

bimblebom
Автор

this just seems like a needlessly complicated way of creating an object

theforeskinsnatcher