Hi,
We are having trouble following Rule M9-3-3 when implementing interfaces using templates, similarly to the idea of "named requirements". I have read a similar post about this rule here and it's stated that the rule will be revised to also take the "override set" of virtual functions into account, making sure a function should be made const only if the whole "override set" can be made const.
Sometimes it might not be feasible to implement interfaces via virtual functions, and templates can be used to achieve the same result instead:
This pattern is commonly used e.g. in static dependency injection. We can pass any type `FooT` as long as it fulfills the interface `FooT::run`. For some types, `run` could be made const, but not all of them, therefore we get warnings from our static analyzers in such functions.
Will you consider this use case in the next revision of the rule? How do you suggest we work with it?
Thanks!
We are having trouble following Rule M9-3-3 when implementing interfaces using templates, similarly to the idea of "named requirements". I have read a similar post about this rule here and it's stated that the rule will be revised to also take the "override set" of virtual functions into account, making sure a function should be made const only if the whole "override set" can be made const.
Sometimes it might not be feasible to implement interfaces via virtual functions, and templates can be used to achieve the same result instead:
Code:
template <typename FooT>
void foo(FooT& f)
{
f.run();
}
This pattern is commonly used e.g. in static dependency injection. We can pass any type `FooT` as long as it fulfills the interface `FooT::run`. For some types, `run` could be made const, but not all of them, therefore we get warnings from our static analyzers in such functions.
Will you consider this use case in the next revision of the rule? How do you suggest we work with it?
Thanks!