News for hackers. Stuff that matters.
Re:Implementing a Type-safe printf in Rust by signa11 on Friday August 14, 2020 @06:38AM (#24156190)
> The issue with templates is that you can’t really type check them at the point of definition. Instead they need to be checked each time the template is used.

> This can make compilation slow but it can also make template writing very hard because a bug might only appear when a template is instantiated with certain types.

yup. templates are 'compiled' in 2 phases as follows:

- without instantiation at definition time, the code itself is checked for correctness, completely ignoring the template parameters.

- at instantiation time, the code is checked again to ensure that all parts depending on template parameters are valid.

the 2-phase translation breaks canonical notions about compile+link, where declarations of function is sufficient to compile its use...

There are no comments on this comment yet.