Home > Articles > Programming > C/C++

Extended STL: The Fibonacci Sequence

  • Print
  • + Share This
In this chapter Matthew Wilson looks at how we might represent the Fibonacci sequence as a collection, in the form of an STL sequence class, and then consider whether it might be better represented as an iterator, before finally coming back to seeing how a range-limited sequence is the most discoverable representation.
This chapter is from the book
  • If liberty means anything at all, it means the right to tell people what they do not want to hear.
  • —George Orwell
  • Subtlety chases the obvious in a never-ending spiral and never quite catches it.
  • —Nero Wolfe

23.1 Introduction

Those who enjoy mathematical elegance may share my appreciation of the Fibonacci sequence and its associated relationship, the Golden Ratio. In this chapter we're going to look at how we might represent this mathematical sequence as a collection, in the form of an STL sequence class, and then consider whether it might be better represented as an iterator, before finally coming back to seeing how a range-limited sequence is the most discoverable representation.

Unlike the other STL extensions described in this book, this one does not derive from any libraries. It is entirely pedagogical. As such, I trust you'll bear with me in some of the less practicable fancies used to illuminate the STL extension issues covered. For those who prefer real examples, worry not, this is the only such fanciful example in the whole book.

  • + Share This
  • 🔖 Save To Your Account