mardi 1 septembre 2015

Ambiguous call for overloaded function templates - even if one is more specialized?

Consider the following:

#include <iostream>
#include <utility>

template <size_t N>
using size_ = std::integral_constant<size_t, N>; 

template <size_t From>
void f(size_<From>, size_<From+1> ) // (1)
{ }

template <size_t From, size_t To>   // (2)
void f(size_<From>, size_<To> )
{ }

int main()
{
    f(size_<0>{}, size_<1>{});
}

Both gcc and clang report the call as ambiguous. Why? Isn't (1) more specialized than (2)?

Note: I know this is easily fixable with an extra enable_if_t<(To > From+1)> thrown into (2), but I wouldn't have thought I needed to do that.

Aucun commentaire:

Enregistrer un commentaire