W
woessner
Hi all. This isn't a really pressing question, but it has been kicking
around my head for a while. Is there any major difference between the
following functors:
template<typename T, T m_kTarget>
struct SEqual1
{
bool operator()(const T& krElem) const { return(krElem == m_kTarget);
}
};
template<typename T>
struct SEqual2
{
Equal2(const T& krTarget): m_kTarget(krTarget) {}
bool operator()(const T& krElem) const { return(krElem == m_kTarget);
}
private:
const T& m_kTarget;
};
Obviously, SEqual1 can't be used with non-primitive types. But beyond
that, is there any reason to prefer one over the other? I'm thinking
SEqual1 will run faster but may cause code bloat due to many
instantiations.
This is a pretty trivial example, but I've come across situations like
this a couple of times. I think I almost always go with SEqual2, but
I'm really starting to wonder if I should consider the alternative.
Thanks in advance,
Bill
around my head for a while. Is there any major difference between the
following functors:
template<typename T, T m_kTarget>
struct SEqual1
{
bool operator()(const T& krElem) const { return(krElem == m_kTarget);
}
};
template<typename T>
struct SEqual2
{
Equal2(const T& krTarget): m_kTarget(krTarget) {}
bool operator()(const T& krElem) const { return(krElem == m_kTarget);
}
private:
const T& m_kTarget;
};
Obviously, SEqual1 can't be used with non-primitive types. But beyond
that, is there any reason to prefer one over the other? I'm thinking
SEqual1 will run faster but may cause code bloat due to many
instantiations.
This is a pretty trivial example, but I've come across situations like
this a couple of times. I think I almost always go with SEqual2, but
I'm really starting to wonder if I should consider the alternative.
Thanks in advance,
Bill