
If I change the parameter of first_pipe to "T & cont" this code compiles. As it stands I get this error on the lambda part of the algorithm call. Error 1 error C2664: 'std::list<_Ty>::_Iterator<_Secure_validation>::_Iterator(const std::list<_Ty>::_Iterator<_Secure_validation> &)' : cannot convert parameter 1 from 'std::list<_Ty>::_Const_iterator<_Secure_validation>' to 'const std::list<_Ty>::_Iterator<_Secure_validation> &' How can I adjust my usage so that the lambda function construction resolves the correct constness and will accept the const iterator? Thanks....code follows. #include <iostream> #include <list> #include <boost/shared_ptr.hpp> #include <boost/lambda/lambda.hpp> #include <boost/lambda/bind.hpp> #include <boost/shared_ptr.hpp> namespace esi { namespace metafunc { template < typename T > struct dereference_type { typedef T type; }; template < typename T > struct dereference_type< T* > { typedef T type; }; template < typename T > struct dereference_type< boost::shared_ptr< T > > { typedef T type; }; } } template < typename T > typename T::iterator first_pipe(T const& cont) { namespace l = boost::lambda; typedef esi::metafunc::dereference_type<T::value_type>::type value_type; return std::find_if(cont.begin(), cont.end(), l::bind(&value_type::GetType, l::_1) == DT_PIPE); } enum DT_TYPE { DT_PUMP, DT_PIPE }; struct mock_pipe { bool pipe; mock_pipe(bool b) : pipe(b) {} DT_TYPE GetType() const { return pipe ? DT_PIPE : DT_PUMP; } }; void test_first_pipe() { typedef std::list<mock_pipe*> list1_t; std::list<mock_pipe*> l; l.push_back(new mock_pipe(false)); l.push_back(new mock_pipe(false)); l.push_back(new mock_pipe(false)); list1_t::iterator fit = first_pipe(l); } int main(void) { test_first_pipe(); }
participants (1)
-
Noah Roberts