Having a brain fart... Is it possible to make something like this work?
template struct Foo
{
template struct Bar;
};
template
Yes, you can. But you'll need to change the call structure, but just a little bit.
Specifically, use the strategy pattern to restructure the implementation of the member function as a class (which IS allowed to be specialized).
This is permitted as long as the strategy class is not nested (and hence not dependent on the unspecialized template type).
e.g. (this probably isn't syntactically correct, but the idea should be clear)
template
class OuterThingThatIsNotSpecialized
{
template
void memberWeWantToSpecialize(const U& someObj_)
{
SpecializedStrategy::doStuff(someObj_);
}
};
template
struct SpecializedStrategy;
template <>
SpecializedStrategy
{
void doStuff(const int&)
{
// int impl
}
};
template <>
SpecializedStrategy
{
void doStuff(const SomeOtherType&)
{
// SOT impl
}
};
This is incredibly useful because calls to OuterThingThatIsNotSpecialized for types where no implementation exists will simply fail to compile.
PS. You can even use this strategy to partially specialize template functions, something that is an otherwise C++ impossibility.