I have a function whose exact behaviour is controlled by a set of flags. Most of these are usually false. Having them all as parameters quickly becomes very messy.
I could create an enum for the flags:
enum ParseFlags { assignmentPossible = 1, commaDelimits = 2, isConst = 4 };
PExpression ParseExpr(unsigned int flags);
A bit better: now, when calling the function, I only have to specify the values I want to set, instead of a long list of bool
s.
However, I would like to know if there is a more elegant or more general way of passing a subset of options to a function. What if I have non-boolean options?
I'm looking for a C++ (Boost is ok) way to call a function like:
ParseExpr({ isConst: true; maxDepth: 5 });
where I can omit all values that I want to leave at their default.
What techniques and/or libraries exist for this?