0

boost::variant exposes its list of variant types via boost::variant<>::types, which can be conveniently used with boost::mpl::for_each. std::variant is missing such a member.

I see std::variant_alternative is provided. Can this be used to produce a type list that boost::mpl::for_each can ingest? Or does it enable a different iteration strategy?

Quentin
  • 62,093
  • 7
  • 131
  • 191
Braden
  • 1,448
  • 10
  • 11

1 Answers1

4

I'm not 100% familiar with Boost.MPL, but this should do what you're looking for:

template <class Variant>
struct mpl_types_impl;

template <class... Ts>
struct mpl_types_impl<std::variant<Ts...>> {
    using type = boost::mpl::vector<Ts...>;
};

template <class Variant>
using mpl_types = typename mpl_types_impl<Variant>::type;

See it live on Wandbox

Quentin
  • 62,093
  • 7
  • 131
  • 191