C + + STL map container member functions

Source: Internet
Author: User

The map container is used to find, set the key value and the element value, enter the key value, can get the element value. The elements in the map object are always ordered, unless they are inserted in an unordered order. It was created with a balanced tree. Find soon.

Function

Description , Note that there is no place where R can be replaced by it.

Map (Comp,alloc)

Map (it first, it last, Comp,alloc)

Map (map& x)

Comp For comparison functions, for sorting, alloc no bird it. Two parameters have a default value, can not be filled in, by default. Create an empty map .

Fills with a paragraph of elements and sets the sort function.

Copy x elements and create new Span style= "font-family: ' Times New Roman ';" >map map object Span style= "font-family: ' Times New Roman ';" >comp Span style= "font-family: the song Body;" > same.

mapped_type& m.at (key_type& k)

Returns the value of the element that corresponds to the value of the key, returned by the value of the reference type.

It M.begin ()

Returns the address of the 1 element, which is the first ordinal element of an order.

Const_it M.cbegin ()

function as above, but this element cannot be modified.

Const_it M.cend ()

Returns the address of the next element of the last element, not a modifiable element value. If the container is empty, the same Cbeginis returned.

Void M.clear ()

Empties all elements within the container.

int M.count (key_type& k)

Returns 1if the corresponding element of the key value k is present,otherwise 0.

Const_rit M.crbegin ()

Returns the address of the last element.

Const_rit M.crend ()

Returns the previous element address of the first element, which has no elements.

Pair<it,bool> m.emplace (key value, single element )

Insert. If the key value does not exist, it is inserted and returns a pair of arguments, respectively, for the element address and true. Otherwise, the address of the element that already exists and false is returned .

It M.emplace_hint (it pos, single Element)

Insert. If the key value does not exist, it is inserted into the position indicated by the POS and returns the address. Otherwise, the address of the element that already exists is returned. In this way, it is not necessarily guaranteed to be orderly.

BOOL M.empty ()

Returns trueif the container is empty,otherwise false.

It M.end ()

Returns the next element address of the last element. The address has no elements.

pair<it,it>              m.equal_range  (k)

Return key value k , returns two Span style= "font-family: ' Times New Roman ';" >begin

void M.erase (It pos)

int M.erase (k)

void M.erase (it first, it last)

Removes the element of the POS address.

Removes an element with a key value of K and returns the number of remaining elements.

Deletes an element and the last element is not deleted.

It M.find (k)

Look for an element with a key value of K and return its address. The address of the end is returned if it is not found.

Get_allocator

Don't understand

Pair<it,bool> M.insert (Val)

It M.insert (it pos, Val)

void M.insert (it first, it last)

Insert element. For example mymap.insert  ( std::p air<char,int> (' A ', b)  ) and return to its address and True pair can also be defined as a variable form.

Insert val to the specified pos position, return to Span style= "font-family: ' Times New Roman ';" >pos it points to the element that already exists.

Will first to last

Key_compare M.key_comp ()

Returns the comparison object for M. Similar to returning a function, this function can be used to compare The size of an element in two maps, with a parameter of two key values.

It M.lower_bound (k)

Returns the first address of the element with the key value K.

Int m.max_size ()

Returns the number of elements that can be accommodated.

map& operator= (const map& x)

Copy. Copies a map object to another object. Note:1 objects can contain multiple elements.

mapped_type& operator[] (const key_type& k)

You can use the subscript method to find the element. For example m[10] means the return of the element with a key value of ten , not the output key value.

RIT M.rbegin ()

Returns the address of the first element in reverse, with a reverse pointer.

RIT M.rend ()

Returns the address of the first element of the forward direction, which is the reverse address of the end.

int M.size ()

Returns the number of elements already present in the map.

It M.upper_bound (k)

Returns the end address of an element with a key value of K , which is another element.

void M.swap (map& x)

Change the name of the two map objects.

Value_compare M.value_comp ()

Returns an element comparison function that can be used to compare value sizes. For example Mymap.value_comp () (*it, highest) here the type of highest is pair type, that is std::p air <char,int>

BOOL operator== (const map<key,t,compare,alloc>& lhs,const map<key,t,compare,alloc>& RHS);

BOOL Operator!= (const map<key,t,compare,alloc>& lhs,const map<key,t,compare,alloc>& RHS);

BOOL operator< (const map<key,t,compare,alloc>& lhs,const map<key,t,compare,alloc>& RHS);

BOOL Operator<= (const map<key,t,compare,alloc>& LHS, const map<key,t,compare,alloc>& RHS);

BOOL Operator> (const map<key,t,compare,alloc>& LHS, const map<key,t,compare,alloc>& RHS);

BOOL Operator>= (const map<key,t,compare,alloc>& lhs,const map<key,t,compare,alloc>& RHS)

void swap (map& x, map& y)

Swaps the names of two map objects, two objects must be of the same type.

C + + STL map container member functions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.