Fix template type matching algorithm in the presence of wildcards.
The algorithm that chooses a type table among template arguments if the
type table entries have wildcards had two grave bugs:
- The intention is that entries that have wildcards in later positions are
better matches than those with wildcards in earlier positions. But the
method that penalized the candidates got this backwards.
- After the penalty of a candidate was found, it was tried to compare it to
the minimal penalty so far. But if a new minimum was found, it was
forgotten to update that minimum. As a consequence, the last candidate
was always chosen.
These bugs are now fixed. The vector<*> and vector<bool,*> templates were
used to test this algorithm, but that the correct candidate was always
chosen was just coincidence.