开发者

using static_cast with boost::bind

开发者 https://www.devze.com 2023-01-10 19:52 出处:网络
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 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 开发者_如何学Cget the error: "expected primary-expression before ‘)’ token". What am I doing wrong?


Use the boost cast functor ll_static_cast<K>()


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消