const_cast

Discussion in 'C++' started by pallav, Apr 19, 2007.

  1. pallav

    pallav Guest

    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.
    pallav, Apr 19, 2007
    #1
    1. Advertising

  2. pallav

    Noah Roberts Guest

    pallav wrote:
    > 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.
    Noah Roberts, Apr 19, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kaspar Minosiants

    [help] const_cast

    Kaspar Minosiants, Jul 21, 2003, in forum: C++
    Replies:
    2
    Views:
    422
    John Harrison
    Jul 21, 2003
  2. drowned

    const_cast question

    drowned, Aug 4, 2003, in forum: C++
    Replies:
    3
    Views:
    484
    Josephine Schafer
    Aug 4, 2003
  3. R. Anbeeswaran

    const_cast<>

    R. Anbeeswaran, Nov 13, 2003, in forum: C++
    Replies:
    7
    Views:
    604
    Ekkehard Morgenstern
    Nov 14, 2003
  4. S.Senthilvel

    const_cast

    S.Senthilvel, Jan 6, 2004, in forum: C++
    Replies:
    4
    Views:
    2,034
    Andrey Tarasevich
    Jan 8, 2004
  5. Gajanan Bhat

    const_cast question

    Gajanan Bhat, May 4, 2004, in forum: C++
    Replies:
    9
    Views:
    550
    Bill Seurer
    May 5, 2004
Loading...

Share This Page