只需使用phx::static_cast_
:Live On Coliru
int main()
{
auto implicit_conversion = phx::static_cast_<const char*>(arg1);
std::vector<MyStringClass> v(10);
std::for_each(v.begin(), v.end(), implicit_conversion);
}
或者包裹在函子中:Live On Coliru
namespace detail
{
template <typename T>
struct my_cast
{
template <typename U> struct result { typedef T type; };
template <typename U>
T operator()(U v) const {
return static_cast<T>(v);
}
};
}
namespace phx = boost::phoenix;
using namespace phx::arg_names;
int main()
{
phx::function<detail::my_cast<const char*>> to_csz;
std::vector<MyStringClass> v(10);
std::for_each(v.begin(), v.end(), to_csz(arg1));
}