Just make an observation that you do not have or want a run-time state. Partially output from your comments in a C ++ chat.
Functions do not have unique types. If you want to generate a unique type that captures which function should be called, use the template template for this.
template< typename t, tv > struct constant { typedef t type; static constexpr t value = v; operator t () { return v; } };
This is essentially the same as std::integral_constant , but removes integral from the name to save confusion. (Actually, I only tested this with std::integral_constant if you want to be cleaner for you.)
Now you can assign functions to individual types, which are defaultless constructive functors.
typedef constant< decltype( & padd ), padd > padd_type; typedef constant< decltype( & psub ), psub > psub_type; padd_type()( 2, 3 );
Note that stateless lambdas are converted to function pointers and are compatible with such a system, but you need to explicitly specify the type of the function pointer. Only decltype will not meet you.
Potatoswatter
source share