Below is a a test program with the purpose of calling member function for each
element of the collection. Argument of this member function is a
boost::function.
I put compilation error after the source code.
Any help will be greatly appreciated.
#include
#include
#include
typedef boost::function delegate;
class A : public boost::noncopyable
{
public:
commandhandler(delegate& f) {}
};
template <typename C> class Acoll
{
typedef boost::ptr_vector<C> ptr_container;
ptr_container m_data;
public:
typedef C CLIENT;
ptr_container& operator() (){return m_data;}
};
template <typename CLIENTS> class Test
{
CLIENTS& m_clients;
public:
delegate dosomething;
Test(CLIENTS& val) : m_clients(val) {}
void run()
{
std::for_each(m_clients().begin(), m_clients().end(),
boost::bind(&CLIENTS::CLIENT::commandhandler,
boost::ref(dosomething), _1 ));
}
};
int _tmain(int argc, _TCHAR* argv[])
{
Acoll<A> coll;
Test test(coll);
test.run();
return 0;
}
Error:
1>e:\libraries\boost\boost_1_37_0\boost\bind.hpp(292) : error C2664: 'R
boost::_mfi::mf1::operator ()(const U &,A1)
const' : cannot convert parameter 2 from 'A' to 'boost::function<Signature> '
1> with
1> [
1> R=void,
1> T=A,
1> A1=delegate &,
1> Signature=void (int,int,const char *),
1> U=delegate
1> ]
1> and
1> [
1> Signature=void (int,int,const char *)
1> ]
1> e:\libraries\boost\boost_1_37_0\boost\bind\bind_template.hpp(32) :
see reference to function template instantiation 'void
boost::_bi::list2::operator ()>(boost::_bi::type<T>,F &,A &,int)' being compiled
1> with
1> [
1> A1=boost::reference_wrapper<delegate>,
1> A2=boost::arg<1>,
1> F=boost::_mfi::mf1,
1> T=void,
1> A=boost::_bi::list1
1> ]
1> e:\program files\microsoft visual studio 9.0\vc\include\algorithm(29)
: see reference to function template instantiation 'void
boost::_bi::bind_t::operator ()<T>(A1 &)' being compiled
1> with
1> [
1> R=void,
1> F=boost::_mfi::mf1,
1>
L=boost::_bi::list2>,
1> T=A,
1> A1=A
1> ]
1> c:\test\t458\t458\t458.cpp(39) : see reference to function template
instantiation '_Fn1
std::for_each,boost::_bi::bind_t>(_
InIt,_InIt,_Fn1)' being compiled
1> with
1> [
1> _Fn1=boost::_bi::bind_t,boost::_bi::list2>>,
1> VoidIter=std::_Vector_iterator>,
1> T=A,
1> R=void,
1> F=boost::_mfi::mf1,
1>
L=boost::_bi::list2>,
1> _InIt=boost::void_ptr_iterator>,A>
1> ]
1> c:\test\t458\t458\t458.cpp(37) : while compiling class template
member function 'void Test<CLIENTS>::run(void)'
1> with
1> [
1> CLIENTS=Acoll<A>
1> ]
1> c:\test\t458\t458\t458.cpp(47) : see reference to class template
instantiation 'Test<CLIENTS>' being compiled
1> with
1> [
1> CLIENTS=Acoll<A>
1> ]