#include <functional>
#include <boost/bind.hpp>
class A
{
public:
A(){}
~A(){}
template<typename _Handler>
void call_handler(_Handler handler)
{
handler();
}
};
class B
{
public:
template<typename _Handler>
void call_handler(_Handler handler)
{
}
template<typename _Handler>
void run(_Handler handler)
{
m_a.call_handler(boost::bind(&B::call_handler<_Handler>, this, handler));
//only can use boost::bind here
}
A m_a;
};
class Test
{
public:
void handler()
{
}
};
int main()
{
B b;
Test t;
b.run(boost::bind(&Test::handler,&t));//only can use std::bind here
}
this is my little test code above.
I am confused that I only can use bind in the specific order...see note above
if I change std::bind to boost::bind ,then compiler failed,vice versa.
tested with:
gcc 4.9.2 for cygwin with option:
g++ -std=c++11 -fdiagnostics-color=always -fdiagnostics-show-location=every-line -I"/cygdrive/e/opensource libs/boost" main.cpp
msvc 12.0(visual studio 2013 with update4) with default option.
gcc diagnostic messages:
In file included from /cygdrive/e/opensource libs/boost/boost/bind.hpp:22:0, from main.cpp:3: /cygdrive/e/opensource libs/boost/boost/bind/bind.hpp: In instantiation of ‘void boost::_bi::list2::operator()(boost::_bi::type, F&, A&, int) [with F = boost::_mfi::mf1, boost::_bi::list1 > > >; A = boost::_bi::list0; A1 = boost::_bi::value; A2 = boost::_bi::bind_t, boost::_bi::list1 > >]’: /cygdrive/e/opensource libs/boost/boost/bind/bind.hpp:893:50:
required from ‘boost::_bi::bind_t::result_type boost::_bi::bind_t::operator()() [with R = void; F = boost::_mfi::mf1, boost::_bi::list1 > > >; L = boost::_bi::list2, boost::_bi::bind_t, boost::_bi::list1 > > >; boost::_bi::bind_t::result_type = void]’ main.cpp:12:11:
required from ‘void A::call_handler(_Handler) [with _Handler = boost::_bi::bind_t, boost::_bi::list1 > > >, boost::_bi::list2, boost::_bi::bind_t, boost::_bi::list1 > > > >]’ main.cpp:27:3:
required from ‘void B::run(_Handler) [with _Handler = boost::_bi::bind_t, boost::_bi::list1 > >]’ main.cpp:44:38:
required from here /cygdrive/e/opensource libs/boost/boost/bind/bind.hpp:313:34: error: invalid use of void expression unwrapper::unwrap(f, 0)(a[base_type::a1_], a[base_type::a2_]); ^
msvc 12.0 diagnostic messages:
1>------ Build started: Project: scince_x32, Configuration: Debug Win32 ------ 1> main.cpp 1>e:\opensource libs\boost\boost\bind\bind.hpp(313): error C2664: 'void boost::_mfi::mf1::operator ()(T *,A1) const' : cannot convert argument 2 from 'void' to 'boost::_bi::bind_t,boost::_bi::list1>>' 1> with 1> [ 1>
_Handler=boost::_bi::bind_t,boost::_bi::list1>> 1> , T=B 1> , A1=boost::_bi::bind_t,boost::_bi::list1>> 1> ] 1> and 1> [ 1> T=Test * 1> ] 1> Expressions of type void cannot be converted to other types 1> e:\opensource libs\boost\boost\bind\bind.hpp(893) : see reference to function template instantiation 'void boost::_bi::list2,boost::_bi::bind_t,boost::_bi::list1>>>::operator ()(boost::_bi::type,F &,A &,int)' being compiled 1> with 1> [ 1> T=B * 1> ,
F=boost::_mfi::mf1,boost::_bi::list1>>> 1> , A=boost::_bi::list0 1> ] 1> e:\opensource libs\boost\boost\bind\bind.hpp(893) : see reference to function template instantiation 'void boost::_bi::list2,boost::_bi::bind_t,boost::_bi::list1>>>::operator ()(boost::_bi::type,F &,A &,int)' being compiled 1> with 1> [ 1> T=B * 1> ,
F=boost::_mfi::mf1,boost::_bi::list1>>> 1> , A=boost::_bi::list0 1> ] 1> e:\opensource libs\boost\boost\bind\bind.hpp(891) : while compiling class template member function 'void boost::_bi::bind_t,boost::_bi::list2,boost::_bi::bind_t,boost::_bi::list1>>>>::operator ()(void)' 1> with 1> [ 1>
_Handler=boost::_bi::bind_t,boost::_bi::list1>> 1> , T=B * 1> ] 1> e:\c++program\scince_x32\scince_x32\main.cpp(12) : see reference to function template instantiation 'void boost::_bi::bind_t,boost::_bi::list2,boost::_bi::bind_t,boost::_bi::list1>>>>::operator ()(void)' being compiled 1> with 1> [ 1>
_Handler=boost::_bi::bind_t,boost::_bi::list1>> 1> , T=B * 1> ] 1> e:\c++program\scince_x32\scince_x32\main.cpp(27) : see reference to class template instantiation 'boost::_bi::bind_t,boost::_bi::list2,boost::_bi::bind_t,boost::_bi::list1>>>>' being compiled 1> with 1> [ 1>
_Handler=boost::_bi::bind_t,boost::_bi::list1>> 1> , T=B * 1> ] 1> e:\c++program\scince_x32\scince_x32\main.cpp(44) : see reference to function template instantiation 'void B::run,boost::_bi::list1>>>(_Handler)' being compiled 1> with 1> [ 1> T=Test * 1> ,
_Handler=boost::_bi::bind_t,boost::_bi::list1>> 1> ] ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Aucun commentaire:
Enregistrer un commentaire