boost::variant
通过 boost::variant<>::types
公开其变体类型列表, 可以方便地与 boost::mpl::for_each
一起使用. std::variant
缺少这样一个成员。
我看到 std::variant_alternative
提供。这可以用来生成 boost::mpl::for_each
的类型列表吗?可以摄取吗?还是它启用了不同的迭代策略?
最佳答案
我不是 100% 熟悉 Boost.MPL,但这应该可以满足您的需求:
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;
关于c++ - std::variant 是否提供类似于 boost::variant<>::types 的功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58025118/