Home > Articles > Programming > C/C++

  • Print
  • + Share This
This chapter is from the book

23.6 Summary

This chapter has covered the issues related to implementing an unbounded (infinite) notional collection. It has highlighted the imperfect fit between such collections and the strict finitude of C++'s integral types and the assumed boundedness of STL iterator pairs. Primarily, we've encountered, and eventually avoided, violations of the Goose Rule (Section 10.1.3).

We've seen that contracts—a mechanism for ensuring program adherence to design—are a thoroughly inappropriate mechanism for dealing with the conflict between conceptual infinity and the finitude of the language's types. We considered exceptions, but this was discounted because the exception point not only was not exceptional but also was entirely predictable. The requirement that users provide the limit to the range was unavoidable.

We determined two equally valid and desirable ways of limiting the range. Each was unambiguous, and providing a discoverable implementation was straightforward. But supporting both led to ambiguous and undiscoverable syntax, with unattractive compromises. Applying true typedefs saved the day, providing a class interface that is clear and discoverable, with the positive side effect that client code is itself more transparent.

  • + Share This
  • 🔖 Save To Your Account