Hi everyone,
Thanks very much for your replies. Sorry I didn't get back to you earlier, I got caught up with a couple of things. Also my apologies for posting this in the Beginners section, I still consider myself very much a beginner and it's my first babysteps with static polymorphism. Anyway, moved it to General.
Thank you Cubbi for your explanations regarding the static_assert / is_base_of, I hadn't considered that it wouldn't work with incomplete types. Also thanks for the tip on private inheritance, seems that's an easy way to do the trick.
I'll copy the original questions in just for easier reference.
I wrote: |
---|
Q1: Would this be a good use-case for friend classes, if I want to only provide the interface of base? |
Interesting that
friend base;
works. I would have expected for the compiler to complain that "base" expects template parameters?
I wrote: |
---|
Q2: In a program where the type of base to instantiate depends on the platform (for instance 32bit/64 bit, just to give an example)... |
Thanks Albatross for that link, I wasn't aware of those. Cubbi was probably right in that 32_BIT and 64_BIT don't mean much, it was a bad example on my part. What I plan on using this for is having different data storage backends, as to separate the data backend from the other code, ie:
1 2 3 4 5 6 7 8
|
#ifdef RDBMS
base_mapper<rdbms_mapper> m;
#endif
#ifdef XML
base_mapper<xml_mapper> m;
#endif
m.create(stuff);
|
I wrote: |
---|
Q3: When would one use Policy-based Design over the CRTP to achieve static polymorphism? |
Thanks JLBorges for your comparison to OO, that made it click. I'm taking away from all your explanations that CRTP is for providing a single interface, implemented differently in derived classes and Policy Based Design is more of a "mix and match" thing where you put together the interface you need from the available parts.
I wrote: |
---|
Q4: Since the base class functions basically just wrap a call to their implementation functions, I'm guessing this would be a good time to use perfect forwarding? |
Cubbi wrote: |
---|
4) It doesn't appear to gain anything in this case. |
Could you please elaborate a little on that? Note that I just corrected a typo, I forgot to pass on the argument to the _impl function, might that be the reason? I'm just asking to check whether I have a flwed understanding of perfect forwarding.
Thanks very much once again everyone for your kind replies, very much appreciated.
All the best,
NwN