2

I have an std::vector<IRenderable*> (_pBkBuffer in the code below). It contains a number of static objects (at the start of the vector) that don't change, followed by a variable number of dynamic objects.

// erase-remove, but leave the static renderables intact
_pBkBuffer->erase( 
    std::remove(
        _pBkBuffer->begin() + _nStatics, _pBkBuffer->end(), ???
    ), 
    _pBkBuffer->end() 
);

What can I put at the ??? in order to erase-remove the non-static renderables?

I know that the ??? should match all objects in the specified subset.

Should I be using erase-remove at all, or should I use another approach?

4

1 回答 1

4

'我应该使用擦除删除吗

显然你已经知道物体在哪里,所以不。你来做这件事:

_pBkBuffer->erase( _pBkBuffer->begin() + _nStatics, _pBkBuffer->end() );

或者,甚至更好:

_pkBuffer->resize( _nStatics );

如果您将它们随机分散在向量中,则将使用擦除删除习语。缺少的???是与要删除的元素进行比较的值。由于您要存储指针,因此您很可能需要提供自定义谓词(函数指针、函子或 lambda)并remove_if改用。

于 2013-04-30T14:01:57.260 回答