map<string, int> Employees;
Employees.insert(map<string,int>::value_type("John A.",7582));
what does the value_type do?
what is the difference between pair() and make_pair()
map<string, int> Employees;
Employees.insert(map<string,int>::value_type("John A.",7582));
what does the value_type do?
what is the difference between pair() and make_pair()
map<string, int> Employees;
Employees.insert(map<string,int>::value_type("John A.",7582));
what does the value_type do?
what is the difference between pair() and make_pair()
The std::map<Key, Value>::value_type
is just a typedef to std::pair<Key, Value
>. So, there is no difference between them.
And the make_pair() is defined like the form:
template <typename T, typename U>
std::pair<T, U> make_pair(const T& first, const T& second) {
return std::pair<T, U>(first, second);
}
When you need a pair, the make_pair() function can be shorter than pair class, and less error-prone:
empolyees.insert(pair<string,int>("John A.", 7582));
empolyees.insert(make_pair("John A.", 7582));
The
std::map<Key, Value>::value_type
is just a typedef tostd::pair<Key, Value>
. So, there is no difference between them.And the
make_pair()
is defined like the form:
template <typename T, typename U>
std::pair<T, U> make_pair(const T& first, const T& second) {
return std::pair<T, U>(first, second);
}
When you need a pair, the
make_pair()
function can be shorter thanpair
class, and less error-prone:
empolyees.insert(pair<string,int>("John A.", 7582));
empolyees.insert(make_pair("John A.", 7582));
end quote.
Very good. I gave you an up vote.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.