I am going through some code and not able to figure out below syntax:
freq_table[field_pm_value] = map<string, int>();
I am confused what is happening here "map string, int()". freq_table is of type
map<string, map<string, int> >& freq_table
The full code is https://github.com/vishalsingh8989/Star-Cubing-Algorithm/blob/master/src/csvreader.cpp
thanks
freq_table[field_pm_value] = map<string, int>();
This creates a new empty map
from string
to int
, and then copies it to the freq_table
entry for field_pm_value
If freq_table
has no entry for field_pm_value
, a new entry is created for it.
Maps are associative containers that store elements formed by a combination of a key value and a mapped value, following a specific order.
This structure is similar to: In a house you have different rooms, representing your "outter map container" map<string, map<string, int> >& freq_table
and in each room you have unique furniture and the amount of them. These furniture are defined in the "inner map".
As std::map
have unique keys, then you can't have 2 bedrooms in your house and can't have 2 beds in the same room.
In your case you are checking whether you "room" already have furniture in it, otherwise you construct an empty "room".
I am sorry about the awkward analogy, although I hope it may help.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.