boost::bind trouble

I'm using bind with boost-1.33. I can't get a simple test to work: ----------- #include <boost/bind.hpp> int G (int a, int b, int c) { return a + b + c; } int main () { int x = boost::bind (G,_1, 4, 8)(2); } ----------- g++ -fsyntax-only -I../ -I../../src TestScale.cc TestScale.cc: In function βint main()β: TestScale.cc:14: error: no match for call to β(boost::_bi::bind_t<int, int (*)(int, int, int), boost::_bi::list3<boost::arg<1>, boost::_bi::value<int>, boost::_bi::value<int> > >) (int)β /usr/include/boost/bind/bind_template.hpp:17: note: candidates are: typename boost::_bi::result_traits<R, F>::type boost::_bi::bind_t<R, F, L>::operator()() [with R = int, F = int (*)(int, int, int), L = boost::_bi::list3<boost::arg<1>, boost::_bi::value<int>, boost::_bi::value<int> >] /usr/include/boost/bind/bind_template.hpp:23: note: typename boost::_bi::result_traits<R, F>::type boost::_bi::bind_t<R, F, L>::operator()() const [with R = int, F = int (*)(int, int, int), L = boost::_bi::list3<boost::arg<1>, boost::_bi::value<int>, boost::_bi::value<int> >] /usr/include/boost/bind/bind_template.hpp:29: note: typename boost::_bi::result_traits<R, F>::type boost::_bi::bind_t<R, F, L>::operator()(A1&) [with A1 = int, R = int, F = int (*)(int, int, int), L = boost::_bi::list3<boost::arg<1>, boost::_bi::value<int>, boost::_bi::value<int> >] /usr/include/boost/bind/bind_template.hpp:35: note: typename boost::_bi::result_traits<R, F>::type boost::_bi::bind_t<R, F, L>::operator()(A1&) const [with A1 = int, R = int, F = int (*)(int, int, int), L = boost::_bi::list3<boost::arg<1>, boost::_bi::value<int>, boost::_bi::value<int> >]

Neal Becker wrote:
I'm using bind with boost-1.33. I can't get a simple test to work:
----------- #include <boost/bind.hpp>
int G (int a, int b, int c) { return a + b + c; }
int main () { int x = boost::bind (G,_1, 4, 8)(2); }
This is the "rvalue problem", boost::bind(...) won't take 2 as an argument. To get it to compile you need int main() { int a = 2; int x = boost::bind (G,_1, 4, 8)(a); } I should probably add some const overloads.

Peter Dimov wrote:
Neal Becker wrote:
I'm using bind with boost-1.33. I can't get a simple test to work:
----------- #include <boost/bind.hpp>
int G (int a, int b, int c) { return a + b + c; }
int main () { int x = boost::bind (G,_1, 4, 8)(2); }
This is the "rvalue problem", boost::bind(...) won't take 2 as an argument. To get it to compile you need
int main() { int a = 2; int x = boost::bind (G,_1, 4, 8)(a); }
I should probably add some const overloads.
Thanks! This seems to work: int F (int a, int b) { return a + b; } template<class T> inline T& lvalue_cast (const T& rvalue) { return const_cast<T&> (rvalue); } int main () { int z = boost::bind (F, _1, 8)(lvalue_cast (2));

On Oct 21, 2005, at 12:51 PM, Peter Dimov wrote:
Neal Becker wrote:
I'm using bind with boost-1.33. I can't get a simple test to work:
----------- #include <boost/bind.hpp>
int G (int a, int b, int c) { return a + b + c; }
int main () { int x = boost::bind (G,_1, 4, 8)(2); }
This is the "rvalue problem", boost::bind(...) won't take 2 as an argument. To get it to compile you need
int main() { int a = 2; int x = boost::bind (G,_1, 4, 8)(a); }
What "rvalue problem"?! Works for me! ;-) -Howard
participants (3)
-
Howard Hinnant
-
Neal Becker
-
Peter Dimov