N
Neelesh
Hi all,
I had some confusion about deduction of non-type template parameters
for function templates :
template <class T, int i> void foo (T, int p = i) ;
void bar()
{
foo<int, 10>(40,40); // OK, T = int, i = 10
foo(40,40); // ERROR, T = int but i cannot be deduced.
}
However here I have another example :
template <class T, int i> void lookup ( Buffer<T,i> b);
void bar(Buffer<int, 128> b)
{
lookup(b,100); // No error, can infer T = int, i = 128
}
So it seems that when 'i' gets inferred as a "side effect" of type
matching, the compiler accepts that. However, it doesnot try to infer
it explicitly if required.
What does the standard say about this?
I had some confusion about deduction of non-type template parameters
for function templates :
template <class T, int i> void foo (T, int p = i) ;
void bar()
{
foo<int, 10>(40,40); // OK, T = int, i = 10
foo(40,40); // ERROR, T = int but i cannot be deduced.
}
However here I have another example :
template <class T, int i> void lookup ( Buffer<T,i> b);
void bar(Buffer<int, 128> b)
{
lookup(b,100); // No error, can infer T = int, i = 128
}
So it seems that when 'i' gets inferred as a "side effect" of type
matching, the compiler accepts that. However, it doesnot try to infer
it explicitly if required.
What does the standard say about this?