
On 08/15/12 20:34, greened@obbligato.org wrote:
[Note: I don't know why my e-mail address got mangled. It should be "greened@..."]
Larry Evans <cppljevans@suddenlink.net> writes:
Could you not use boost::variant
Thanks for your feedback!
boost::variant can do some similar things but I think it is really aimed at a different problem. As I understand it, boost::variant's primary use case is to function as a type safe generalized union. Thus it has to deal with things like alignment, etc. that the presented technique (which I call "value dispatch" for lack of a better name) does not.
But the only reason why value dispatch does not have to deal with alignment is because the values are all empty. The only member values in vehicle is the tag: kind the_kind; As soon as you have to add other member variables (I assume a real Boat or a real Plane would have other member variables), you'll have to deal with alignment, if you want to save space.
A quick glance at boost::variant source code shows that it is quite complex. IMHO, value dispatch is much simpler.
Agreed. [snip]