本文整理汇总了C++中ListType::erase方法的典型用法代码示例。如果您正苦于以下问题:C++ ListType::erase方法的具体用法?C++ ListType::erase怎么用?C++ ListType::erase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ListType
的用法示例。
在下文中一共展示了ListType::erase方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: removeEdge
bool DirectedGraph::removeEdge(int fromNodeId, int toNodeId) {
ListType::iterator neighborToRemove;
ListType* fromNeighbors = inNeighborsTable[toNodeId];
neighborToRemove = std::lower_bound(fromNeighbors->begin(), fromNeighbors->end(), fromNodeId);
if (neighborToRemove != fromNeighbors->end() && (*neighborToRemove == fromNodeId))
fromNeighbors->erase(neighborToRemove);
else
return false;
ListType* toNeighbors = outNeighborsTable[fromNodeId];
neighborToRemove = std::lower_bound(toNeighbors->begin(), toNeighbors->end(), toNodeId);
assert(*neighborToRemove == toNodeId);
toNeighbors->erase(neighborToRemove);
edgeCount--;
return true;
}
示例2: addToList
void addToList(const typename ListType::value_type &data, ListType &list) const {
if (length()<=0) {
// Ensure that no dummy data will get added. Shouldn't get here.
return;
}
if (startbyte()==0 && goesToEndOfFile()) {
// favor a single chunk covering the whole file.
list.clear();
list.insert(list.end(), data);
return;
}
typename ListType::iterator endIter=list.end(), iter=list.begin();
Range::base_type startdata = startbyte();
Range::base_type maxend = startdata;
bool includeseof = false;
while (iter != endIter) {
// maxend is not relevant for ranges strictly above us.
if ((*iter).startbyte() > startdata) {
break;
}
if ((*iter).endbyte() > maxend) {
maxend = (*iter).endbyte();
}
if ((*iter).goesToEndOfFile()) {
includeseof = true;
}
// we do not want to allow for more than one
// range starting at the same start byte--
// If this is the case, one is guaranteed to overlap.
if ((*iter).startbyte() >= startdata) {
break;
}
++iter;
}
if (includeseof || (maxend > endbyte() && !goesToEndOfFile())) {
return; // already included by another range.
}
iter = list.insert(iter, data);
++iter;
while (iter != endIter) {
typename ListType::iterator nextIter = iter;
++nextIter;
if (goesToEndOfFile() ||
(!(*iter).goesToEndOfFile() && (*iter).endbyte() <= endbyte())) {
list.erase(iter);
}
iter = nextIter;
}
}