How did we used to pass predicate with state?

C

cpisztest

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
 
V

Victor Bazarov

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
 
C

cpisztest

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

Victor Bazarov

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
 

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top