public member function
<map>
std::map::map empty (1)explicit map (const key_compare& comp = key_compare(), const allocator_type& alloc = allocator_type());range (2)
template <class InputIterator> map (InputIterator first, InputIterator last, const key_compare& comp = key_compare(), const allocator_type& alloc = allocator_type());copy (3)
map (const map& x);empty (1)
explicit map (const key_compare& comp = key_compare(), const allocator_type& alloc = allocator_type());explicit map (const allocator_type& alloc);range (2)
template <class InputIterator> map (InputIterator first, InputIterator last, const key_compare& comp = key_compare(), const allocator_type& = allocator_type());copy (3)
map (const map& x);map (const map& x, const allocator_type& alloc);move (4)
map (map&& x);map (map&& x, const allocator_type& alloc);initializer list (5)
map (initializer_list<value_type> il, const key_compare& comp = key_compare(), const allocator_type& alloc = allocator_type());empty (1)
map();explicit map (const key_compare& comp, const allocator_type& alloc = allocator_type());explicit map (const allocator_type& alloc);range (2)
template <class InputIterator> map (InputIterator first, InputIterator last, const key_compare& comp = key_compare(), const allocator_type& = allocator_type());template <class InputIterator> map (InputIterator first, InputIterator last, const allocator_type& = allocator_type());copy (3)
map (const map& x);map (const map& x, const allocator_type& alloc);move (4)
map (map&& x);map (map&& x, const allocator_type& alloc);initializer list (5)
map (initializer_list<value_type> il, const key_compare& comp = key_compare(), const allocator_type& alloc = allocator_type());map (initializer_list<value_type> il, const allocator_type& alloc = allocator_type());
Construct map
Constructs a map container object, initializing its contents depending on the constructor version used:The container keeps an internal copy of
allocand
comp, which are used to allocate storage and to sort the elements throughout its lifetime.
The copy constructor
(3)creates a container that keeps and uses copies of
x's
allocatorand
comparison object.
The storage for the elements is allocated using this internal allocator.
The container keeps an internal copy of
alloc, which is used to allocate and deallocate storage for its elements, and to construct and destroy them (as specified by its
allocator_traits). If no
allocargument is passed to the constructor, a default-constructed allocator is used, except in the following cases:
- The copy constructor
(3, first signature)creates a container that keeps and uses a copy of the allocator returned by calling the appropriate
selected_on_container_copy_constructiontrait on
x's allocator.
- The move constructor
(4, first signature)acquires
x's allocator.
The container also keeps an internal copy of comp (or x's comparison object), which is used to establish the order of the elements in the container and to check for elements with equivalent keys.
All elements are copied, moved or otherwise constructed by calling allocator_traits::construct with the appropriate arguments.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// constructing maps
#include <iostream>
#include <map>
bool fncomp (char lhs, char rhs) {return lhs<rhs;}
struct classcomp {
bool operator() (const char& lhs, const char& rhs) const
{return lhs<rhs;}
};
int main ()
{
std::map<char,int> first;
first['a']=10;
first['b']=30;
first['c']=50;
first['d']=70;
std::map<char,int> second (first.begin(),first.end());
std::map<char,int> third (second);
std::map<char,int,classcomp> fourth; // class as Compare
bool(*fn_pt)(char,char) = fncomp;
std::map<char,int,bool(*)(char,char)> fifth (fn_pt); // function pointer as Compare
return 0;
}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4