I\'m writing a template class, and I want to allow an additional method to exist only for a certain template type. Currently the method exists for all template types, but c
Yes, this is possible, but not with the class template parameter directly. boost::enable_if
can only be used with a template parameter on the method itself. So, with a little typedef usage:
template<typename T, typename BASE>
class MyClass : public BASE
{
public:
typedef Utility2<BASE> util;
typename T& operator() (const Utility1<BASE>& foo);
template<typename U>
typename boost::enable_if<boost::is_same<util, U>, T>::type const &
operator() (const U& foo) const;
};
This works, because Utility2 can only be created from a certain BASE type. So if the BASE type is something else, the const version of operator() won't exist.
So, it's a very minor thing. It doesn't gain me much. But it was neat to do.