I understand that template arguments cannot always be deduced to reference types; foo(0) deduces to foo<int>, not foo<const int&>, while bar(baz<int&>() ) will deduce to bar<int&> if it takes a baz<T> argument. It seems sensible to assume that this code would work, but it doesn't:
Is there any way around this, bearing in mind that my real problem concerns template constructors, so there is no possibility of explicitly specifing the template parameter, and there are too many arguments to provide T& and const T& overloads for every argument?
Code:
template<typename T> class foo
{
};
template<typename T> void bar(foo<T>&, type)
{
}
int main()
{
foo<int&> x;
int y;
bar(x, y);
}
Comment