whatIsThisFor
Check out this C++ code fragment at the beginning of the MessageBase class template definition:
After staring at it for a few minutes, I was able to distill the essence of the idiom(???) used in the code as:
I can’t figure out why B was designed as a class template and not just a plain ole’ class that simply inherits from A (see below). It reminds me a little of the CRTP idiom but it’s not the same. Would you happen to know what problems it is intended to solve? Is it some template meta-programming technique?
Rate this:
Related
Categories: C++, uml
Tags: c++, class diagram, CRTP, linkedin, programming, Template metaprogramming
Leave a Reply Cancel reply
This site uses Akismet to reduce spam. Learn how your comment data is processed.
My BTC Address

13VFoawXgQuFAvZokYjkSMohd4uEGn7abp
Top Posts
agile
bitcoin
Bjarne Stroustrup
bureaucracy
business
c++
C++11
CEO
class diagram
company culture
complexity
concurrency
consciousness
design
ego
Erlang
failure
Fred Brooks
Grady Booch
Herb Sutter
hierarchy
leadership
linkedin
management
manager
organizational behavior
postaday2011
product development
programming
project management
requirements analysis
Russell Ackoff
schedule
Scott Berkun
Scrum
software architecture
software design
software development
spirituality
sysml
systems
systems engineering
systems thinking
thinking
thought
Tony Hsieh
uml
William Livingston
writing
zappos.com
Categories
- bitcoin (101)
- business (200)
- C++ (106)
- C++11 (49)
- C++14 (5)
- C++17 (3)
- Cancer (87)
- Cannabis (4)
- management (593)
- miscellaneous (306)
- Quantum Physics (11)
- spirituality (122)
- sysml (22)
- technical (520)
- uml (53)
Blog Stats
- 328,216 hits
In and of itself it is not a metaprogramming technique. It can, however, form the basis for one (see mpl::inherit_linearly).
There’s actually a lot of uses for this kind of thing though admittedly they’re all rather rare to run into. Here’s one example where I apply it: http://stackoverflow.com/questions/4688138/initializing-the-base-class-to-a-derived-base-class/4688402#4688402
No idea if they used my first or second idea but there you go…an application of the technique.
Thanks for the valiant try CE, but I’m still confused 🙂
Thinking out loud: B “is an” A, and B also uses another A for some purpose.
Well, perhaps you’d understand better if you grabbed yourself a copy of “Modern C++ Design” by Alexandrescu. He describes “Policy Based Design” and the implementations look very much like the code that’s confusing you. I thought there was an excerpt of that part online but I couldn’t find it anywhere now. The book should be on any C++ developer’s shelf anyway.
Ah yes, Mr. “Loki”. I do have his book on my list and am planning to read it after I finish “C++ Templates: The Complete Guide”. Thanks for your help.