What is the purpose of std::make_pair
?
Why not just do std::pair
?
Is there any difference between the tw
There is no difference between using make_pair
and explicitly calling the pair
constructor with specified type arguments. std::make_pair
is more convenient when the types are verbose because a template method has type deduction based on its given parameters.
For example,
std::vector< std::pair< std::vector<int>, std::vector<int> > > vecOfPair;
std::vector<int> emptyV;
// shorter
vecOfPair.push_back(std::make_pair(emptyV, emptyV));
// longer
vecOfPair.push_back(std::pair< std::vector<int>, std::vector<int> >(emptyV, emptyV));