Boost logo

Boost :

From: Neal Becker (ndbecker2_at_[hidden])
Date: 2005-10-21 12:29:14


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));


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk