Boost logo

Boost :

Subject: Re: [boost] [hana]Either generalization & missing variant
From: Louis Dionne (ldionne.2_at_[hidden])
Date: 2015-06-08 16:55:31


Michael Caisse <mcaisse-lists <at> ciere.com> writes:

>
> [...]
>
> Converting a type list to a variant is a common thing I need to do.
> Creating yet-one-more-variant type is probably not in Hana's best
> interest. Variant is a priority for C++17 and there are already a
> variety of other implementations.
>
> If you provide an adapter for boost::variant (possibly as a util so it
> isn't a dependency of the core library) then that may satisfy the
> concerns. Optionally, getting an MPL style typelist from Hana would also
> solve these types of interfacing issues.

If all you need is to make a variant type (boost::variant<...>) from a
sequence of types (make_tuple(type<T>...) in Hana), the following will do:

    auto types = make_tuple(...); // a tuple of Type objects in Hana
    using Variant = decltype(unpack(types, template_<boost::variant>))::type;
    // Variant is now your boost::variant<...>

Basically, we're considering boost::variant as a function on types
(via template_), and then we're applying that function to the contents
of the tuple (via unpack). Finally, we take everything back to the type
level by using decltype(...)::type.

Regards,
Louis


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