Re: specialization on function functors
On Feb 17, 12:31 am, p7ere...@gmail.com wrote:
Hi,
I am building a template that takes an argument class F which is a
functor template argument. Normally this does equality testing with
the == sign so that a global scope template function Equals can do the
job. Moreover, the F argument uses a T argument that is also part of
the template class signature. My question is this, is there a way to
specialize when F argument is the global function Equals and not a
true functor?
template <class T, class F>
class MyClass {
F f;
T t1, t2;
bool Compare ()
{
return F(t1, t2);
}
};
This would be the unspecialized version.
Here's the global scope function:
template <class T>
bool Equals (T t1, T t2)
{
return t1 == t2;
}
typedef MyClass<int, Equals> cls;
I think you'll find that won't compile -- Equals is not a type.
How to specialize when F==Equals?
If Equals were a type (like so:
struct Equals
{
template <class T>
bool operator()(T t1, T t2)
{
return t1 == t2;
}
};
), you could specialise like this:
template <class T>
class MyClass<T, Equals> {
// specialised members here
};
Why do yu want to specialise it?
Yechezkel Mett
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]