std::multimap::multimap
STD::Multimap::Multimap
| (1) | |
---|---|---|
explicit multimap( const Compare& comp = Compare(), const Allocator& alloc = Allocator() | (until C++14) | |
multimap() : multimap( Compare() ) {} explicit multimap( const Compare& comp, const Allocator& alloc = Allocator() | (since C++14) | |
explicit multimap( const Allocator& alloc | (1) | (since C++11) |
| (2) | |
template< class InputIterator > multimap( InputIterator first, InputIterator last, const Compare& comp = Compare(), const Allocator& alloc = Allocator() | | |
template< class InputIterator > multimap( InputIterator first, InputIterator last, const Allocator& alloc | (since C++14) | |
multimap( const multimap& other | (3) | |
multimap( const multimap& other, const Allocator& alloc | (3) | (since C++11) |
multimap( multimap&& other | (4) | (since C++11) |
multimap( multimap&& other, const Allocator& alloc | (4) | (since C++11) |
| (5) | |
multimap( std::initializer_list<value_type> init, const Compare& comp = Compare(), const Allocator& alloc = Allocator() | (since C++11) | |
multimap( std::initializer_list<value_type> init, const Allocator& | (since C++14) |
从各种数据源构造新容器,并可选择使用用户提供的分配器。alloc
或比较函数对象comp
...
1%29默认构造函数。构造空容器。
2%29构造包含范围内容的容器。[first, last)
...
3%29复制构造函数。的内容的副本构造容器。other.如果alloc不提供,则通过调用std::allocator_traits<allocator_type>::select_on_container_copy_construction(other.get_allocator())...
4%29移动构造函数。的内容构造容器。other
使用移动语义。如果alloc
如果不提供分配器,则通过移动构造从属于other
...
5%29使用初始化程序列表的内容构造容器。init
...
参数
alloc | - | allocator to use for all memory allocations of this container |
---|---|---|
comp | - | comparison function object to use for all comparisons of keys |
first, last | - | the range to copy the elements from |
other | - | another container to be used as source to initialize the elements of the container with |
init | - | initializer list to initialize the elements of the container with |
类型要求
-输入器必须符合输入器的要求。
-比较必须符合比较的要求。
-分配器必须符合分配器的要求。
复杂性
1%29常数
2%29N
日志%28N
%29N =
std::distance
(first, last)
一般情况下,线性在N
如果范围已经按value_comp()
...
3%29线性other
4%29常数。如果alloc
被赋予和alloc != other.get_allocator()
,然后是线性的。
5%29N
日志%28N
%29N = init.size())
一般情况下,线性在N
如果init
已按value_comp()
...
注记
在容器移动构造%28重载%284%29%29之后,引用、指针和迭代器%28---other
保持有效,但引用当前在*this
.现行标准通过第23.2.1节中的总括声明作出这一保证。集装箱。所需经费/12,目前正在考虑通过以下方式提供更直接的担保:lwg 2321...
例
二次
#include <iostream>
#include <map>
struct Point { double x, y; };
struct PointCmp {
bool operator()(const Point& lhs, const Point& rhs) const {
return lhs.x < rhs.x; // NB. ignores y on purpose
}
};
int main() {
std::multimap<int, int> m = {{1,1},{2,2},{3,3},{4,4},{5,5},{4,4},{3,3},{2,2},{1,1}};
for(auto& p: m) std::cout << p.first << ' ' << p.second << '\n';
// custom comparison
std::multimap<Point, double, PointCmp> mag{
{ {5, 12}, 13 },
{ {3, 4}, 5 },
{ {8, 15}, 17 },
{ {3, -3}, -1 },
};
for(auto p : mag)
std::cout << "The magnitude of (" << p.first.x
<< ", " << p.first.y << ") is "
<< p.second << '\n';
}
二次
产出:
二次
1 1
1 1
2 2
2 2
3 3
3 3
4 4
4 4
5 5
The magnitude of (3, 4) is 5
The magnitude of (3, -3) is -1
The magnitude of (5, 12) is 13
The magnitude of (8, 15) is 17
二次
另见
operator= | assigns values to the container (public member function) |
---|
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
http://en.cppreference.com/w/cpp/container/Multimap/Multimap