Trait Template Technique

December 17, 2005
The STL makes some downright amazing use of the C++ language. One technique I've seen used throughout the STL is a traits pattern. If you've used the STL, you've seen it at the interface level and probably never took advantage of it. Anyhow, there's a nice article that goes into detail on what this technique is.
Support for internationalization was one of the mandates to the ANSI/ISO C++ Standard Library working group at its inception. What this would mean wasn't clear at the time, and has only gradually become clear over the course of five years. One thing we have discovered it to mean is that any library facility which operates on characters must be parameterized on the character type, using templates.Parameterizing existing iostream and string classes on the character type turned out to be unexpectedly difficult. It required inventing a new technique, which has since been found to be unexpectedly useful in a variety of applications.

This new technique is a clean way to abstract below an interface class for internal properties of an object.

Related Posts