Why code is not compiled?

#include <map> #include <set> template <typename T> void modify(T& A) { for (auto&& zzz : A) for (auto&& qqq : zzz.second) qqq.second = 1; }; int main() { std::map<std::pair<size_t, size_t>, std::set<std::pair<std::pair<size_t, size_t>, size_t>>> A; modify(A); } 

Closed due to the fact that it was off topic by Nicolas Chabanovsky 15 May '17 at 7:18 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Nicolas Chabanovsky
If the question can be reformulated according to the rules set out in the certificate , edit it .

    1 answer 1

    The values ​​of the std::set elements cannot be changed through an iterator. Just delete or add. Otherwise all sorting would break. To visualize this, consider that std::set is std::map without Value . It is not good to change keys in an associative array without re-sorting it.

    • And how can you do it then? - mia
    • @mia I do not quite understand what you want. Try replacing set<std::pair<A, B>> with std::map<A, B> . This is probably what you need. - int3
    • No, the types are what you need, std::pair<size_t, size_t> is the key. Each key corresponds to many other keys along with values. In short, this is a weighted graph of adjacency lists with vertices std::pair<size_t, size_t> - mia
    • So since this is the key, then make the std::map<std::pair<size_t, size_t> /* ключ */, size_t /* значение */> instead of the second template argument in the source type - int3