I know that in std::map we have a key and a corresponding mapped value.
Now in the Data Type that i mentioned, key would be of type std::set<long> or std::pair<long, long> . So, is that valid keeping in mind that in map values are stored on the bases on sorted value of keys. So, is std::map<std::set<long>, double> AND std:map< std::pair<long, long>, double> valid ?
std::set has an operator< which performs a lexicographical comparison between two sets of the same type. So yes, an std::set<T> can be a valid key for a map.
An std::pair<T1,T2> also has an operator< implementing a lexicographical comparison, so std::map<std::pair<T1, T2>, T3> would also be valid iff both T1 and T2 have a less-than comparison operator< implementing strict weak ordering. So the requirements are tighter. Both T1 and T2 need the comparison to be keys of a map, but they do not need it to form a valid pair. So a valid pair does not necessarily form a valid key for a map. On the other hand, you can instantiate the map with your own comparison criteria.
std::map<std::pair<T1, T2>, T3, Comp> m;
No, the syntax is wrong. What you want is std::map<std::set<a_type_here>, double>, so add the template parameter for set.
Note a_type_here should have operator< or you need to use std::set<a_type_here, compare_function>
What you seem to want is: std::map<std::pair<long, long>, double> mapping
Example of how to use; mapping[std::make_pair(1,2)] = 0.1;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With