samedi 15 août 2020

Why does std::pair have two different constructors for both const reference and forwarding reference parameter?

From ISO standard (precisely N4860) std::pair synopsis:

constexpr explicit(see below) pair(const T1& x, const T2& y); // first constructor

template<class U1, class U2>
constexpr explicit(see below) pair(U1&& x, U2&& y); // second constructor

I can't seem to find any reason why the first constructor should be defined in conjunction with perfect forwarding constructor. Isn't perfect forwarding constructor sufficient enough to handle both copy, move cases? In which case does first constructor win in overload resolution?

Aucun commentaire:

Enregistrer un commentaire