bool InstanceSelector::IsWorkloadMatch()

in src/vswhere.lib/InstanceSelector.cpp [249:299]


bool InstanceSelector::IsWorkloadMatch(_In_ ISetupInstance2* pInstance) const
{
    _ASSERT(pInstance);

    const auto requires = m_args.get_Requires();
    if (requires.empty())
    {
        // No workloads required matches every instance.
        return true;
    }

    // Keep track of which requirements we matched.
    typedef map<wstring, bool, ci_less> MapType;
    MapType found;
    for (const auto& require : requires)
    {
        found.emplace(make_pair(require, false));
    }

    LPSAFEARRAY psa = NULL;
    auto hr = pInstance->GetPackages(&psa);
    if (FAILED(hr))
    {
        return false;
    }

    SafeArray<ISetupPackageReference*> packages(psa);
    for (const auto package : packages.Elements())
    {
        auto id = GetId(package);

        auto it = found.find(id);
        if (it != found.end())
        {
            it->second = true;
        }
    }

    if (m_args.get_RequiresAny())
    {
        return any_of(found.begin(), found.end(), [](MapType::const_reference pair) -> bool
        {
            return pair.second;
        });
    }

    return all_of(found.begin(), found.end(), [](MapType::const_reference pair) -> bool
    {
        return pair.second;
    });
}