From: Daniel Krügler on
On 17 Mrz., 06:56, PGK <graham.k...(a)gmail.com> wrote:
> Would there be any disadvantage in using static_assert, instead of the
> extra sfinae template parameter method you present? For example:
>
> template<typename... U>
> void bar(Type t1, Type t2, U... ts) {
> static_assert(sizeof...(U) == 2 * sizeof...(Types), "Error");
> do_bar<0>(t1, t2, ts...);
> }

There is nothing fundamentally wrong with your alternative
approach. The real advantage of SFINAE becomes obvious,
if alternative overloads could still do something useful if the
other one doesn't match the criteria. In your example, there
is no such overload alternative. But I tend to prefer SFINAE
even in your situation (if not too much overhead), because
it has a similar compile-time behavior as a non-template
function called with non-matching parameters, e.g.

void foo();
void foo(int, int);

int main() {
foo(0); // error: no instance of overloaded function
// "foo" matches the argument list
}

and doesn't have the tendency to cause deep-instantiation
errors.

- Daniel


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]