C ++ 98 v。C ++ 11 std :: set :: insert规范 [英] C++98 v. C++11 std::set::insert Specifications

查看:97
本文介绍了C ++ 98 v。C ++ 11 std :: set :: insert规范的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

迭代器的含义作为位置提示传递给 std :: set :: insert(iterator position,const value_type& val) std :: multiset :: insert(iterator position,const value_type& val)在C ++ 98和C ++ 11之间进行更改。在编译时有一个简单的方法来检测哪个正在使用中,不同的代码?

The meaning of the iterator passed as a position hint to std::set::insert(iterator position, const value_type& val) and std::multiset::insert(iterator position, const value_type& val) changes between C++98 and C++ 11. Is there an easy way at compile-time to detect which is in use and use different code?

对C ++ 11的一般检查似乎不是一个好主意( 1 check-for-c11-support> 2 ),但我没有看到合适的 Boost.Config 宏。

A general check on C++11 does not appear to be a good idea (1, 2), and I didn't see a suitable Boost.Config macro.

具体来说,文档 for C ++ 98说:

Specifically, the documentation for C++98 says:


如果 position 指向先于插入元素的
元素,函数将优化其插入时间。

The function optimizes its insertion time if position points to the element that will precede the inserted element.

而对于C ++ 11它说:

while for C++11 it says:


函数优化其插入时间如果位置指向将跟随插入的元素的
元素(或如果
将是最后一个,则到结束)。

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).

这很重要,因为提示会影响插入调用的复杂性。如果提示是正确的,复杂性只是一个摊销的常数。

This matters because the hint effects the complexity of the insertion call. If the hint is correct, the complexity is only an amortized constant. But if it's not, it's logarithmic in size.

正如JerryCoffin在下面的描述,这是一个

As so nicely described below by JerryCoffin, the C++98 specification is, essentially, a typo.

推荐答案

//groups.google.com/group/comp.std.c++/browse_frm/thread/6ff4ab58318f0870/52c2484d42d2a083\">完整报告 LWG问题#233 n1780

This was the subject of a defect report, LWG issue #233, and n1780.

如上所述,显然编辑C ++ 98标准时出现了一个简单的错误。

As noted there, it was apparently a simple error in editing the C++98 standard.

Stepanov的原始实现是根据当前的规范工作的,就我所知的大多数(所有?)实现,因为做了相同的(虽然有一个看起来两个

Stepanov's original implementation worked according to the current specification, and as far as I know most (all?) implementations since have done the same (though there is one that looks both before and after the hinted location, so you'll get optimal behavior if you specify either one).

在提示位置之前的之前,您可以获得最佳的行为。插入将位于集合的开头,这在以前的规范下是不可能的。

This also makes it possible to hint that an insertion will be at the beginning of the set, which wasn't possible under the previous specification.

这篇关于C ++ 98 v。C ++ 11 std :: set :: insert规范的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆