-1

How can i insert in std::multimap <bool life, int id, std::pair < x, y >> ?

I ll use it for storing data's player and ia, Is it the best container for this?

chris
  • 60,560
  • 13
  • 143
  • 205
  • 7
    Have you tried `insert`? – Kerrek SB May 25 '16 at 11:03
  • 3
    The third template parameter of `std::multimap` is a comparator. I'm clueless as to what you're trying to do exactly. The explanation in the question and the bit of code you've provided make no sense to me. – chris May 25 '16 at 11:07
  • 1
    You can find useful documentation on [cppreference](http://en.cppreference.com/w/cpp/container/multimap) – Ilya Popov May 25 '16 at 11:13

1 Answers1

3

Not good at all.

The signature of a multimap is as follows:

template < class Key,                                   // multimap::key_type
           class T,                                     // multimap::mapped_type
           class Compare = less<Key>,                   // multimap::key_compare
           class Alloc = allocator<pair<const Key,T> >  // multimap::allocator_type
           > class multimap;

The use of your multimap is wrong.

The key is bool which means you use only two nodes 0 and 1 (or false´ andtrue`). So each inserted element is in either one of them, and thus you are actually enlisting elements with the same key. This is inefficient.

The value is an int. Well, alright though I wonder why would you want to map a bool to an int.

And lastly the error in your signature: pair is not a compare function, but the third template argument must be a compare function. If you leave it empty then by default if would be less<bool> (because you chose bool as the key).

Ely
  • 10,860
  • 4
  • 43
  • 64