Impossibly Fast C++ Delegates and different translation units

The so-called stub functions in Impossibly Fast C++ Delegates are static template member functions, which are basically template functions. The same applies for the improved variant Impossibly Fast C++ Delegates, Fixed.

So the question boils down to this:

Do instantiations of a template function (using the same template parameters and definition) in different translation units share the same function pointer address?

According to the C++ standard (ISO C++17, § 17.5.6.1), the answer is yes.

As @Pavel said in his answer, the same applied for the ISO C++03 standard (ISO C++03, § 14.5.5.1).

In other words this approach is standard compliant and delegates are safely comparable - their data compare equal if and only if they are bound to the same function and (in case of member functions) the same object.


The code is both standard compliant, and fine. I don't see any place where he violates ODR, and it is true that all instantiations of a function template with the same template parameters should have "the same address" (in a sense that pointers to functions should all be equal) - how this is achieved is not important. ISO C++03 14.5.5.1[temp.over.link] describes the rules in more detail.

So, a comparison could well be defined there in a conformant and portable way.