Previous section   Next section

Imperfect C++ Practical Solutions for Real-Life Programming
By Matthew Wilson
Table of Contents
Part Four.  Cognizant Conversions


Chapter 20. Shims

Shim: A thin, often tapered piece of material, used to fill gaps, make something level, or adjust something to fit properly.

This entire chapter revolves around one rather important imperfection that C++ shares with pretty much any language you can think of, so I'm going to start with the imperfection itself.

Imperfection: Logically related types in C++ can, and usually do, have incompatible interfaces and operations, rendering a generalized approach to type manipulation sometimes difficult and often impossible.


Needless to say, this is a pretty bold claim, and a serious problem. The concept of shims described here and the broader concept of explicit generalization supported by it have evolved in two separate threads over several years.

Ironically, shims first came about as a result of my naïve irritation with the specification of the std::basic_string template, insofar as it's not providing an implicit conversion operator. Thankfully, I woke up to myself before doing something as heinous as deriving from it and implementing a conversion operator in the derived class.[1] The original shim technique developed to address that case has, through a couple of evolutionary steps, ended up as the c_str_ptr access shim, which we see in section 20.6.1.

[1] In my consultative work I have seen this very thing on more than one occasion. <Sigh!>

The second was a continual frustration over the inconsistencies between so-called smart pointers and their raw pointer equivalents. The technique that has evolved provides a unified syntax for dealing with pointers, whether they are raw, simple, smart, or too-smart-for-their-own-good.


      Previous section   Next section