编译时解决方案以检测特征对象没有eval()成员

Compile-time solution to detect that an Eigen object does not have an eval() member?

本文关键字:eval 成员 对象 解决方案 检测 特征 编译      更新时间:2023-10-16

大多数特征类都具有迫使其评估的eval()方法。有些课程不可能,例如矩阵分解。有没有办法在编译时区分这些类?

您可以定义自己的特征,该特质使用Sfinae来确定这一点:

namespace detail
{
    template<typename T>
    auto has_eval_impl(void*)
        -> decltype(std::declval<T>().eval(), std::true_type());
    template<typename T>
    auto has_eval_impl(...) -> std::false_type;
}
template<typename T>
struct has_eval : decltype(detail::has_eval_impl<T>(nullptr)) { };