using static_cast with boost::bind

心已入冬 提交于 2019-12-13 07:24:05

问题


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?


回答1:


Use the boost cast functor ll_static_cast<K>()




回答2:


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.



来源:https://stackoverflow.com/questions/3430152/using-static-cast-with-boostbind

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!