using static_cast with boost::bind

2019-08-24 13:58发布

I want to transform a vector of type T to a vectorof type K. I tried this, but it doesn't work:

transform(vec.rbegin(),vec.rend(),vecNew.begin(),boost::bind(static_cast<K>(),_1));

I get the error: "expected primary-expression before ‘)’ token". What am I doing wrong?

标签: c++ boost bind
2条回答
叛逆
2楼-- · 2019-08-24 14:47

There's no need for the static cast unless there is no implicit conversion from T to K. If the conversion constructor is not explicit, or if you a T::operator K(), you can just do:

transform(vec.rbegin(),vec.rend(),vecNew.begin());

Note that this reverses the order of the elements as well.

查看更多
叼着烟拽天下
3楼-- · 2019-08-24 14:53

Use the boost cast functor ll_static_cast<K>()

查看更多
登录 后发表回答