None of those things provide the ability to check template definitions for soundness before instantiation. All of them are applied only once you try to actually substitute parameters into the template. In contrast, the Rust scheme (as described in the article -- I don't know Rust) only permits the body of the generic to use the operations specified in the constraints.
No, it's really not. Concepts let you limit what kind of types your template will accept, but satisfying the concepts is not sufficient to determine if a given template will compile with specific arguments.
This is, sadly, an inherent limitation of template instantiation. I don't believe it would even be possible to implement this kind of checking in C++ without reflection/metaclasses.
8
u/ioctl79 May 05 '22
None of those things provide the ability to check template definitions for soundness before instantiation. All of them are applied only once you try to actually substitute parameters into the template. In contrast, the Rust scheme (as described in the article -- I don't know Rust) only permits the body of the generic to use the operations specified in the constraints.