0

For my application, it is much more convenient and logical to hold a map of websocketpp::connection_hdls as keys in a map, but I've found that this could be potentially dangerous since they are weak_ptrs.

However, it's been claimed that a boost::unordered_map may not break if a weak_ptr key expires.

Is that true? If so, how can one be constructed to hold connection_hdls as keys as well as be inserted, erased, and found/counted? Also, what is necessary to be able to loop through them, such as with a for?

This is currently beyond my skillset, so I'm unsure of what I'm looking at.

Community
  • 1
  • 1

1 Answers1

1

boost::unordered_map could be slow on iteration, thus, I would suggest that you could store all websocketpp::connection_hdl in a std::vector. For the map you can use pointers as keys: boost::unordered_map<websocketpp::connection_hdl*, X>

Philipp H.
  • 1,513
  • 3
  • 17
  • 31
  • Yes. Or if O(log(n)) time on iteration and lookup is okay for you, use a std::map. – Philipp H. Apr 20 '14 at 10:10
  • All stl containers are what you put in stays there. You have to remove expired connections out of every container yourself. – Philipp H. Apr 20 '14 at 19:20
  • Thank you again! Does this answer and your comments conflict with this? http://stackoverflow.com/a/23156251/1382306 This is all well beyond my skills, and I need to get this right. Thank you so much in advance! –  Apr 20 '14 at 19:32
  • 1
    The pointer will always point to some address, order or hash is always defined. Just take care of removing the entries of expired connections. – Philipp H. Apr 22 '14 at 13:02