Stunt programming. Modern C++ is not about that.

Option Three


Ok. Sobering time. Cold head.  May I remind you (of course) we all know very well about the good old Function Object aka “Functor”. So let’s do a proverbial step back and use what we already know. Bellow is the very bland looking very traditional C++ solution.  I am not sure but perhaps even C++98 compiler could produce a decent byte code from this?

Testing begins here

This is one sober solution indeed. And working too. Usage seems simple and with no surprises.

Also the default argument issue is solved the C++ way. Modern or not. By using () operator overload, on the class.

What also is delivered is correct behavior in case of const required.  Code above is documented. And easy to maintain, expand or do whatever might be required down the line.