C++: need help with boost::bind
-
template <typename T>
bool filterOut( T * const who, bool (T::*func)(Object::Ptr, ObjectInfo::Type) const )
{
std::vector<Object::Ptr>::iterator it = std::partition( m_objects.begin(), m_objects.end(), boost::bind( (who->*func), _2, m_objectType ) );m_objects.erase( it, m_objects.end() );
...
}
m_objects is a private std::vector<Object::Ptr>
m_objectType is a private ObjectInfo::Type
Object::Ptr is a Boost shared pointer for Object class :
typedef boost::shared_ptr<Object> Ptr;
called as :
objectSet->filterOut<Filter>( this, &Filter::isObjectOfType )
definition of isObjectOfType :
class Filter {
public:
bool isObjectOfType(
Object::Ptr object, ObjectInfo::Type type
) const;
}
-
As fascinating as all that may be, you don't appear to have a question.
-
@asuffield said:
As fascinating as all that may be, you don't appear to have a question.
This does not compile. error is somwhere in boost::bind.
After couple of hours at the monitor I just don't see it.
-
@Nelle said:
@asuffield said:
As fascinating as all that may be, you don't appear to have a question.
This does not compile. error is somwhere in boost::bind.
After couple of hours at the monitor I just don't see it.
throws error somewhere in boost::bind.
Compiling...
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
... \boost\boost\bind.hpp(1628) : see declaration of 'boost::bind'
Filter.cpp(124) : see reference to function template instantiation
'bool ObjectSet::filterOut<Filter>(T const ,bool (__thiscall
Filter:: )(Object::Ptr,ObjectInfo::Type) const)' being compiled
with
[
T=Filter
]
After couple of hours at the monitor I just don't see it.
-
If you're using MSVC 7/8 (as it looks like) Google shows it may be a compiler issue, for example. Try using another compiler, even if its just a small test snippet to see what works where, or spend a little more time on Google than I did and see if anyone has come up with a solution.
-
Just a wild guess: _1 instead of _2 ?
-
@ammoQ said:
Just a wild guess: _1 instead of _2 ?
good one :
so the current status is :
if I use boost::lambda::bind(func, who, _1, m_objectType) ( some Object::Ptr() ) in the testing function, it works, which means the bind is properly resolved to a method that has one Object::Ptr argument and returns a bool..
all nice an well, but when I try to use the same bind here :
std::vector<Object::Ptr>::iterator it = std::partition( m_objects.begin(), m_objects.end(), boost::lambda::bind(func, who, _1, m_objectType) );
the compiler throws the following error :
error C2664: 'bool (Object::Ptr,ObjectInfo::Type) const' : cannot convert parameter 1 from 'const rt2' to 'Object::Ptr'
-
@Nelle said:
@ammoQ said:
Just a wild guess: _1 instead of _2 ?
good one :
so the current status is :
if I use boost::lambda::bind(func, who, _1, m_objectType) ( some Object::Ptr() ) in the testing function, it works, which means the bind is properly resolved to a method that has one Object::Ptr argument and returns a bool..
all nice an well, but when I try to use the same bind here :
std::vector<Object::Ptr>::iterator it = std::partition( m_objects.begin(), m_objects.end(), boost::lambda::bind(func, who, _1, m_objectType) );
the compiler throws the following error :
error C2664: 'bool (Object::Ptr,ObjectInfo::Type) const' : cannot convert parameter 1 from 'const rt2' to 'Object::Ptr'
Finally solved it .....
if someone runs into similar problem, just keep in mind that
boost::bind != boost::lambda::bind
and when using both in one class be extra carefull, since _1 for lambda bind is defined in boost::lambda::_1,
however _1 for boost bind is defined in ::_1 anonymous namespace . gg
p.s. ammoQ thnx for _2 -> _1
-