Boost logo

Boost Users :

Subject: [Boost-users] [bind] Pointer as third parameter
From: Jean-Pierre Bergamin (james_at_[hidden])
Date: 2008-12-18 08:03:17


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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net