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) - 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
-
-
-
-
-
Ranges and pipelines in C++20/2357s
-
(Locked)
Why use ranges? (transforming a collection)2m 47s
-
(Locked)
Combining filters and transforms3m 48s
-
(Locked)
Lazy evaluation with coroutines (infinite Fibonacci generator)13m 25s
-
(Locked)
Combining multiple range operations to transform collections4m 38s
-
(Locked)
Challenge: Build a functional pipeline42s
-
(Locked)
Solution: Build a Functional pipeline3m 44s
-
-
-
-
-
-
-
-
-