The pair::second element in the pair is set to true if a new element was inserted or false if an equivalent key already existed. The single element versions (1) return a pair, with its member pair::first set to an iterator pointing to either the newly inserted element or to the element with an equivalent key in the map. Member type value_type is the type of the elements contained in the container, defined in map as pair (see map member types). These objects are automatically constructed from initializer list declarators. The function template argument InputIterator shall be an input iterator type that points to elements of a type from which value_type objects can be constructed. Notice that the range includes all the elements between first and last, including the element pointed by first but not the one pointed by last. Copies of the elements in the range [first,last) are inserted in the container. first, last Iterators specifying a range of elements. Member types iterator and const_iterator are defined in map as bidirectional iterator types that point to elements. Notice that this is just a hint and does not force the new element to be inserted at that position within the map container (the elements in a map always follow a specific order depending on their key). The function optimizes its insertion time if position points to the element that will follow the inserted element (or to the end, if it would be the last). Member type value_type is the type of the elements in the container, defined in map as pair (see map member types). Parameters val Value to be copied to (or moved as) the inserted element. The parameters determine how many elements are inserted and to which values they are initialized: The elements are always inserted in its respective position following this ordering. Internally, map containers keep all their elements sorted by their key following the criterion specified by its comparison object. ![]() Extends the container by inserting new elements, effectively increasing the container size by the number of elements inserted.īecause element keys in a map are unique, the insertion operation checks whether each inserted element has a key equivalent to the one of an element already in the container, and if so, the element is not inserted, returning an iterator to this existing element (if the function returns a value).įor a similar container allowing for duplicate elements, see multimap.Īn alternative way to insert elements in a map is by using member function map::operator.
0 Comments
Leave a Reply. |