First Draft: Implicit Type Template Instantiation via Constructors

Dennis dkorpel at gmail.com
Wed May 14 22:30:27 UTC 2025


On Wednesday, 14 May 2025 at 16:41:44 UTC, Sebastiaan Koppe wrote:
> Fair enough, but could the dip support it, or perhaps in the 
> future? The fact that we both expected it was a constructor - 
> and you could argue it actually is, on the grounds that it does 
> in fact construct an object - suggests more users would expect 
> it to work.

It could be added, but there's something to watch out for: as the 
DIP specifies, the search for constructors in a template is 
shallow, so just because the search didn't find one, doesn't mean 
there is none. I'm imagining a scenario where a constructor is 
hidden behind a mixin / static if or whatever, so Implicit 
Template Instantiation would assume a generated 'default 
constructor', but after the instantiation it ends up calling the 
written constructor instead but with template parameters resolved 
incorrectly. Granted, that might also happen when a 'hidden' 
constructor exists with a stronger match than the constructor 
found for IFTI, so I'm not sure. Perhaps an extra check can be 
added that the constructor used for deriving template parameters 
is the one that ends up actually being called, but it's getting 
rather complex.


More information about the dip.development mailing list