dimanche 26 janvier 2020

c++ 11 Trailing return type with decltype does not work as expected

Why this works "as expected"? My understanding is that this should not work:

template <class T, class U>
auto x(T a, U b) -> decltype(a<b ? a:b) {
    return a > b ? a : b;
}


int main() {
    cout << x<long, double>(1, 2.01) << endl;
    cout << x<long, double>(5, 2.01) << endl;

}

I have tried some other combinations such as:

auto x(T a, U b) -> decltype(a<b ? a:a) {
    return a > b ? a : b;
}

This way it does not compile, which is expected.

Aucun commentaire:

Enregistrer un commentaire