In the following code (simplified for demonstration):
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;
In std::is_same<double, mpl::_1>
, the placeholder is correctly substituted with double
, as if the instantiation were explicitly std::is_same<double, double>
which results in the correct/expected behavior.
However, in std::common_type<double, mpl::_1>
, the placeholder is not substituted, as if the instantiation were explicitly std::common_type<double, mpl_::arg<1>>
, which causes the following error since there is obviously no "common" type:
error: incompatible operand types ('double' and 'mpl_::arg<1>')
The Question: Why is the mpl::_1
placeholder correctly transformed/substituted with double
in std::is_same
, but not in std::common_type
? And is there a workaround?
::value
afterstd::is_same<...>
and maybe::type
aftermpl_if_<...>
? – Birthmarkmpl::if_
parameter 1 takes anintegral_constant
(whichstd::is_same
subclasses). Theif1
works correctly, andapply1
isdouble
as expected. The problem isif2
withstd::common_type
as explained in the question. – Parthia