Subject: Re: [boost] [Interest] Value Dispatch
Date: 2012-08-16 00:40:26
Steven Watanabe <watanabesj_at_[hidden]> writes:
> On 08/15/2012 06:34 PM, greened_at_[hidden] wrote:
>> I was aiming for a value-centered analogue to virtual functions as
>> opposed to an enhanced union type.
> Well, what you have is essentially a union type,
> even if that's not what you intended.
It entirely depends on how the classes arrange member data, no? In my
"real" project, the classes all have std::vectors with different kinds
of stuff in them, depending on the kind tag. The elements all use the
same value dispatch mechanism to implement polymorphism. In that sense
I guess it's sort of like a union, but certainly not in the traditional
>> boost::variant feels opaque to me (get<>, etc.) while value dispatch
>> seems more natural and transparent for the use cases I had in mind.
> You should avoid using get<> on a variant. Whenever possible,
> apply_visitor is better.
That's no less opaque.
>> Note also that boost::variant appears to require or at least
>> encourage inheritance (e.g. static_visitor) while value dispatch does
>> not. I don't think that's a strong positive or negative as long as
>> value semantics are maintained.
> Boost.Variant doesn't care about inheritance. static_visitor is like
> std::iterator or std::binary_function. It's just a helper that
> provides a result_type typedef. Anyway, static_visitor is for
> apply_visitor and doesn't have anything to do with the types stored in
> the variant.
That's why I said it's not a strong positive or negative. :)
But I guess I'm sensing value dispatch isn't too interesting outside my
own project. That's ok, it's made my life easier anyway and I found the
lookup table implementation neat enough to share. :)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk