I do not understand why the following simple example fails:
#include <boost/hana.hpp>
template <typename _T>
static constexpr void Foo(boost::hana::type<_T>) {
}
int main() {
Foo(boost::hana::type_c<int>);
return 0;
}
I get the following error message:
[build] error: no matching function for call to ‘Foo(boost::hana::type<int>&)’
[build] 74 | Foo(hana::type_c<int>);
[build] | ~~~^~~~~~~~~~~~~~~~~~~
[build] note: candidate: ‘template<class _T> constexpr void Morphy::Foo(boost::hana::type<T>)’
[build] 61 | static constexpr void Foo(hana::type<_T>) {
[build] | ^~~
[build] note: template argument deduction/substitution failed:
[build] note: couldn’t deduce template parameter ‘_T’
[build] 74 | Foo(hana::type_c<int>);
[build] | ~~~^~~~~~~~~~~~~~~~~~~
The only way to make the above work is by making explicit the template argument of Foo by writing Foo<int>(boost::hana::type_c<int>). Why is the compiler unable to automatically deduce the template argument?
Notice that the above code works if I use boost::hana::basic_type in place of boost::hana::type in the declaration of Foo. Is this alternative approach correct?