MCPcopy Create free account
hub / github.com/KDE/kdevelop / unite

Function unite

kdevplatform/util/algorithm.h:26–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24 */
25template <typename ForwardIt>
26auto unite(ForwardIt first, ForwardIt last)
27{
28 if (first == last) {
29 return std::remove_cv_t<std::remove_reference_t<decltype(*first)>>{};
30 }
31 const auto maxElement = std::max_element(first, last, [](const auto& a, const auto& b) {
32 return a.size() < b.size();
33 });
34 Q_ASSERT(maxElement != last);
35
36 // Start with the largest-size set. None of this set's elements is inserted
37 // into another set, so picking the largest one achieves optimum performance.
38 auto result = *maxElement;
39 for ( ; first != maxElement; ++first) {
40 result.unite(*first);
41 }
42 // skip the already included *maxElement
43 for (++first; first != last; ++first) {
44 result.unite(*first);
45 }
46 return result;
47}
48
49/**
50 * This is an overloaded convenience function.

Callers 4

testUnite2StringMethod · 0.85
testUnite5IntMethod · 0.85
filesMethod · 0.85
fileSetMethod · 0.85

Calls 3

sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by 2

testUnite2StringMethod · 0.68
testUnite5IntMethod · 0.68