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?
Asked
Active
Viewed 278 times
0

yannick
- 397
- 3
- 19
-
[Possible duplicate](http://stackoverflow.com/questions/1966362/sfinae-to-check-for-inherited-member-functions). – rodrigo Jan 20 '14 at 23:10
-
I was aware of that answer, but I was looking for an eigen-specific solution. – yannick Jan 20 '14 at 23:20
-
What do you mean by an Eigen-specific solution? – David G Jan 21 '14 at 00:59
-
classes that have `eval()` probably inherit from some class I'm not aware of. But your solution is cool I must admit. – yannick Jan 21 '14 at 07:02
1 Answers
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
-
-
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