I have the following function template
template
<
typename FilterLHS,
typename FilterRHS,
typename Of = typename FilterLHS::OfType,
std::enable_if_t<std::is_base_of_v<Filter<Of>, FilterLHS> && std::is_base_of_v<Filter<Of>, FilterRHS>, int> = 0
>
std::shared_ptr<OrFilter<Of>> operator ||(const std::shared_ptr<FilterLHS> &lhs, const std::shared_ptr<FilterRHS> &rhs)
{
return std::make_shared<OrFilter<Of>>(OrFilter<Of>{ lhs, rhs });
}
It works fine. My question is, why is the int
second argument, and default value of enable_if
required? As I understand, especially from this answer, I should just be able to do
template
<
typename FilterLHS,
typename FilterRHS,
typename Of = typename FilterLHS::OfType,
std::enable_if_t<std::is_base_of_v<Filter<Of>, FilterLHS> && std::is_base_of_v<Filter<Of>, FilterRHS>>
>
std::shared_ptr<OrFilter<Of>> operator ||(const std::shared_ptr<FilterLHS> &lhs, const std::shared_ptr<FilterRHS> &rhs)
{
return std::make_shared<OrFilter<Of>>(OrFilter<Of>{ lhs, rhs });
}
but when I do that, my template never seems to get enabled.
Aucun commentaire:
Enregistrer un commentaire