I am specializing the 'less' (predicate) for a data type.
The code looks like this:
template<>
struct std::less<DateTimeKey>
{
bool operator()(const DateTimeKey& k1, const DateTimeKey& k2) const
{
// Some code ...
}
};
When compiling (g++ 4.4.1 on Ubuntu 9.10), I get the error:
Specialization of 'template struct std::less' in different namespace
I did some research and found that there was a 'workaround' which involved wrapping the specialization in a std namespace - i.e. changing the code to:
namespace std {
template<>
struct less<DateTimeKey>
{
bool operator()(const DateTimeKey& k1, const DateTimeKey& k2) const
{
// Some code ...
}
};
}
which indeed, shuts the compiler up. However, that solution was from a post 5 years old (By the 'great' Victor Bazarof no less [pun unintended]). Is this fix still the way to go, or is there a better way of resolving this, or is the "old way" still valid?
DateTimeKey::operator<
? – Gesticulate