为什么在开始之前没有降低Deque Iterator的运行时断言:在VC++?
void foo (std::deque<Class>& dq)
{
auto it = dq.begin();
--it; // <--- asserts in VC++
...
}
上面的代码是一个过于简单的版本,但我的代码中也发生了类似的情况。它在Ubuntu/Linux中正常工作,但通过Visual Studio断言并逐步中止该程序。
表达式:在开始之前无法降低Deque Iterator
有关您的程序如何导致断言失败的信息,请参见VC ++ ...
即使我们没有寻求或取消迭代器的价值,为什么它会对其进行对待作为运行时错误?
void foo (std::deque<Class>& dq)
{
auto it = dq.begin();
--it; // <--- asserts in VC++
...
}
Above code is an oversimplified version, but similar is happening in my code. It works fine in Ubuntu/Linux, but asserts and aborts the program with Visual studio.
Expression: cannot decrement deque iterator before begin
For information on how your program can cause assertion failure, see VC++ ...
Even though we are not seeking or dereferencing the value of the iterator, why does it treats it as a runtime error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从指定要求的描述 noReferrer“> nekacyBidirectionaliteratorator :
请注意,仅当
-Container.Begin()
被解释时,行为不会不确定。仅仅试图减少开始迭代器的行为是不确定的行为。来自标准在双向迭代器上,以下前提条件适用于
-R
当r
是双向迭代器时:对于
dq.begin()
,没有这样的s
,因此减少的是未定义的行为。From the description of the named requirement LegacyBidirectionalIterator:
Note that behavior isn't undefined only if
--container.begin()
is dereferenced. Simply attempting to decrement the begin iterator at all is undefined behavior.From the standard on bidirectional iterators, the following precondition applies to
--r
whenr
is a bidirectional iterator:There is no such
s
fordq.begin()
and so decrementing it is undefined behavior.