Okay guys, time to get your hands dirty
Who here can help me get around this little prob?
I warn ya, this is some heavy shizz
I've got a base templated structure like this:
template<typename Type>
struct Structure{
/* contents... */
};
Now I want to offer a specialisation for that class for pointer types...
BUT the original class is damn big; So I want this new one to inherit all of its contents...
template<typename Type>
struct Structure<Type*>:Structure<Type*>{
/* extra contents... */
};
Well that's no good coz it links back to itself (since Type* is already specialised). What I'm after is a way of passing Type* as the the type for the original global templation without getting a feedback loop
My first plan was to add a boolean flag to the original global template with a default value of true & use that to differentiate:
template<typename Type, bool original=true>
struct Structure{};
template<typename Type>
struct Structure<Type,true>{
/* contents... */
};
template<typename Type>
struct Structure<Type*,false>:Structure<Type*,true>{
/* extra contents... */
};
BUT quite a few of the methods in the global prototype <Type,true> return instances of itself. That means the return type for those functions MUST contain all template parameters. But I can't cast to <Type,true> because then those methods will cast when inherited by the pointer alternative & the results won't have the extra contents
So really the global template version MUST be able to fully contain the specialisation, but if this is the case then how do I differentiate that I want to inherit from the base without the inherit line being picked up by the specilisation itself.. I doubt there is special syntax for this
I know c++ templating is severly limited & I'm already right up against the limits in several other situations.
But does anyone know a way around this?
Maybe some other way of copying the declaration body from the first to the specilisation using macros? & then somehow linking in their later definitions.. oh I don't know
This is a CHALLENGE, comon you great minds out there!
(& yeah it's g++ 8P)
_______________________________ ________ _____ ___ __ _`By offloading cognitive load to the computer, programmers are able to design more elegant systems' - Unununium OS regarding Python