int main() { std::vector<int> v; v.erase(remove(v.begin(), v.end(), 10)); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this call will remove at most one item even when multiple items should be removed [misc-inaccurate-erase] // CHECK-FIXES: {{^ }}v.erase(remove(v.begin(), v.end(), 10), v.end());{{$}} v.erase(remove(v.begin(), v.end(), 20), v.end()); // Fix is not trivial. auto it = v.end(); v.erase(remove(v.begin(), it, 10)); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this call will remove at most one // CHECK-FIXES: {{^ }}v.erase(remove(v.begin(), it, 10));{{$}} g<std::vector<int>>(); g<custom_container>(); ERASE(v, 15); // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: this call will remove at most one // CHECK-FIXES: {{^ }}ERASE(v, 15);{{$}} std::vector<std::unique_ptr<int>> vupi; auto iter = vupi.begin(); vupi.erase(iter++); // CHECK-FIXES: {{^ }}vupi.erase(iter++);{{$}} }
static double pathFindWork(int_vec_t *destpath, int pos, int dest, path_bitmap_t seen, const waypoint_vec_t* wmap, const region_map_t* regs) { BEGIN_DEPTH; int_vec_t wpoints; INIT(wpoints); assert(pos >=0); assert(dest >=0); // already there. if (pos == dest) { END_DEPTH; return 0.0; } if (full_set(&seen)) { END_DEPTH; return INFINITY; } if (GET(*wmap,pos).distances[dest] != INFINITY) { PUSH_BACK(*destpath, dest); END_DEPTH; return GET(*wmap,pos).distances[dest]; } sortedWaypoints(&wpoints, pos, dest, wmap, regs); // remove those we've already seen. int j = 0; while (j < SIZE(wpoints)) { if (is_set(&seen, GET(wpoints,j))) { ERASE(wpoints, j); } else { ++j; } } if (SIZE(wpoints) == 0) { END_DEPTH; return INFINITY; } const int offset = SIZE(*destpath); int lowest_idx = -1; double lowest_value = INFINITY; int_vec_t tmp; INIT(tmp); COPY(tmp, *destpath); int i; for (i=0; i<SIZE(wpoints); ++i) { if (!is_set(&seen, GET(wpoints,i))) { double val; PUSH_BACK(tmp, GET(wpoints,i)); path_bitmap_t local_seen = seen; set(&local_seen, GET(wpoints,i)); val = pathFindWork(&tmp, GET(wpoints,i), dest, local_seen, wmap, regs) + GET(*wmap,pos).distances[GET(wpoints,i)]; if (lowest_value == INFINITY || (val != INFINITY && val < lowest_value)) { lowest_value = val; lowest_idx = GET(wpoints,i); COPY(*destpath, tmp); END_DEPTH; // with this return, it's an A* search. without, it's // a DFS. return val; } RESIZE(tmp, offset); } } // at the end, destpath has the minimum path we've seen so far, // and now we're returning our distance to the path we've appended on. END_DEPTH; return lowest_value; // + distance(wmap[pos].pos, wmap[lowest_idx].pos, regs); }