Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualBrother Bob

Posted 31 May 2013 - 12:56 PM

Thanks a lot guys!

Guess it's just me then not being used to templates xD

Even though it looks logical (to me) that the compiler will infer the evaluated type of the variables from the type of objects contained in the list, I guess it's not.

I mean the compiler usually will be able to "guess" what s the type if I write:

template <typename T>
bool greaterThan(const T& in1, const T& in2)
{
return in1>in2;
}

and:

int a=5, b=6;
cout << greaterThan(a,b) << endl; 

No error in this one...

There's a major difference between that example and deducing the argument of the predicate in your first post. The template parameter of greaterThan is deduced from the parameters being passed to it, while you expected that the template parameter of sortDescending to be deduced from the type of the parameter of another function to which the predicate is passed.


#2Brother Bob

Posted 31 May 2013 - 12:55 PM

Thanks a lot guys!

Guess it's just me then not being used to templates xD

Even though it looks logical (to me) that the compiler will infer the evaluated type of the variables from the type of objects contained in the list, I guess it's not.

I mean the compiler usually will be able to "guess" what s the type if I write:

template <typename T>
bool greaterThan(const T& in1, const T& in2)
{
return in1>in2;
}

and:

int a=5, b=6;
cout << greaterThan(a,b) << endl; 

No error in this one...

There's a major difference between that example and deducting the argument of the predicate in your first post. The template parameter of greaterThan is deducted from the parameters being passed to it, while you expected that the template parameter of sortDescending to be deducted from the type of the parameter of another function to which the predicate is passed.


#1Brother Bob

Posted 31 May 2013 - 12:53 PM

Thanks a lot guys!

Guess it's just me then not being used to templates xD

Even though it looks logical (to me) that the compiler will infer the evaluated type of the variables from the type of objects contained in the list, I guess it's not.

I mean the compiler usually will be able to "guess" what s the type if I write:

template <typename T>
bool greaterThan(const T& in1, const T& in2)
{
return in1>in2;
}

and:

int a=5, b=6;
cout << greaterThan(a,b) << endl; 

No error in this one...

There's a major difference between that example and deducting the argument of the predicate. The template parameter of greaterThan is deducted from the parameters being passed to it, while you expected that the template parameter of sortDescending to be deducted from the type of the parameter of another function to which the predicate is passed.


PARTNERS