下标a std :: list

Eyz*_*uky 0 c++

我有这些typedef:

typedef pair<k2Base, list<v2Base>> shuffled_pair;
typedef list<shuffled_pair> shuffled_list;
Run Code Online (Sandbox Code Playgroud)

而这个功能:

shuffled_pair getItem(unsigned int index){
    return this->_items[index];
} 
Run Code Online (Sandbox Code Playgroud)

其中this->_items的类型是shuffled_list在typedef的声明.

我从编译器得到这个错误:

 Type 'const shuffled_list' (aka 'const list<pair<k2Base, list<v2Base> > >') does not provide a subscript operator
Run Code Online (Sandbox Code Playgroud)

但是类型基本上是列表类型,那么问题是什么?

Pot*_*ter 5

标准库仅在具有O(1)运行时时提供下标运算符.

因为std::list,库要求您获取迭代器并使用它std::advance来确认性能损失.