Код: Выделить всё
#include
#include
#include
#include
#include
template
struct CDep
{ template
CDep operator-(const CDep&) const
{ static_assert(
!std::is_same::value
&& !std::is_same::value,
"must not be a string!"
);
return {};
}
};
typedef boost::variant<
CDep,
CDep,
CDep
> values;
template
struct second
{ const T0&m_r;
second(const T0&_r)
:m_r(_r)
{
}
template
values operator()(const T&_r1)
{ return m_r - _r1;
}
template
values operator()(const T&_r1, const std::true_type&) const
{ return (*this)(_r1);
}
template
values operator()(const T&, const std::false_type&) const
{ throw std::logic_error("does not compile!");
}
template
values operator()(const T&_r0) const
{ return (*this)(
_r0,
std::integral_constant<
bool,
(boost::hof::is_invocable())
>()
);
}
};
struct first
{ const values&m_r;
first(const values&_r)
:m_r(_r)
{
}
template
values operator()(const T&_r0) const
{ return boost::apply_visitor(second(_r0), m_r);
}
};
values operator-(const values&_r0, const values&_r1)
{ return boost::apply_visitor(first(_r1), _r0);
}
int main(int, char**)
{ values(CDep()) - values(CDep());
values(CDep()) - values(CDep());
}
Но ошибка компилятора все равно происходит, как будто is_invocable всегда возвращает true_type.
После прочтения других вопросов относительно той же проблемы у меня есть два вопроса (которые должны быть очевидны и на которые я не нашел ответа):
- Какой смысл в is_invocable, если это не работает так, как ожидалось?
- Есть ли другой способ реализовать то, чего я хотел достичь?
Подробнее здесь: https://stackoverflow.com/questions/787 ... s-expected