How did we used to pass predicate with state?

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

  1. 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)
    :
    m_myInt(theInt)
    {
    }

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

    if( item->GetData(false) == m_myInt)
    {
    item->DoStuff();
    }
    }
    };

    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
     
    , May 22, 2014
    #1
    1. Advertisements

  2. On 5/21/2014 9:14 PM, wrote:
    > 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

    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.

    >
    > 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?


    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.

    >
    > Here is my code snippet
    >
    > struct MyFunctor
    > {
    > int m_myInt;
    >
    > //
    > MyFunctor(int theInt)
    > :
    > m_myInt(theInt)
    > {
    > }
    >
    > //
    > void DoIt(MyTemplateClass::CollectionType::iterator it)
    > {
    > MyTemplateClass::EnrolleeType item = it->second;
    >
    > if( item->GetData(false) == m_myInt)
    > {
    > item->DoStuff();
    > }
    > }
    > };
    >
    > 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
    >


    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".

    V
    --
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, May 22, 2014
    #2
    1. Advertisements

  3. Guest

    On Thursday, May 22, 2014 7:54:36 AM UTC-5, Victor Bazarov wrote:
    > On 5/21/2014 9:14 PM, wrote:
    > > 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

    >
    > >

    >
    > 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".
    >



    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.
     
    , May 23, 2014
    #3
  4. On 5/23/2014 12:45 PM, wrote:
    > On Thursday, May 22, 2014 7:54:36 AM UTC-5, Victor Bazarov wrote:
    >> On 5/21/2014 9:14 PM, wrote:
    >>> 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

    >>
    >>>

    >>
    >> 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".
    >>

    >
    >
    > 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)'


    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.

    > 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.


    '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!

    V
    --
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, May 23, 2014
    #4
    1. Advertisements

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.
Similar Threads
  1. bmmodi
    Replies:
    1
    Views:
    3,166
    Saravana
    Dec 2, 2004
  2. Jacques

    Predicate by attribute?

    Jacques, Jun 24, 2004, in forum: XML
    Replies:
    2
    Views:
    473
    Jacques
    Jun 24, 2004
  3. hall
    Replies:
    4
    Views:
    1,008
  4. Xah Lee
    Replies:
    0
    Views:
    559
    Xah Lee
    Apr 23, 2007
  5. Casey Hawthorne
    Replies:
    1
    Views:
    983
    Arne Vajhøj
    Mar 18, 2009
  6. Daniel Waite
    Replies:
    2
    Views:
    451
    Daniel Waite
    May 2, 2008
  7. Xah Lee
    Replies:
    0
    Views:
    399
    Xah Lee
    Apr 23, 2007
  8. Ted Byers
    Replies:
    23
    Views:
    854
    Peter J. Holzer
    Nov 15, 2008
Loading...