|
Boost Users : |
From: JaeWook Choi (zzzz.ooo_at_[hidden])
Date: 2006-02-18 01:16:08
Hello,
I've been trying to use STL alogorithms on POD struct data member without
writing any user defined functor nor adding get/set member function to the
POD sturct, instead I just wanted to use boost::mem_fn, boost::bind,
boost::lambda for member data pointer.
It was fine to use the member data pointer with any of boost::mem_fn,
boost::bind and boost::lambda only until I tried to use them in the nested
bind as an argument of outter bind. If I use them in nested bind, I got
compile error message of "cannot convert parameter 1 from
'boost::_bi::bind_t<R,F,L> ' to 'const RECT *'" or "cannot convert parameter
1 from 'boost::lambda::lambda_functor<T>' to 'const RECT *'"
As a boost newbie, it is too difficult for me to figure out the problem
here. Maybe someone can help me out to sovle the problem.
Thanks,
Jae.
The below is my test code. (BTW, I compiled it on VC71)
~~~
#include "stdafx.h"
#include <wtypes.h>
#include <vector>
#include <algorithm>
using std::vector;
using std::find_if;
#define BOOST_BIND_ENABLE_STDCALL
#include <boost/bind.hpp>
#include <boost/lambda/lambda.hpp>
using boost::mem_fn;
using boost::bind;
// an arbitrary POD struct
struct CTestClass
{
RECT rc;
};
int main(int argc, char* argv[])
{
vector<CTestClass> vecTestClass;
CTestClass testObj = { { 0, 0, 100, 100} };
vecTestClass.push_back(testObj);
::OffsetRect(&testObj.rc, 100, 100);
vecTestClass.push_back(testObj);
LONG rc_left = mem_fn(&CTestClass::rc)(testObj).left; // mem_data_ptr &
boost::mem_fn
LONG rc_top = bind(&CTestClass::rc, _1)(testObj).top; // mem_data_ptr &
boost::bind
LONG rc_right = ((&boost::lambda::_1)->*&CTestClass::rc)(testObj).right;
// mem_data_ptr & boost::lambda
POINT ptTest = { 150, 150 };
::PtInRect(&mem_fn(&CTestClass::rc)(testObj), ptTest); // ok
::PtInRect(&bind(&CTestClass::rc, _1)(testObj), ptTest); // ok
::PtInRect(&((&boost::lambda::_1)->*&CTestClass::rc)(testObj), ptTest);
// ok
vector<CTestClass>::iterator it_f1 =
find_if(vecTestClass.begin(), vecTestClass.end(),
bind(::PtInRect, &bind(&CTestClass::rc, _1), ptTest) ); // compile
error!
vector<CTestClass>::iterator it_f2 =
find_if(vecTestClass.begin(), vecTestClass.end(),
bind(::PtInRect, &((&boost::lambda::_1)->*&CTestClass::rc), ptTest) );
// compile error!
return 0;
}
~~~
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