C++ guys hate static_if?

Jonathan M Davis jmdavisProg at gmx.com
Thu Mar 14 11:29:05 PDT 2013


On Thursday, March 14, 2013 13:07:16 Andrei Alexandrescu wrote:
> Very simple. Traditionally there's two crucial epochs known as
> compilation time and run time. (There's some minor distinctions like
> link time etc.) The whole notion of concepts and other type systems for
> templates is predicated on three crucial epochs: library compilation
> time, library user compilation time, and run time. The logic goes,
> someone writes a generic library and wants to distribute it to users.
> Users shouldn't ever see bugs caused by e.g. typos in the library.
> 
> So the crowd that use meta-type systems is formed of library writers who
> want to distribute libraries without ever instantiating them. I don't
> think that's a good crowd to cater for.
> 
> I've been surprised to figure how many people don't get this flow, or
> only have a vague image of it. Although meta-types are arguably "the
> right thing" to do, they're a lot less attractive once it's clear what
> scenarios they help.

The main problem is not people who don't unit test their templates but the 
fact that it's pretty much impossible to cover every possible instantiation of 
a template, and so it can be pretty easy to miss stuff. Better unit testing 
will obviously cover more, and on the whole, I think that that's a fine 
solution, but it would also be nice if the compiler caught more. However, 
given that it's pretty much a given that the compiler won't catch the stuff 
that's actually going to be a problem (e.g. a type with weird characteristics 
due to alias this or whatnot ends up not working correctly with a template), 
I'm not sure that it the compiler really can be improved to help out in any 
meaningful way. In general, the more the compiler can catch for you at compile 
time, the better, but there are definite limits to that even with a very smart 
compiler (and the smarter the compiler, the more likely it is to be buggy).

- Jonathan M Davis


More information about the Digitalmars-d mailing list