[bind] Pointer as third parameter
Dear boost-Users I'm having problems with calling a function that takes a pointer as the third argument through bind. I cannot explain, why the code below does not compile with the function 'op3' enabled. When changing f3 to void f3(int a, int b, int c) { } it also works. I don't see any reasony why this should fail, since f2 also works. Any ideas how to solve this? // --------------------------------------- void f3(int a, int b, int *c) { } void f2(int a, int *b) { } template <typename F> void op3(F f) { int a = 1, b = 2, c = 3; f(a, b, &c); } template <typename F> void op2(F f) { int a = 1, b = 2; f(a, &b); } void call() { op2(boost::bind(&f2, _1, _2)); //op3(boost::bind(&f3, _1, _2, _3)); } // --------------------------------------- This compiles fine. When uncommenting the line op3(...) in the function "call", gcc fails with: test.cpp: In function `void op3(F) [with F = boost::_bi::bind_t<void, void (*)(int, int, int*), boost::_bi::list3<boost::arg<1> (*)(), boost::arg<2> (*)(), boost::arg<3> (*)()> >]': test.cpp:23: instantiated from here test.cpp:11: error: no match for call to `(boost::_bi::bind_t<void, void (*)(int, int, int*), boost::_bi::list3<boost::arg<1> (*)(), boost::arg<2> (*)(), boost::arg<3> (*)()> >) (int&, int&, int*)' /usr/local/include/boost/bind/bind_template.hpp:18: note: candidates are: typename boost::_bi::result_traits<R, F>::type boost::_bi::bind_t<R, F, L>::operator()() [with R = void, F = void (*)(int, int, int*), L = boost::_bi::list3<boost::arg<1> (*)(), boost::arg<2> (*)(), boost::arg<3> (*)()>] /usr/local/include/boost/bind/bind_template.hpp:24: note: typename boost::_bi::result_traits<R, F>::type boost::_bi::bind_t<R, F, L>::operator()() const [with R = void, F = void (*)(int, int, int*), L = boost::_bi::list3<boost::arg<1> (*)(), boost::arg<2> (*)(), boost::arg<3> (*)()>] /usr/local/include/boost/bind/bind_template.hpp:114: note: typename boost::_bi::result_traits<R, F>::type boost::_bi::bind_t<R, F, L>::operator()(A1&, A2&, A3&) [with A1 = int, A2 = int, A3 = int*, R = void, F = void (*)(int, int, int*), L = boost::_bi::list3<boost::arg<1> (*)(), boost::arg<2> (*)(), boost::arg<3> (*)()>] /usr/local/include/boost/bind/bind_template.hpp:120: note: typename boost::_bi::result_traits<R, F>::type boost::_bi::bind_t<R, F, L>::operator()(A1&, A2&, A3&) const [with A1 = int, A2 = int, A3 = int*, R = void, F = void (*)(int, int, int*), L = boost::_bi::list3<boost::arg<1> (*)(), boost::arg<2> (*)(), boost::arg<3> (*)()>] MSVC 8 fails with: .\test.cpp(19) : error C2664: 'void boost::_bi::bind_t<R,F,L>::operator ()<int,int,int*__w64 >(A1 &,A2 &,A3 &) const' : cannot convert parameter 3 from 'int *__w64 ' to 'int *__w64 &' with [ R=void, F=void (__cdecl *)(int,int,int *), L=boost::_bi::list3<boost::arg<1>,boost::arg<2>,boost::arg<3>>, A1=int, A2=int, A3=int *__w64 ] .\Sleep.cpp(29) : see reference to function template instantiation 'void op3<boost::_bi::bind_t<R,F,L>>(boost::_bi::bind_t<R,F,L>)' being compiled with [ R=void, F=void (__cdecl *)(int,int,int *), L=boost::_bi::list3<boost::arg<1>,boost::arg<2>,boost::arg<3>> ] Thanks for your help. James
Jean-Pierre Bergamin wrote:
Dear boost-Users
I'm having problems with calling a function that takes a pointer as the third argument through bind. I cannot explain, why the code below does not compile with the function 'op3' enabled. When changing f3 to void f3(int a, int b, int c) { } it also works. I don't see any reasony why this should fail, since f2 also works.
Any ideas how to solve this?
// --------------------------------------- void f3(int a, int b, int *c) { } void f2(int a, int *b) { }
template <typename F> void op3(F f) { int a = 1, b = 2, c = 3; f(a, b, &c); }
template <typename F> void op2(F f) { int a = 1, b = 2; f(a, &b); }
void call() { op2(boost::bind(&f2, _1, _2)); //op3(boost::bind(&f3, _1, _2, _3)); } // ---------------------------------------
Works for me on MSVC 8 w/ 64bit disabled.
MSVC 8 fails with:
.\test.cpp(19) : error C2664: 'void boost::_bi::bind_t<R,F,L>::operator ()<int,int,int*__w64 >(A1 &,A2 &,A3 &) const' : cannot convert parameter 3 from 'int *__w64 ' to 'int *__w64 &' with [ R=void, F=void (__cdecl *)(int,int,int *), L=boost::_bi::list3<boost::arg<1>,boost::arg<2>,boost::arg<3>>, A1=int, A2=int, A3=int *__w64 ] .\Sleep.cpp(29) : see reference to function template instantiation 'void op3<boost::_bi::bind_t<R,F,L>>(boost::_bi::bind_t<R,F,L>)' being compiled with [ R=void, F=void (__cdecl *)(int,int,int *), L=boost::_bi::list3<boost::arg<1>,boost::arg<2>,boost::arg<3>> ]
Did you try: void f3(int a, int b, int* __w64 c) { } Jeff
Jeff Flinn schrieb:
Jean-Pierre Bergamin wrote:
I'm having problems with calling a function that takes a pointer as the third argument through bind. I cannot explain, why the code below does not compile with the function 'op3' enabled. When changing f3 to void f3(int a, int b, int c) { } it also works. I don't see any reasony why this should fail, since f2 also works.
Any ideas how to solve this?
// --------------------------------------- void f3(int a, int b, int *c) { } void f2(int a, int *b) { }
template <typename F> void op3(F f) { int a = 1, b = 2, c = 3; f(a, b, &c); }
template <typename F> void op2(F f) { int a = 1, b = 2; f(a, &b); }
void call() { op2(boost::bind(&f2, _1, _2)); //op3(boost::bind(&f3, _1, _2, _3)); } // ---------------------------------------
Works for me on MSVC 8 w/ 64bit disabled. I just found out that it works with boost 1.37 on MSVC 8, but not with 1.34.1. Any clue how to get this working with 1.34.1 (since 1.37 is not avaialable for FreeBSD yet)?
Regards James
On Thu, Dec 18, 2008 at 1:20 PM, Jean-Pierre Bergamin <james@ractive.ch>wrote:
I just found out that it works with boost 1.37 on MSVC 8, but not with 1.34.1. Any clue how to get this working with 1.34.1 (since 1.37 is not avaialable for FreeBSD yet)?
If it helps it works on 1.36/Gcc too. - Rob.
Robert Jones schrieb:
On Thu, Dec 18, 2008 at 1:20 PM, Jean-Pierre Bergamin <james@ractive.ch> wrote:
I just found out that it works with boost 1.37 on MSVC 8, but not with 1.34.1. Any clue how to get this working with 1.34.1 (since 1.37 is not avaialable for FreeBSD yet)?
If it helps it works on 1.36/Gcc too. Unfortunately, 1.34.1 is the last official port for FreeBSD. :-(
James
Jean-Pierre Bergamin: ...
f(a, b, &c);
...
I just found out that it works with boost 1.37 on MSVC 8, but not with 1.34.1. Any clue how to get this working with 1.34.1 (since 1.37 is not avaialable for FreeBSD yet)?
The problem is that, in 1.34, 'f' doesn't accept non-const rvalues (temporaries). You can fix that with int * pc = &c; f( a, b, pc ); or with f( a, b, static_cast< int* const& >( &c ) ); -- Peter Dimov http://www.pdplayer.com
Peter Dimov schrieb:
Jean-Pierre Bergamin: ...
f(a, b, &c);
...
I just found out that it works with boost 1.37 on MSVC 8, but not with 1.34.1. Any clue how to get this working with 1.34.1 (since 1.37 is not avaialable for FreeBSD yet)?
The problem is that, in 1.34, 'f' doesn't accept non-const rvalues (temporaries). You can fix that with
int * pc = &c; f( a, b, pc );
or with
f( a, b, static_cast< int* const& >( &c ) );
Thank you. That solves this issue. Strange enough that the non-const rvalue works for the function that only takes two parameters f(a, &b). But anyway. I'm happy that it works this way. James
participants (4)
-
Jean-Pierre Bergamin
-
Jeff Flinn
-
Peter Dimov
-
Robert Jones