Shims

The Shorter Oxford [13] defines a shim as "a thin slip, wedge or washer inserted in a space in machinery etc. to make parts fit or align." Shims are small, lightweight (in most all cases having zero runtime cost) components that help types "fit or align" into algorithms and client code. There are currently four fundamental shim types (with Access Shims a composite of Attribute and Conversion Shims):

Attribute Shims

These shims access some attribute, or aspect of state, of a typed instance. An example is STLSoft's get_ptr() shim, which accesses the raw pointer representation of a pointer, a smart-pointer class or any other type for which it is defined.

Attribute Shims are the most common type. Most are named in the form get_xyz() except where, like c_str_ptr(), they are part of a composite type.

Conversion Shims

Conversion Shims convert from one type to another, e.g., to_int(). They can involve the creation, and return, of temporaries, in which cases the return value must be used within their defining expression.

Apart from scenarios described in this article with c_str_ptr, where they need to have the same token names as other shim types, Conversion Shim names take the form of to_xyz().

Control Shims

Control shims are basically commands that are invoked or effected on the instance to which the shim is applied. A good example is the make_empty() shim, which can be defined for any kind of container, and which causes instances to be emptied of their "contents."

Their names take the form of an imperative, such as make_xyz(), set_abc().

Logical Shims

Logical Shims are similar to Attribute Shims, except that they deal only with logical concepts. For example, is_empty() asks/answers the question as to whether the instance is, or may be considered, empty. This can be applied to built-in types, pointers, and instances of user-defined types of any type for which the shim is defined.

Logical Shim names take the form of an interrogative, i.e., is_xyz().