I am trying to use a multimap with an integer key and values made of array of integers with 2 elements.
typedef std::multimap<int,int[2]> reverseHeightMap;
reverseHeightMap container;
When I try to add values like this:
container.insert( std::pair<int,int[2]>(5,{1,2}) );
I get:
error C2143: syntax error: missing ')' before '{'
I can't figure if I am failing at defining the data structure or inserting the value, or both. Thanks in advance for the help :)
insert() is used to insert new values to the multimap container and increases the size of the container by the number of elements inserted. Unlike a map container that checks the associated key already present then won't insert the elements but multimap has the feature of associating multiple elements to the same key.
We can find all values of a key in Multimap using is member function equal_range(). It accepts the key as an argument and returns a pair of multimap iterator. This returned pair has a range that represents the entries with given key.
Multimap is an associative container that contains a sorted list of key-value pairs, while permitting multiple entries with the same key. Sorting is done according to the comparison function Compare , applied to the keys. Search, insertion, and removal operations have logarithmic complexity.
You can't store arrays in containers because one of the requirements for the datatypes stored in STL containers is that they are assignable; arrays are not assignable.
Consider using std::vector
or std::array<int, 2>
.
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