c++ - STL Map with structure -


i have structure:

struct tuple{int node; float cost}; std::map<int,std::set<tuple>> graph; 

i'd know how change comparison operator map container not insert key repeated value example:

ex.:

insert(1, {2,3}) insert(1, {2,4}) // not allowed insert(1, {4,3}) // allowed 

the containers used implement graph whenever node in node adjacency, can no longer inserted in adjacency. thanks.

you can't this. key of map int, there no way make @ tuple well.

maybe replace map std::set<std::pair<int, std::set<tuple>>, cmp> cmp is

struct cmp {   using value_type = std::pair<int, std::set<tuple>>;   bool operator()(const value_type& l, const value_type& r) const   {     if (l.first < r.first)       return true;     if (l.first > r.first)       return false;     return l.second < r.second;   } }; 

this works because std::set can examine part of value_type determine ordering of elements, whereas std::map can examine key_type

you need check definition of comparison though, it's not clear how expect use std::set<tuple> when tuple not lessthancomparable, , it's not clear expect insert(1, {3,4}) do, when {3,4} not valid initializer set<tuple>.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -