const_cast

P

pallav

vector<TLExpression*> forms;
map<const TLExpression*, bool> stateTable;

for (ExprMap::iterator itr = stateTable.begin(); itr !=
stateTable.end(); ++itr)
forms.push_back(const_cast<TLExpression *>(itr->first));

i'm trying to use the stl::transform to convert the above code. i have

std::transform(stateTable.begin(0, stateTable.end(),
std::back_inserter(forms),
boost::bind(&ExprMap::value_type::first, _1));

however, i get compiler errors with this saying i'm trying to convert
const TLExpresion* to TLExpression*. i'm not sure where/how to cast
in std::transform. where/what/how should i cast?

thanks for your time/help.
 
N

Noah Roberts

pallav said:
vector<TLExpression*> forms;
map<const TLExpression*, bool> stateTable;

for (ExprMap::iterator itr = stateTable.begin(); itr !=
stateTable.end(); ++itr)
forms.push_back(const_cast<TLExpression *>(itr->first));

i'm trying to use the stl::transform to convert the above code. i have

std::transform(stateTable.begin(0, stateTable.end(),
std::back_inserter(forms),
boost::bind(&ExprMap::value_type::first, _1));

however, i get compiler errors with this saying i'm trying to convert
const TLExpresion* to TLExpression*. i'm not sure where/how to cast
in std::transform. where/what/how should i cast?

thanks for your time/help.

Actually, to really help I shouldn't tell you. What you're doing
shouldn't be done.

You will have to write a function that does the cast. There may be some
already in boost.

std::transform(st.begin(), st.end(), std::back_inserter(forms),
bind(cast_f, bind(&ExprMap::value_type::first, _1)));

something along those lines anyway.

have fun.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top