Troy shows his solution to the Fibonacci generator challenge in this video.
(bright tone)…- [Instructor] So, how did you do with challenge?…Hopefully, it went well for you.…Let's take a look at my solution.…The code for this is very similar to that…of the factorial program.…We need to create two template specializations.…One for zero and one for one,…and the base case is going to recursively call itself.…So, let's take a look at it in code.…So here, I have my include file and my namespace set up.…I have some code out here to render everything,…and let's go ahead and write the code,…and we're going to start off with our keyword template,…and we're going to say int n,…then, we're going to have a struct…and this is going to be called fibonacci.…
Then, inside of here, we'll have our enum,…and a value and it's going to be equal to fibonacci…and n - 1,…and then, use the scope resolution on the value…and it's + fibonacci…n - 2,…and once again, with the value,…then, we need a semicolon and another semicolon.…
Now, let's do the first of our specializations,…and so, our keyword template again,…the angle brackets are going to be empty this time.…
- Unit testing and functional programming
- Function and Lambda functions
- C++ templates
- Working with the Standard Template Library and Boost.Hana
- Functional reactive programming
Skill Level Intermediate
2. Functional Programming in Modern C++
3. Template Metaprogramming
4. Functional Reactive Programming
RxCpp library5m 21s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.