std::void_t : std::void_t is used to check whether a type is ill-formed with SFINAE.
An Example is:
template <typename, typename void>
struct isMemberAvailable : false_type
{};
template <typename T>
struct isMemberAvailable<T, std::void_t<decltype(std::declval<T&>().a)>> : true_type
{};
Another approach is using boost::is_detected_v<> instead.
An example is:
template <typename T>
using isMemberAvailable_t = decltype(std::declval<T&>().a);
template <typename T>
int get(T& t) {
if constexpr (boost::is_detected_v<isMemberAvailable_t, T>) {
return t.a;
}
else {
return 0;
}
}
std::enable_if: it will take two arguements like <bool, default type> so we can combine it with the SFINEA created by std::void_t above.