Implementing the named parameter idiom
C++ supports only positional parameters, which means arguments are passed to a function based on the parameter’s position. Other languages also support named parameters – that is, they specify parameter names when making a call and invoking arguments. This is particularly useful with parameters that have default values. A function may have parameters with default values, although they always appear after all the non-defaulted parameters.
However, if you want to provide values for only some of the defaulted parameters, there is no way to do this without providing arguments for the parameters that are positioned before them in the function parameters list.
A technique called the named parameter idiom provides a method to emulate named parameters and help solve this problem. We will explore this technique in this recipe.
Getting ready
To exemplify the named parameter idiom, we will use the control
class shown in the...