LINUX.ORG.RU

История изменений

Исправление quasimoto, (текущая версия) :

.begin(), entry.second.end() и inserter забыл.

private:

    using SubMap = std::map<std::string, std::vector<std::string>>;
    template <typename T> using Map = std::map<T, SubMap>;

    template <typename T>
    static Map<T> compressDependencies(Map<T> const& dependencies) {
        Map<T> result;
        for (auto & entry : dependencies) {
            //    ^ less allocations
            auto & subMap = entry.second;
            auto & coMap = result[entry.first];
            std::copy_if(
                subMap.begin(), subMap.end(), std::inserter(coMap, coMap.end()),
                [](SubMap::value_type const& subEntry) { return subEntry.second.size(); }
            );
        }
        return result;
    }

Исправление quasimoto, :

.begin(), entry.second.end() и inserter забыл.

private:

    using SubMap = std::map<std::string, std::vector<std::string>>;
    template <typename T> using Map = std::map<T, SubMap>;

    template <typename T>
    static Map<T> compressDependencies(Map<T> const& dependencies) {
        Map<T> result;
        for (auto & entry : dependencies) {
            //    ^ less allocations
            auto & subMap = entry.second;
            auto & coMap = result[entry.first];
            std::copy_if(
                subMap.begin(), subMap.end(), std::inserter(coMap, coMap.end()),
                [](SubMap::value_type subEntry) { return subEntry.second.size(); }
            );
        }
        return result;
    }

Исправление quasimoto, :

.begin(), entry.second.end() и inserter забыл.

private:

    using Map1 = std::map<std::string, std::vector<std::string>>;
    template <typename T> using Map2 = std::map<T, Map1>;

    template <typename T>
    static Map2<T> compressDependencies(Map2<T> const& dependencies) {
        Map2<T> result;
        for (auto & entry : dependencies) {
            //    ^ less allocations
            auto & subMap = entry.second;
            auto & coMap = result[entry.first];
            std::copy_if(
                subMap.begin(), subMap.end(), std::inserter(coMap, coMap.end()),
                [](Map1::value_type subEntry) {
                    return subEntry.second.size();
                }
            );
        }
        return result;
    }

Исходная версия quasimoto, :

.begin(), entry.second.end() и inserter забыл.

private:

    using Map1 = std::map<std::string, std::vector<std::string>>;
    template <typename T> using Map2 = std::map<T, Map1>;

    template <typename T>
    static Map2<T> compressDependencies(Map2<T> const& dependencies) {
        Map2<T> result;
        for (auto & entry : dependencies) {
            //    ^ less allocations
            auto & subMap = entry.second;
            auto & coMap = result[entry.first];
            std::copy_if(
                subMap.begin(), subMap.end(), std::inserter(coMap, coMap.end()),
                [](Map1::value_type const subEntry) {
                    return subEntry.second.size();
                }
            );
        }
        return result;
    }