Topic: explicit template specialisation
Author: "Richard Smith" <richard@ex-parrot.com>
Date: Fri, 14 Sep 2001 18:20:51 GMT Raw View
On several occasions, I have wanted to write code such as the following,
class fish
{
template <class T>
class soup
{
// ...
};
template <>
struct std::less<soup> // Error: explicit specialisation at class scope
{
bool operator()(const soup &a, const soup &b) { /* ... */ }
};
std::set<soup> octopus;
};
Clearly, it is possible to get around this error. For example, I could use
a pimpl instead of octopus, or I could declare soup outside fish and perhaps
typedef it into fish, or I could use a differnt functor and specialise
std::less outside of the class. However all of these solutions have the
feeling (to me at least) of being hacks to overcome a deficiency in the
language. Can anyone give me a good reason why explicit specialisation (or
for that matter, instantiation) is not permitted at class scope? Or is it
something that was just not considered necessary?
--
Richard Smith
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]