幸运的是,我们可以通过另一个mpl算法——equal——来解决这个问题,equal用于测试两个序列是否具有相同的一集元素:
template <class otherdimensions>
quantity(quantity<t,otherdimensions> const& rhs)
: m_value(rhs.value())
{
boost_static_assert((
mpl::equal<dimensions,otherdimensions>::type::value
));
}
现在,如果两个单位不匹配,那么这个assertion就会导致一个编译错误,及时阻止你的错误行为。