N
Noah Roberts
template < typename T >
typename T::const_iterator first_pipe(T const& cont)
{
namespace l = boost::lambda;
typedef esi::metafunc::dereference_type<typename T::value_type>::type
value_type; // value type is mock_pipe_base in this case.
return std::find_if(cont.begin(), cont.end(),
l::bind(&value_type::GetType, *(l::_1)) == DT_PIPE);
}
struct mock_pipe_base
{
bool pipe;
mock_pipe_base(bool b) : pipe(b) {}
DT_TYPE GetType() const {
return pipe ? DT_PIPE : DT_PUMP;
}
virtual void f() = 0;
};
struct mock_pipe : mock_pipe_base
{
mock_pipe(bool b) : mock_pipe_base(b) {}
void f() {}
};
typedef std::list<mock_pipe_base*> list1_t;
list1_t l;
l.push_back(list1_t::value_type(new mock_pipe(false)));
l.push_back(list1_t::value_type(new mock_pipe(false)));
l.push_back(list1_t::value_type(new mock_pipe(false)));
list1_t::const_iterator fit = first_pipe(l);
This results in an attempt to instantiate a mock_pipe_base object,
which is of course not possible.
I can provide the real error if desired but it is quite lengthy. It
definately has something to do with the lambda expression. I'm hoping
someone will be able to look at that and know what I'm doing wrong and
be able to provide a solution. I'm about to disallow use of lambda in
our projects but I would like to come up with a solution and leave it
open with some guidelines for use.
Thanks.
typename T::const_iterator first_pipe(T const& cont)
{
namespace l = boost::lambda;
typedef esi::metafunc::dereference_type<typename T::value_type>::type
value_type; // value type is mock_pipe_base in this case.
return std::find_if(cont.begin(), cont.end(),
l::bind(&value_type::GetType, *(l::_1)) == DT_PIPE);
}
struct mock_pipe_base
{
bool pipe;
mock_pipe_base(bool b) : pipe(b) {}
DT_TYPE GetType() const {
return pipe ? DT_PIPE : DT_PUMP;
}
virtual void f() = 0;
};
struct mock_pipe : mock_pipe_base
{
mock_pipe(bool b) : mock_pipe_base(b) {}
void f() {}
};
typedef std::list<mock_pipe_base*> list1_t;
list1_t l;
l.push_back(list1_t::value_type(new mock_pipe(false)));
l.push_back(list1_t::value_type(new mock_pipe(false)));
l.push_back(list1_t::value_type(new mock_pipe(false)));
list1_t::const_iterator fit = first_pipe(l);
This results in an attempt to instantiate a mock_pipe_base object,
which is of course not possible.
I can provide the real error if desired but it is quite lengthy. It
definately has something to do with the lambda expression. I'm hoping
someone will be able to look at that and know what I'm doing wrong and
be able to provide a solution. I'm about to disallow use of lambda in
our projects but I would like to come up with a solution and leave it
open with some guidelines for use.
Thanks.