Implicit Function Template Instantiation (IFTI) Question

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Apr 27 17:55:43 UTC 2020


On Mon, Apr 27, 2020 at 05:19:35PM +0000, jmh530 via Digitalmars-d-learn wrote:
> When using a template with multiple functions within it, is it
> possible to access the underlying functions directly?

Yes, but only if the template is not eponymous.


> Not sure I am missing anything, but what works when the functions are
> named differently from the headline template doesn't work when the
> functions are named the same.

Yes, when the template is eponymous, the name of the template becomes
the name of the eponymous member, and thus effectively hides the other
members from outside access.

This is actually useful when you want to write a template function with
internal implementation details that outside code cannot access no
matter what.  It's like a little encapsulation unit locked away behind
the public-facing eponymous member. I've used this on a few occasions
when I wanted template implementation details to be invisible even to
other code inside the same module.

(Interesting note: you can even stick unittests inside the template
block to test internal details, while still keeping said details away
from prying eyes in the rest of the module. :-P)


T

-- 
Doubtless it is a good thing to have an open mind, but a truly open mind should be open at both ends, like the food-pipe, with the capacity for excretion as well as absorption. -- Northrop Frye


More information about the Digitalmars-d-learn mailing list