ARTICLE AD BOX
I have a class model that is good case for CRTP templates. Most information is static, the classes are singletons, therefore I can access them using their type names as opposed to object references.
In pseudo code:
// Bridge base template class BridgeBaseT < class tDerivedBridgeType, class tRequiringDomain, class tProvidingDomain >; // Bridge types SingleBridgeT < class tDerivedBridgeType, class tRequiringDomain, class tProvidingDomain > : public BridgeBaseT<tDerivedBridgeType, tRequiringDomain, tProvidingDomain>; ThreadedFixedBridgeT < class tDerivedBridgeType, class tRequiringDomain, class tProvidingDomain, const FixedQueueSize tQueueSize = FixedQueueSize::_15_SLOTS > : public BridgeBaseT<tDerivedBridgeType, tRequiringDomain, tProvidingDomain>; ThreadedDynamicBridgeT < class tDerivedBridgeType, class tRequiringDomain, class tProvidingDomain, const unsigned int tInitialQueueSize = 16, const unsigned int tQueueIncrement = 8 > : public BridgeBaseT<tDerivedBridgeType, tRequiringDomain, tProvidingDomain>; // Base class for signals and operations SigOpT < class tDerivedSigOp, class tRequiringDomain, class tProvidingDomain >Several template parameters (tRequiringDomain, tProvidingDomain, ...) are used in several places.
Since this is part of a framework, I want to reduce the need for typing, therefore I want to wrap all the pieces in a wrapper template and tie everything together for the end user. That would be something along the lines of:
Using MyBridgeWrapper = BridgeWrapperT < MyReqDomain, MyProvDomain, <BRIDGE_TEMPLATE>, MySigOpTypeList... > {...};where <BRIDGE_TEMPLATE> would be replaced with one of the ***BridgeT<> templates above, including its specific, additional parameters (e.g. const FixedQueueSize tQueueSize). As an example of reuse, note that MyReqDomain and MyProvDomain should be able to be forwarded to the <BRIDGE_TEMPLATE>. MySigOpTypeList is a parameter pack of SigOpT<>:s.
The problem is that I can't find a way where a generic <BRIDGE_TEMPLATE> can be used to support all the different bridge templates.
<BRIDGE_TEMPLATE> could be a template template, but the diversity of the extra bridge parameters for threaded bridges messes things up. One idea I had was using a base class that ends with a parameter pack, like:
BridgeBaseT < class tDerivedBridgeType, class tRequiringDomain, class tProvidingDomain, class... tAdditionalBridgeParams >;It doesn't work because the extra parameters are constant int values, which can't be included in parameter packs.
I've tried numerous other approaches, and it seems I end up in all the corner cases where templates don't work.
BTW, I'm using C++14, but I'm not 100% bound to that.
