Let function and template parameters carry optionally a visibility attribute. For example:
void log(
string message,
private int line = __LINE__,
private string func = __FILE_FULL_PATH__
);
In another module, log can be called, but the line parameter cannot be set explicitly as it’s not visible. That way, the author or a library can ensure that magic default values for some parameters are indeed applied. The user has the advantage that it is harder to use such a function incorrectly, e.g. log("current step: ", i) accidentally passes something entirely unrelated to line.
Another example would be to alleviate the need for a private overload that has more parameters and is called by the public one.
Permalink
Reply