I would do this:
template<typename L, typename R> auto isLess(L&& lhs, R&& rhs) -> decltype(std::declval<L>().a < std::declval<R>().a) { return std::forward<L>(lhs).a < std::forward<R>(rhs).a; }
This will work regardless of the relationship between your types and will not compile into multiple functions (see the last paragraph). This will allow you to use any types that have a member a that is less than comparable.
Function templates and allowing it to infer types will work, but will then be compiled for multiple functions.
Not bad. It is even better than this, it will compile without any function, since any sane compiler (even msvc) will fully integrate this function.
Guillaume racicot
source share