First it groups the lifetimes together using std::partition with the lifetimes that refer to the same token or token of a subexpression. Then it finds the lifetime in that group that refers to the "highest" parent using std::min_element and adds that to the vector.
| 716 | // First it groups the lifetimes together using std::partition with the lifetimes that refer to the same token or token of a subexpression. |
| 717 | // Then it finds the lifetime in that group that refers to the "highest" parent using std::min_element and adds that to the vector. |
| 718 | static std::vector<ValueFlow::Value> pruneLifetimes(std::vector<ValueFlow::Value> lifetimes) |
| 719 | { |
| 720 | std::vector<ValueFlow::Value> result; |
| 721 | auto start = lifetimes.begin(); |
| 722 | while (start != lifetimes.end()) |
| 723 | { |
| 724 | const Token* tok1 = start->tokvalue; |
| 725 | auto it = std::partition(start, lifetimes.end(), [&](const ValueFlow::Value& v) { |
| 726 | const Token* tok2 = v.tokvalue; |
| 727 | return start->lifetimeKind == v.lifetimeKind && (astHasToken(tok1, tok2) || astHasToken(tok2, tok1)); |
| 728 | }); |
| 729 | auto root = std::min_element(start, it, [](const ValueFlow::Value& x, const ValueFlow::Value& y) { |
| 730 | return x.tokvalue != y.tokvalue && astHasToken(x.tokvalue, y.tokvalue); |
| 731 | }); |
| 732 | result.push_back(*root); |
| 733 | start = it; |
| 734 | } |
| 735 | return result; |
| 736 | } |
| 737 | |
| 738 | static ValueFlow::Value getLifetimeIteratorValue(const Token* tok, MathLib::bigint path = 0) |
| 739 | { |
no test coverage detected