Rebinding policies

As we have already seen, the policy lists can get quite long. Often, we want to change just one policy and create a class just like that other one, but with a small change. There are at least two ways to do this.

The first way is very general but somewhat verbose. The first step is to expose the template parameters as typedefs, or aliases, inside the primary template. This is a good practice, anyway—without such aliases, it is very difficult to find out, at compile time, what a template parameter was in case we ever need to use it outside of the template. For example, we have a smart pointer, and we want to know what the deletion policy was. The easiest way, by far, is with some help from the smart pointer class itself: ...

Get Hands-On Design Patterns with C++ 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.