在以下代码中(为演示而简化):
namespace mpl = boost::mpl;
using if1 = mpl::if_<std::is_same<double, mpl::_1>, double, void>;
//using if2 = mpl::if_<std::is_same<double, mpl::_1>, typename std::common_type<double, mpl::_1>::type, void>;
using apply1 = boost::mpl::apply<if1, double>::type;
//using apply2 = boost::mpl::apply<if2, double>::type;
在std::is_same<double, mpl::_1>
中,占位符被正确替换为double
,就好像实例化是明确的std::is_same<double, double>
,这会导致正确/预期的行为。
但是,在 中std::common_type<double, mpl::_1>
,占位符没有被替换,就好像实例化是显式的一样std::common_type<double, mpl_::arg<1>>
,这会导致以下错误,因为显然没有“通用”类型:
error: incompatible operand types ('double' and 'mpl_::arg<1>')
问题:为什么mpl::_1
占位符被正确转换/替换为double
in std::is_same
,而不是in std::common_type
?有没有解决方法?