문제

Most Eigen classes have an eval() method that force their evaluation. Some classes don't, for example matrix decompositions. Is there a way to distinguish between these classes at compile-time?

도움이 되었습니까?

해결책

You can define your own trait which uses SFINAE to determine this:

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)) { };
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top