C++ guys hate static_if?

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Mar 14 11:13:33 PDT 2013


On Thu, Mar 14, 2013 at 06:09:26PM +0100, Andrej Mitrovic wrote:
> On 3/14/13, bearophile <bearophileHUGS at lycos.com> wrote:
> > This is an invalid argument. You can say the same thing for many
> > (most?) tests done by the compiler. Unit tests can't be sure to
> > verify all code paths inside a function or template.
> 
> No, it must do exactly that. If you have so many paths that you can't
> reasonably test all paths then your template or function is too
> complicated to begin with. The benefit here of D over C++ is that unit
> testing is cheap and doesn't require external libraries.
[...]

I think you're missing the point. The point is that concepts allow the
compiler to deduce template correctness *without* instantiating it with
every possible combination of types.

Right now, we *don't* have concepts, and therefore the only way to
ensure template correctness is to iterate over the exponential number of
combinations of template arguments. But if we *had* concepts, then the
compiler could reason about code correctness without needing to
explicitly check every instantiation -- thus effectively covering all
possible combinations, but without actually doing it. It's the
difference between proving a boolean statement is tautologous by
reducing it to true using known logic identities, vs. looping over every
combination of variable assignments and checking that they all evaluate
to true.


T

-- 
Кто везде - тот нигде.


More information about the Digitalmars-d mailing list