tags:

views:

55

answers:

1

Any one Explain this with an example

  "Involving conversions on a function argumentsinvolved in template
   parameter deduction."

EXamples like this:

 template<class T> struct B { /* ... */ };
 template<class T> struct D : public B<T> { /* ... */ };
 template<class T> void f(B<T>&);
 void g(B<int>& bi, D<int>& di)
   {
    f(bi);
    f(di);
   }

Please give me some more examples

EDIT: It is a point / statement from ISO C++ Standard 14.8.3/5th :Overload resolution

+2  A: 

It is about what the example shows. In sum, these are those conversions

  • The function parameter can be a Base<T>, while the function argument is a Derived<T>. Compare with ifstream << "hello" - left side of operator<< is deduced in that way.
  • The function parameter can be a const U&, while the function argument is a U (same for volatile).
  • The function parameter can be a const U* or const E C::* while the function argument is a U* or E C::* respectively (these are the qualification conversions) - same for volatile.

Other conversions cannot be done for a function parameter / argument that participate in deduction. The whole range of conversions can be applied if a function parameter does not participate in deduction, but this needs a non-deduced context or a context where there is no argument to be deduced at all, and implementation don't actually agree on it (see here).

In other words:

template<typename T> struct id { typedef T type; };
template<typename T> void f(T, typename id<T>::type);

int main() {
  // deduction acts on void(int*, int*) - deduction does not need
  // to deduce anything and follows [temp.arg.explicit]p4
  f<int*>(0, 0); 

  // deduction acts on void(T, id<T>::type) - second is a non-deduced context,
  // which *will* allow the conversion of int -> int*, since it will not compare
  // the argument with parameter during deduction (since it is non-deduced).
  f((int*)0, 0);
}

The second example is vital for some partial ordering contexts to work.

Johannes Schaub - litb
Thank you very much .. :)
BE Student
@johannes : U described about conversions right..Can u able to tell that in a program ... (i mean iam asking for a proof) to check whether it is correct or not
USER
@USER :In the link ..there is some source ..see that also
BE Student