How did we used to pass predicate with state?

Discussion in 'C++' started by cpisztest, May 22, 2014.

  1. cpisztest

    cpisztest Guest

    I am using boost::bind and boost::function in a project, but to my my distress, they are asking that it compile in msvc7.1

    Evidently, msvc7.1 can't handle boost::bind. I've tried everything suggested in the docs and everything I could google up. It works in msvc8.0 and up.

    Is there an old school alternative?

    Here is my code snippet

    struct MyFunctor
    int m_myInt;

    MyFunctor(int theInt)

    void DoIt(MyTemplateClass::CollectionType::iterator it)
    MyTemplateClass::EnrolleeType item = it->second;

    if( item->GetData(false) == m_myInt)

    MyFunctor functor(10);
    MyTemplateClass::ForEach(boost::bind(&MyFunctor::DoIt, &functor, _1));

    Here is the error it is giving me (which is alien speak to me):
    error C2780: 'boost::_bi::bind_t<_bi::dm_result<MT::* ,A1>::type,boost::_mfi::dm<M,T>,_bi::list_av_1<A1>::type> boost::bind(M T::* ,A1)' : expects 2 arguments - 3 provided
    cpisztest, May 22, 2014
    1. Advertisements

  2. distress, they are asking that it compile in msvc7.1

    Have you gone back to the version of Boost that used to compile with VC
    7.1? There has to be something like that. I seem to recall Boost as
    far back as VC 6.0.
    suggested in the docs and everything I could google up. It works in
    msvc8.0 and up.
    There probably is. IIRC, you would need to use the combination of
    'bind1st' and 'mem_fun'. You can probably search for 'bind1st' in the
    archives and find a few examples. It's been deprecated, but in 7.1 it
    has to exist. You can always use the preprocessor to exclude the code
    dedicated to one compiler and not the rest.
    What's alien here? It says that you need to provide 2 arguments, and
    you provided three (see the two commas in your parentheses following the
    word 'bind' in your statement?)

    Try to omit the ", _1".

    Victor Bazarov, May 22, 2014
    1. Advertisements

  3. cpisztest

    cpisztest Guest

    If you do that you get error C2893: Failed to specialize function template 'boost::_bi::bind_t<_bi::dm_result<MT::* ,A1>::type,boost::_mfi::dm<M,T>,_bi::list_av_1<A1>::type> boost::bind(M T::* ,A1)'

    also tried boost::bind<void> and boost::bind::(boost::type<void>(),
    Nothing seems to work. I'll see if I can use bind1st and mem_fn instead.
    cpisztest, May 23, 2014
  4. The rules (and compiler capabilities) of deducing the template arguments
    from a function call have changed. VC++ 7.1 wasn't really far advanced
    in that area either, so you're not likely to get anywhere with it when
    using the modern version of Boost.
    'bind1st' used to be a bit tricky, and it's been more than 10 years
    since 7.1 came out (IIRC), so don't expect too much with it. As they
    say, YMMV.

    You *could* write a wrapper for your predicate, of course. Give it a
    state (the value at construction) and make it call the other predicate's
    member function with the argument that it needs...

    Good luck!

    Victor Bazarov, May 23, 2014
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.