When I first learned how to verify a particular signature in a class, I was taught how to use std::void_tand write code like this:
template<typename T, typename =void>
class HAS:public false_type{};
template<typename T>
class HAS<T,void_t<decltype(declval<T>().print())>>:public true_type{};
And this piece of code checks to see if the class has a method named " print()". It works well.
But when I tried to remove std::void_t, it still worked.
The code is as follows:
template<typename T, typename = void>
class HAS:public false_type{};
template<typename T>
class HAS<T,decltype(declval<T>().print())>:public true_type{};
So, I'm confused if " std::void_t" you need to check if the class has a method with a specific signature? Or is it just a coincidence?
source
share