|
Boost Users : |
From: Surya Kiran Gullapalli (skg_at_[hidden])
Date: 2005-02-07 07:49:33
Hi all,
This is a follow up to my previous message on boost::bind question.
Please go thru the attached program.
I've 2 structures X an Y, and i'm calling stable_sort on vectors of both
the objects.
But in one stable sort, i'm using the member variable directly, and in
the other i'm using a member function to access that.
When i use boost::bind with member variable directly, it has no problem
(structure Y),
But if i use member function to access the member variable, which is
private, i'm getting compilation errors, The essence of the compilation
error is given below..
=====================
./boost/include/boost/lambda/detail/actions.hpp:86: error: no matching
function for call to `boost::lambda::function_adaptor<int
(X::*)()>::apply(int (X::*const&)(), const X&)'
./boost/include/boost/lambda/detail/function_adaptors.hpp:193: note:
candidates are: static Result boost::lambda::function_adaptor<Result
(Object::*)()>::apply(Result (Object::*)(), Object*) [with RET = int,
Object = X, Result = int]
./boost/include/boost/lambda/detail/function_adaptors.hpp:197: note:
static Result boost::lambda::function_adaptor<Result
(Object::*)()>::apply(Result (Object::*)(), Object&) [with RET = int,
Object = X, Result = int]
=====================
what am i doing wrong.
thanks in advance,
Surya
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace boost::lambda ;
using namespace std ;
struct X
{
private:
int a ;
public:
X () {}
int get_a() { return a ; }
void set_a (int var) { a = var ;}
} ;
struct Y
{
int a ;
} ;
int main (void)
{
vector <X> vx ;
vector <Y> vy ;
X varx1; varx1.set_a(5) ; vx.push_back (varx1) ;
X varx2; varx2.set_a(8) ; vx.push_back (varx2) ;
X varx3; varx3.set_a(7) ; vx.push_back (varx3) ;
X varx4; varx4.set_a(4) ; vx.push_back (varx4) ;
X varx5; varx5.set_a(9) ; vx.push_back (varx5) ;
X varx6; varx6.set_a(2) ; vx.push_back (varx6) ;
X varx7; varx7.set_a(6) ; vx.push_back (varx7) ;
Y vary1; vary1.a = 5 ; vy.push_back (vary1) ;
Y vary2; vary2.a = 8 ; vy.push_back (vary2) ;
Y vary3; vary3.a = 7 ; vy.push_back (vary3) ;
Y vary4; vary4.a = 4 ; vy.push_back (vary4) ;
Y vary5; vary5.a = 9 ; vy.push_back (vary5) ;
Y vary6; vary6.a = 2 ; vy.push_back (vary6) ;
Y vary7; vary7.a = 6 ; vy.push_back (vary7) ;
cout << "BEFORE SORT" << '\t' ;
for_each (vy.begin(), vy.end(), cout << bind (&Y::a, _1) << '\t') ;
cout << endl ;
stable_sort (vy.begin(), vy.end(), bind (less<int>(), bind (&Y::a, _1), bind (&Y::a, _2))) ;
cout << "AFTER SORT" << '\t' ;
for_each (vy.begin(), vy.end(), cout << bind (&Y::a, _1) << '\t') ;
cout << endl ;
#if 0
cout << "BEFORE SORT" << '\t' ;
for_each (vx.begin(), vx.end(), cout << bind (&X::get_a, _1) << '\t') ;
cout << endl ;
stable_sort (vx.begin(), vx.end(), bind (less<int>(), bind (&X::get_a, _1), bind (&X::get_a, _2))) ;
cout << "AFTER SORT" << '\t' ;
for_each (vx.begin(), vx.end(), cout << bind (&X::get_a, _1) << '\t') ;
cout << endl ;
#endif
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