Question

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?

Was it helpful?

Solution

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)) { };
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top