65. Customize intentionally and explicitly

Summary

Intentional is better than accidental, and explicit is better than implicit: When writing a template, provide points of customization knowingly and correctly, and document them clearly. When using a template, know how the template intends for you to customize it for use with your type, and customize it appropriately.

Discussion

A common pitfall when writing template libraries is providing unintentional points of customization—that is, points where a caller’s code can get looked up and used inside your template, but you didn’t mean for a caller’s code to get involved. It’s easy to do: Just call another function or operator the normal way (unqualified), and if one of its arguments happens to ...

Get C++ Coding Standards: 101 Rules, Guidelines, and Best Practices now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.