Template Constraints

psychoticRabbit meagain at meagain.com
Sat Feb 24 04:13:30 UTC 2018


On Saturday, 24 February 2018 at 03:58:48 UTC, Jonathan M Davis 
wrote:
>
> Whether an implicit cast or an explicit cast makes more sense 
> depends entirely on what the code is doing, but either way, the 
> conversion needs to be forced inside the function, or you end 
> up with bugs. Far too often, when someone has a template 
> constraint that checks an implicit conversion, the function 
> doesn't actually force the conversion, and that can do anything 
> from resulting in some instantiations not compiling to causing 
> subtle bugs due to the argument being used without being 
> converted. In general, it's actually best to avoid conversions 
> entirely with generic code and force the caller to do the 
> conversion if a conversion is appropriate.
>
> But ultimately, what works best depends on what the code is 
> trying to do.
>
> - Jonathan M Davis

yeah it's hard to say much more without knowing what the code 
really wants to do..but presumably, you'd want to incorporate 
some contract programming in such a solution too, particulary 
given there's something potentially dodgy going on within such a 
function.



More information about the Digitalmars-d-learn mailing list