0

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?

yannick
  • 397
  • 3
  • 19

1 Answers1

2

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)) { };
David G
  • 94,763
  • 41
  • 167
  • 253
  • why do you need to pass arguments to `has_eval_impl`? – yannick Jan 21 '14 at 07:31
  • 1
    @yannick Overload resolution only works between functions with parameters. If I leave both parameters empty the compiler will tell me that I can't overload based on the return type. – David G Jan 21 '14 at 12:57