diff --git a/src/libs/utils/algorithm.h b/src/libs/utils/algorithm.h index c0fb62b645f..7c0b73d2028 100644 --- a/src/libs/utils/algorithm.h +++ b/src/libs/utils/algorithm.h @@ -333,7 +333,7 @@ inserter(QSet &container) // different container types for input and output, e.g. transforming a QList into a QSet // function: -template class C, // result container type +template class C, // result container type template class SC, // input container type typename F, // function type typename... SCArgs, // Arguments to SC @@ -348,6 +348,22 @@ decltype(auto) transform(const SC &container, F function) return result; } +template class C, // result container type + template class SC, // input container type + typename F, // function type + typename... SCArgs, // Arguments to SC + typename Value = typename SC::value_type, + typename Result = std::decay_t>, + typename ResultContainer = C>> +Q_REQUIRED_RESULT +decltype(auto) transform(const SC &container, F function) +{ + ResultContainer result; + result.reserve(container.size()); + std::transform(std::begin(container), std::end(container), inserter(result), function); + return result; +} + // member function: template class C, // result container type template class SC, // input container type