|
Boost Users : |
From: David Greene (greened_at_[hidden])
Date: 2006-01-11 13:27:25
Hi again,
As can can probably guess, I'm just learning how to use the BLL.
Here's another testcase I'm having trouble with:
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
#include <boost/iterator/counting_iterator.hpp>
#include <vector>
#include <algorithm>
#include <cassert>
class Test {
private:
int value;
public:
Test(int v) : value(v) {};
int get(void) const { return(value); };
};
std::vector<Test> seq;
std::vector<Test>::iterator find_value(const Test &value)
{
using boost::lambda::bind;
using boost::lambda::_1;
return(std::find(seq.begin(), seq.end(),
bind(&Test::get, _1) == value.get()));
}
int main(void)
{
std::copy(boost::counting_iterator<int>(0),
boost::counting_iterator<int>(10),
std::back_inserter(seq));
std::vector<Test>::iterator i = find_value(0);
assert(i == seq.begin());
i = find_value(5);
assert(i != seq.end());
i = find_value(11);
assert(i == seq.end());
return(0);
}
[compile log below]
Another question: when using bind to delay application of the member
function to the object, is the object passed by reference or value
on invocation? If by value, is there a way to pass it by reference?
It's not relevant to this test but will be in the code I'm
working on. I'm thinking of cases where I might want to
run transform algorithms on Test objects.
Thanks for your help. Some of this is just learning to pattern-match
gcc's cryptic template error messages.
-Dave
-------------------
/usr/include/c++/3.3.3/bits/stl_algo.h: In function `_RandomAccessIter
std::find(_RandomAccessIter, _RandomAccessIter, const _Tp&,
std::random_access_iterator_tag) [with _RandomAccessIter =
__gnu_cxx::__normal_iterator<Test*, std::vector<Test,
std::allocator<Test> >
>, _Tp =
boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::relational_action<boost::lambda::equal_action>,
boost::tuples::tuple<const int,
boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<2,
boost::lambda::function_action<2, boost::lambda::detail::unspecified> >,
boost::tuples::tuple<int (Test::*const)() const, const
boost::lambda::lambda_functor<boost::lambda::placeholder<1> >,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type> > >,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type> > >]':
/usr/include/c++/3.3.3/bits/stl_algo.h:298: instantiated from
`_InputIter std::find(_InputIter, _InputIter, const _Tp&) [with
_InputIter = __gnu_cxx::__normal_iterator<Test*, std::vector<Test,
std::allocator<Test> > >, _Tp =
boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::relational_action<boost::lambda::equal_action>,
boost::tuples::tuple<const int,
boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<2,
boost::lambda::function_action<2, boost::lambda::detail::unspecified> >,
boost::tuples::tuple<int (Test::*const)() const, const
boost::lambda::lambda_functor<boost::lambda::placeholder<1> >,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type> > >,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type> > >]'
lambda2.cc:28: instantiated from here
/usr/include/c++/3.3.3/bits/stl_algo.h:208: error: could not convert `
boost::lambda::operator==(const A&, const
boost::lambda::lambda_functor<Arg>&) [with A = Test, Arg =
boost::lambda::lambda_functor_base<boost::lambda::relational_action<boost::lambda::equal_action>,
boost::tuples::tuple<const int,
boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<2,
boost::lambda::function_action<2, boost::lambda::detail::unspecified> >,
boost::tuples::tuple<int (Test::*const)() const, const
boost::lambda::lambda_functor<boost::lambda::placeholder<1> >,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type> > >,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type> >]((+__val))' to
`bool'
/usr/include/c++/3.3.3/bits/stl_algo.h:298: instantiated from
`_InputIter std::find(_InputIter, _InputIter, const _Tp&) [with
_InputIter = __gnu_cxx::__normal_iterator<Test*, std::vector<Test,
std::allocator<Test> > >, _Tp =
boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::relational_action<boost::lambda::equal_action>,
boost::tuples::tuple<const int,
boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<2,
boost::lambda::function_action<2, boost::lambda::detail::unspecified> >,
boost::tuples::tuple<int (Test::*const)() const, const
boost::lambda::lambda_functor<boost::lambda::placeholder<1> >,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type> > >,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type> > >]'
lambda2.cc:28: instantiated from here
/usr/include/c++/3.3.3/bits/stl_algo.h:211: error: could not convert `
boost::lambda::operator==(const A&, const
boost::lambda::lambda_functor<Arg>&) [with A = Test, Arg =
boost::lambda::lambda_functor_base<boost::lambda::relational_action<boost::lambda::equal_action>,
boost::tuples::tuple<const int,
boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<2,
boost::lambda::function_action<2, boost::lambda::detail::unspecified> >,
boost::tuples::tuple<int (Test::*const)() const, const
boost::lambda::lambda_functor<boost::lambda::placeholder<1> >,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type> > >,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type> >]((+__val))' to
`bool'
/usr/include/c++/3.3.3/bits/stl_algo.h:214: error: could not convert `
boost::lambda::operator==(const A&, const
boost::lambda::lambda_functor<Arg>&) [with A = Test, Arg =
boost::lambda::lambda_functor_base<boost::lambda::relational_action<boost::lambda::equal_action>,
boost::tuples::tuple<const int,
boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<2,
boost::lambda::function_action<2, boost::lambda::detail::unspecified> >,
boost::tuples::tuple<int (Test::*const)() const, const
boost::lambda::lambda_functor<boost::lambda::placeholder<1> >,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type> > >,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type> >]((+__val))' to
`bool'
/usr/include/c++/3.3.3/bits/stl_algo.h:217: error: could not convert `
boost::lambda::operator==(const A&, const
boost::lambda::lambda_functor<Arg>&) [with A = Test, Arg =
boost::lambda::lambda_functor_base<boost::lambda::relational_action<boost::lambda::equal_action>,
boost::tuples::tuple<const int,
boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<2,
boost::lambda::function_action<2, boost::lambda::detail::unspecified> >,
boost::tuples::tuple<int (Test::*const)() const, const
boost::lambda::lambda_functor<boost::lambda::placeholder<1> >,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type> > >,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type> >]((+__val))' to
`bool'
/usr/include/c++/3.3.3/bits/stl_algo.h:223: error: could not convert `
boost::lambda::operator==(const A&, const
boost::lambda::lambda_functor<Arg>&) [with A = Test, Arg =
boost::lambda::lambda_functor_base<boost::lambda::relational_action<boost::lambda::equal_action>,
boost::tuples::tuple<const int,
boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<2,
boost::lambda::function_action<2, boost::lambda::detail::unspecified> >,
boost::tuples::tuple<int (Test::*const)() const, const
boost::lambda::lambda_functor<boost::lambda::placeholder<1> >,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type> > >,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type> >]((+__val))' to
`bool'
/usr/include/c++/3.3.3/bits/stl_algo.h:226: error: could not convert `
boost::lambda::operator==(const A&, const
boost::lambda::lambda_functor<Arg>&) [with A = Test, Arg =
boost::lambda::lambda_functor_base<boost::lambda::relational_action<boost::lambda::equal_action>,
boost::tuples::tuple<const int,
boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<2,
boost::lambda::function_action<2, boost::lambda::detail::unspecified> >,
boost::tuples::tuple<int (Test::*const)() const, const
boost::lambda::lambda_functor<boost::lambda::placeholder<1> >,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type> > >,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type> >]((+__val))' to
`bool'
/usr/include/c++/3.3.3/bits/stl_algo.h:229: error: could not convert `
boost::lambda::operator==(const A&, const
boost::lambda::lambda_functor<Arg>&) [with A = Test, Arg =
boost::lambda::lambda_functor_base<boost::lambda::relational_action<boost::lambda::equal_action>,
boost::tuples::tuple<const int,
boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<2,
boost::lambda::function_action<2, boost::lambda::detail::unspecified> >,
boost::tuples::tuple<int (Test::*const)() const, const
boost::lambda::lambda_functor<boost::lambda::placeholder<1> >,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type> > >,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type> >]((+__val))' to
`bool'
make: *** [lambda2.o] Error 1
Compilation exited abnormally with code 2 at Wed Jan 11 12:21:07
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