I came across an implementation of std::is_convertible and was confused on why they would test for returnability. Below is an excerpt of the total implementation. Why cast a nullptr to pointer to a function returning type T? Is there an example of a type that is not returnable?
template<class T>
auto test_returnable(int) -> decltype(
void(static_cast<T(*)()>(nullptr)), std::true_type{}
);
template<class>
auto test_returnable(...) -> std::false_type;
This tests to see if the type T is valid to return from a function via SFINAE and returns true_type or false_type depending on the result.
For example, functions have types yet cannot be returned from functions (though pointers and references to them can be)
https://en.cppreference.com/w/cpp/language/functions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With