I recommend typedefcomplex templates such as container-related ones, so you can do something like:
typedef std::unordered_map<KeyType, std::shared_ptr<ValueType>> map_type;
map_type myMap;
std::for_each(myMap.begin(), myMap.end(),
[](typename map_type::value_type& pair){
pair.second->someMethod();
});
or without typedef
std::for_each(myMap.begin(), myMap.end(),
[](typename decltype(myMap)::value_type& pair){
pair.second->someMethod();
});
decltype gets the type of the object, you need to use the type name defined in the template, for this you use the keyword typename. This is necessary if the template specialization does not have this typedef.
source
share