I am reading the source code of std::pair
implemented by GCC. And I got confused by the redundant typedef
as below. I know I must miss something, but just a few functions use first_type
and second_type
, like the move assignment operator. Why doesn’t it just use _T1
and _T2
? Thank you.
template<typename _T1, typename _T2>
struct pair
: public __pair_base<_T1, _T2>
{
typedef _T1 first_type; ///< The type of the `first` member
typedef _T2 second_type; ///< The type of the `second` member
_T1 first; ///< The first member
_T2 second; ///< The second member
/// Move assignment operator
constexpr pair&
operator=(pair&& __p)
noexcept(_S_nothrow_assignable<_T1, _T2>())
requires (_S_assignable<_T1, _T2>())
{
first = std::forward<first_type>(__p.first);
second = std::forward<second_type>(__p.second);
return *this;
}
};
6