Give the definition of a template class called HeterogeneousPair that is
like the class template Pair discussed in the section “Syntax for Class
Templates,” except that with HeterogeneousPair the first and second positions may store values of different types. Use two type parameters T1 and T2; all items in the first position will be of type T1, and all items in the second position will be of type T2. The single mutator method set_element in the template class Pair should be replaced by two mutator methods called set_first and set_second in the template class Heterogeneous-Pair. Similarly, the single accessor method get_element in the template class Pair should be replaced by two accessor methods called get_first and get_second in the template class HeterogeneousPair.
//Class for a pair of values, the first of type T1
//and the second of type T2:
template<class T1, class T2>
class HeterogeneousPair
{
public:
HeterogeneousPair( );
HeterogeneousPair(T1 first_value, T2 second_value);
void set_first(T1 value);
void set_second(T2 value);
T1 get_first( ) const;
T2 get_second( ) const;
private:
T1 first;
T2 second;
};
The member function definitions are as follows:
template<class T1, class T2>
HeterogeneousPair<T1, T2>::HeterogeneousPair( )
//Do nothing.
}
template<class T1, class T2>
HeterogeneousPair<T1, T2>::HeterogeneousPair
(T1 first_value, T2 second_value)
: first(first_value), second(second_value)
{
//Body intentionally empty.
}
template<class T1, class T2>
T1 HeterogeneousPair<T1, T2>::get_first() const
{
return first;
}
template<class T1, class T2>
T2 HeterogeneousPair<T1, T2>::get_second() const
{
return second;
}
template<class T1, class T2>
void HeterogeneousPair<T1, T2>::set_first(T1 value)
{
first = value;
}
template<class T1, class T2>
void HeterogeneousPair<T1, T2>::set_second(T2 value)
{
second = value;
}