【发布时间】:2017-03-04 22:38:39
【问题描述】:
Boost 变体有一个名为 make_variant_over 的函数,它接受一个 MPL 序列(例如 list<A, B, C>)并从这些类型中生成一个变体。
但是,如果仔细观察,生成的类型绝不是简单的variant<A, B, C>。
例如在这段代码中,
#include<boost/variant.hpp>
int main(){
using List = boost::mpl::list<double, int>;
using Variant = boost::make_variant_over<List>::type;
}
Variant 是boost::variant<boost::detail::variant::over_sequence<boost::mpl::list<double, int, mpl_::na, ...> >>。
貌似可以和boost::variant<double, int>互换使用,但不是同一个类型。最好的情况是在读取编译器错误时会产生混淆,最坏的情况是很难实现依赖于参数的确切类型的某些函数。
有没有办法强制简化生成的变体类型?
【问题讨论】:
-
这似乎归结为 MPL 的哲学,其中元程序的结果不会简化,但在功能上表现得像简化的结果。见stackoverflow.com/questions/28585599/…
标签: c++ boost boost-mpl boost-variant