std :: multimap插入顺序保证 [英] std::multimap insertion order guarantees
问题描述
您好,
std :: multimap是否对插入订单有任何保证?
例如:
int main()
{
std :: multimap< int,int>地图;
Map.insert(std :: make_pair(0,1));
Map.insert(std :: make_pair(0,2) );
Map.insert(std :: make_pair(0,3));
Map.insert(std :: make_pair(0,4));
std :: copy(Map.begin(),Map.end(),std :: ostream_iterator< int>(std :: cout,
" ));
}
它会按顺序输出1 2 3 4吗?并且equal_range(0)总是
也给1 2 3 4?
或者它是平台相关的,例如允许输出2 4 3 1?
感谢您的帮助。
祝您好运,
Tanguy
TanguyFautré写道:你好,
std :: multimap是否对插入顺序做出任何保证?
据我所知。
-
WW aka Attila
"TanguyFautré" < TF ***** @ pandora.be>在消息中写道
news:ol ********************* @ phobos.telenet-ops.be ...您好,
std :: multimap是否对插入顺序有任何保证?
std :: map和std :: multimap保证取消引用
的迭代器值从''begin()''到'end( )'' - 1'收益'
''key''顺序中的元素。对于''multimap'',无法保证检索此序列中
重复值的顺序。
例如:
int main()
{st / :: std :: multimap< int,int>地图;
Map.insert(std :: make_pair(0,1));
Map.insert(std :: make_pair(0,2));
Map。 insert(std :: make_pair(0,3));
Map.insert(std :: make_pair(0,4));
std :: copy(Map.begin() ,Map.end(),
std :: ostream_iterator< int>(std :: cout,""));
}
是否总是输出1 2 3 4按顺序?
如果您确定要复制的电话,是的。 (multimap< int,int> :: iterator
deref产生类型''std :: pair< int,int>'',而不是''int'')
并且equal_range(0)总是
给1 2 3 4吗?
是。
或者它是否依赖于平台,例如可以输出2 4 3 1?
>
No.
-Mike
" Mike Wahler" < MK ****** @ mkwahler.net>在消息中写道
新闻:NI ***************** @ newsread3.news.pas.earthl ink.net ...TanguyFautré < TF ***** @ pandora.be>在消息中写道
新闻:ol ********************* @ phobos.telenet-ops.be ...您好,
std :: multimap是否对插入顺序做出任何保证?
std :: map和std :: multimap保证取消引用迭代器的值来自' 'begin()''到'end()'' - 1'''''''''''''''''''''''''''''''''''''''对于''multimap'',无法保证检索此序列中重复值的顺序。
例如:
int main()
{st / :: std :: multimap< int,int>地图;
Map.insert(std :: make_pair(0,1));
Map.insert(std :: make_pair(0,2));
Map。 insert(std :: make_pair(0,3));
Map.insert(std :: make_pair(0,4));
std :: copy(Map.begin() ,Map.end(),
std :: ostream_iterator< int>(std :: cout,""));
}
它是否总是以该顺序输出1 2 3 4?
如果您修复该复制的调用,是的。 (multimap< int,int> :: iterator
deref产生类型''std :: pair< int,int>'',而不是''int'')
并且equal_range(0)总是
给1 2 3 4吗?
是的。
或者它是否依赖于平台允许输出2 4 3 1
例子?
-Mike
你让我感到困惑。
你说对于'''''''''''''''''''''''''''''' >
序列被检索不保证。
然后你说它将始终输出0 1 0 2 0 3 0 4.(如果我修复
copy ;-)打印键和映射值)。
因此,具有相同键的元素是否会保持它们的顺序
是否插入?
祝你好运,
Tanguy
Hello,
does std::multimap make any guarantee about the insertion order?
for example:
int main()
{
std::multimap<int, int> Map;
Map.insert(std::make_pair(0, 1));
Map.insert(std::make_pair(0, 2));
Map.insert(std::make_pair(0, 3));
Map.insert(std::make_pair(0, 4));
std::copy(Map.begin(), Map.end(), std::ostream_iterator<int>(std::cout,
" "));
}
Will it always output 1 2 3 4 in that order? and will equal_range(0) always
give 1 2 3 4 too?
Or is it platform dependent and is allowed to output 2 4 3 1 for example?
Thanks for your help.
Best regards,
Tanguy
Tanguy Fautré wrote:Hello,
does std::multimap make any guarantee about the insertion order?
Not as far as I know.
--
WW aka Attila
"Tanguy Fautré" <tf*****@pandora.be> wrote in message
news:ol*********************@phobos.telenet-ops.be...Hello,
does std::multimap make any guarantee about the insertion order?
std::map and std::multimap guarantee that the dereference
of the iterator values from ''begin()'' to ''end()'' - 1 yield
the elements in ''key'' order. For a ''multimap'', the order in which
duplicate values in this sequence are retrieved is not guaranteed.
for example:
int main()
{
std::multimap<int, int> Map;
Map.insert(std::make_pair(0, 1));
Map.insert(std::make_pair(0, 2));
Map.insert(std::make_pair(0, 3));
Map.insert(std::make_pair(0, 4));
std::copy(Map.begin(), Map.end(), std::ostream_iterator<int>(std::cout, " "));
}
Will it always output 1 2 3 4 in that order?
If you fix that call to copy, yes. (multimap<int,int>::iterator
deref yields type ''std::pair<int, int>'', not ''int'')
and will equal_range(0) always
give 1 2 3 4 too?
Yes.
Or is it platform dependent and is allowed to output 2 4 3 1 for example?
No.
-Mike
"Mike Wahler" <mk******@mkwahler.net> wrote in message
news:NI*****************@newsread3.news.pas.earthl ink.net..."Tanguy Fautré" <tf*****@pandora.be> wrote in message
news:ol*********************@phobos.telenet-ops.be...Hello,
does std::multimap make any guarantee about the insertion order?
std::map and std::multimap guarantee that the dereference
of the iterator values from ''begin()'' to ''end()'' - 1 yield
the elements in ''key'' order. For a ''multimap'', the order in which
duplicate values in this sequence are retrieved is not guaranteed.
for example:
int main()
{
std::multimap<int, int> Map;
Map.insert(std::make_pair(0, 1));
Map.insert(std::make_pair(0, 2));
Map.insert(std::make_pair(0, 3));
Map.insert(std::make_pair(0, 4));
std::copy(Map.begin(), Map.end(),
std::ostream_iterator<int>(std::cout," "));
}
Will it always output 1 2 3 4 in that order?
If you fix that call to copy, yes. (multimap<int,int>::iterator
deref yields type ''std::pair<int, int>'', not ''int'')and will equal_range(0) always
give 1 2 3 4 too?
Yes.Or is it platform dependent and is allowed to output 2 4 3 1 for
example?
No.
-Mike
You got me puzzled there.
You say "For a ''multimap'', the order in which duplicate values in this
sequence are retrieved is not guaranteed."
but then you say that it will always output 0 1 0 2 0 3 0 4. (if I fix the
copy ;-) to print both the key and the mapped value).
So, will the the elements with the same key keep the order they were
inserted in or not ?
Best regards,
Tanguy
这篇关于std :: multimap插入顺序保证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!