[英]Does std::variant provide functionality similar to boost::variant<>::types?
boost::variant
exposes its list of variant types via boost::variant<>::types
, which can be conveniently used with boost::mpl::for_each
. boost::variant
通过boost::variant<>::types
公开其变体类型列表,可以方便地与boost::mpl::for_each
一起使用。 std::variant
is missing such a member. std::variant
缺少这样的成员。
I see std::variant_alternative
is provided.我看到提供了std::variant_alternative
。 Can this be used to produce a type list that boost::mpl::for_each
can ingest?这可以用来生成boost::mpl::for_each
可以摄取的类型列表吗? Or does it enable a different iteration strategy?或者它是否支持不同的迭代策略?
I'm not 100% familiar with Boost.MPL, but this should do what you're looking for:我对 Boost.MPL 不是 100% 熟悉,但这应该可以满足您的需求:
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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.