mercredi 25 décembre 2019

Unexpected Output Type From decltype

I've been experimenting with decltype, trying to figure out the potential benefits of it. I ran this very simple function:

template<class T, class U>
auto MyFunc(T t, U u) -> decltype(t < u ? t : u)
{
  return t < u ? t : u;
}

when calling the function:

auto d = MyFunc(3,3.5);

std::cout << d<<'\n';
std::cout<<"type: "<<typeid(d).name();

I get the following result:

3
type: d

My question is why the returned type is d (decimal) not i (integer)? Thanks!

Aucun commentaire:

Enregistrer un commentaire