c++ - 负数或超大 STL 双端队列?

标签 c++ indexing deque

我有双端队列并想向后迭代它。我还需要索引(否则我会使用 reverse_iterator)所以我尝试了:

if ( _children.size( ) > 0 ) // debugging purpose
{
    unsigned si( _children.size( ) ); // debugging purpose
    int s( _children.size( ) - 1 ); // debugging purpose
    for ( unsigned c ( 0 ) ; c < _children.size( ) ; ++c )
        if ( this->_children[ ( _children.size( ) - 1 ) - c ]->Topmost( ) && 
             this->_children[ ( _children.size( ) - 1 ) - c ]->BorderRectangle( ).IsIn( X , Y ) )
               return std::pair< int, WindowPointer >( ( _children.size( ) - 1 ) - c, this->_children[ ( _children.size( ) - 1 ) - c ]->WindowAt( x, y ) );

但我得到了一个 sigsev。调试后我得到的索引是-65。我通过

检查了 _children.size( )
unsigned si = _children.size( );

它是 4294967232。

long s = _children.size( ) - 1;

是 -65。我如何获得这些值(value)?以及如何解决这个问题?

最佳答案

您应该使用reverse_iterator。如果你想跟踪一个索引,你可以像这样在你的 for 循环中添加一个变量:

int counter = 0;
for (xx::reverse_iterator it = yy.rbegin(); it != yy.rend(); ++it, ++counter) {
    // Do something
}

这比您正在做的更不容易出错。

关于c++ - 负数或超大 STL 双端队列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12987284/

相关文章:

java - 为什么 ArrayList RandomAccess 而 ArrayDeque 不是?

c++ - 为什么这里需要静态

c++ - 添加分钟和秒。以小时显示

c++ - 从 vector < vector <字符串>>中删除重复值,不区分大小写?由 小码哥发布于

Solr 4.0 在字符串字段中搜索

c++ - 空双端队列与未使用的指向双端队列的指针

c++ - 使用双端队列插入无符号字符数组

c++ - 重新定义 C++ 中的基本类型

python - 多维数组上的 numpy 高级索引

php - 当用户登录网站时——我应该选择用户名和密码,还是只选择用户名?