Why is implicit conversion from <int64_t, int64_t> pair to <int, int> pair allowed?

I noticed some cases where std :: pair would be implicitly converted to std :: pair of a different type without warning, but I can't figure out why. I've looked at the constructors for std :: pair and can't figure it out. Can anyone explain this to me?

Example:

 std::pair<int,int> a = std::pair<int64_t, int64_t>(1,2);

      

Doesn't give any warnings with clang -Wall -Weverything.

+3


source to share


1 answer


Constructor

template<class U, class V> pair(const pair<U, V>& p);

      



allows copying from any pairs, if the first element p

can be converted to the first element of the pair to be built, and the same for the second elements.

+2


source







All Articles