Hello I have this simple question:
std::pair<int, int*> foo( int* p1, int* p2)
{
return make_pair<int, int*>(*p1, p2); // error
}
Why can I not supply the element types explicitly to the template function std::make_pair
? I know that the template deduces the element types from the arguments but why can I not specify them explicitly?
The thing that matters to me is if I implement my own pair
and make_pair
it works fine:
template<typename T, typename U>
struct Pair
{
T first_;
U second_;
};
template<typename T, typename U>
Pair<T, U> Make_Pair(T x, U y)
{
return Pair<T, U>{ x, y };
}
Pair<int, int*> foo(int* p1, int* p2)
{
return Make_Pair<int, int*>(*p1, p2); // works fine
// return Make_Pair(*p1, p2); // works fine
}