Boost logo

Boost :

Subject: Re: [boost] [Interest] Value Dispatch
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2012-08-15 23:36:37


AMDG

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.

> 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.

> 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.

In Christ,
Steven Watanabe


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk