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?
Categories: C++, uml
Tags: c++, class diagram, CRTP, linkedin, programming, Template metaprogramming
Leave a Reply Cancel reply
Top Posts
Top Clicks
BD00 Twits
- Ask Slashdot: How To Start Reading Other's Code? @slashdot rpx.me/0Xro 14 hours ago
- RT @AgileBorat: Scrum is very socialist! It is give power to people, so they can able of sustainable self-organize work for great sharehold… 1 day ago
- The Importance Of Locality wp.me/psQTe-6nG 1 day ago
- RT @RealTimeInnov: "Collecting lots of 3D data in real-time" @NASA robot uses #Connext #DDS for reliable communications. http://t.co/3RyE6R… 2 days ago
- One Step Forward, N-1 Steps Back wp.me/psQTe-6q0 3 days ago
Tags
agile
Bjarne Stroustrup
bureaucracy
business
c++
CEO
class diagram
company culture
complexity
concurrency
consciousness
design
ego
Erlang
failure
Grady Booch
Herb Sutter
hierarchy
leadership
linkedin
management
manager
organizational behavior
postaday2011
product development
programming
project management
requirements analysis
Russell Ackoff
schedule
Scott Berkun
software architecture
software design
software development
spirituality
sysml
systems
systems engineering
systems thinking
thinking
thought
Tony Hsieh
uml
William Livingston
zappos.com
Categories
- business (186)
- C++ (67)
- C++11 (21)
- management (507)
- miscellaneous (211)
- Quantum Physics (10)
- spirituality (112)
- sysml (22)
- technical (388)
- uml (51)
Blog Stats
- 93,135 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.