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

StackOverflow https://stackoverflow.com/questions/21245933

  •  30-09-2022
  •  | 
  •  

سؤال

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