From the course: Functional Programming in C++

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

Lazy evaluation with coroutines (infinite Fibonacci generator)

Lazy evaluation with coroutines (infinite Fibonacci generator) - C++ Tutorial

From the course: Functional Programming in C++

Lazy evaluation with coroutines (infinite Fibonacci generator)

- [Instructor] Alright, so coroutines let us create generators that produce values on demand, avoiding storing huge or infinite sequences of memory. We've already seen the Fibonacci sequence and so let's do a generator that can produce the Fibonacci sequence. In our code, we have a few libraries. One of them is kind of new, which is the coroutines, and we also have some old friends that we've seen before. Here we're going to create our generator, and this generator is going to be used by the Fibonacci sequence to create its values. In main, we have some code that uses the Fibonacci generator to produce values. And as we come down, we have a vector of numbers and that vector of numbers is going to get transformed, once again doing a scoring function on it. And then it's going to be sent to the output. And let's get into it 'cause we have a lot of code right now. So from inside of our generator function, we are going to do an STD optional, and that is going to be of type int, and it's…

Contents