Hi,
The code below does not compile and gives me 2 errors that, whatever I
try, do not want to disappear. What am I doing wrong?
TIA
The errors:
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"Main.d" -MT"Main.d" -o"Main.o" "../Main.cpp"
../Main.cpp: In function ‘std::map, std::basic_string, std::less >, std::allocator, std::basic_string > > > getObjects(const Predicate&)’:
../Main.cpp:34: error: no matching function for call to ‘bind(<unresolved overloaded function type>, std::map, std::basic_string, std::less >, std::allocator, std::basic_string > > >*&, std::pair >, boost::tuples::tuple std::pair, std::basic_string >::* const, const boost::lambda::lambda_functor >, 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::lambda::lambda_functor >, boost::tuples::tuple std::pair, std::basic_string >::* const, const boost::lambda::lambda_functor >, 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> > > >&)’
../Main.cpp: In function ‘int main(int, char**)’:
../Main.cpp:46: error: no match for ‘operator<<’ in ‘boost::lambda::operator<<(A&, const boost::lambda::lambda_functor<Arg>&) [with A = std::ostream, Arg = boost::lambda::lambda_functor_base >, boost::tuples::tuple std::pair, std::basic_string >::* const, const boost::lambda::lambda_functor >, 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> >](((const boost::lambda::lambda_functor >, boost::tuples::tuple std::pair, std::basic_string >::* const, const boost::lambda::lambda_functor >, 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::lambda::bind(const Arg1&, const Arg2&) [with Arg1 = const std::basic_string std::pair, std::basic_string >::*, Arg2 = boost::lambda::lambda_functor >](((const boost::lambda::lambda_functor >&)((const boost::lambda::placeholder1_type*)boost::lambda::<unnamed>::_1)))))) << std::endl’
../Main.cpp: In function ‘std::map, std::basic_string, std::less >, std::allocator, std::basic_string > > > getObjects(const Predicate&) [with Predicate = boost::function]’:
../Main.cpp:45: instantiated from here
../Main.cpp:28: error: no matching function for call to ‘bind(<unresolved overloaded function type>, std::map, std::basic_string, std::less >, std::allocator, std::basic_string > > >*, std::pair >, boost::tuples::tuple std::pair, std::basic_string >::* const, const boost::lambda::lambda_functor >, 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::lambda::lambda_functor >, boost::tuples::tuple std::pair, std::basic_string >::* const, const boost::lambda::lambda_functor >, 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> > > >)’
make: *** [Main.o] Error 1
The code:
#include <iostream>
#include <map>
#include
#include
#include
#include
#include
using namespace std;
using namespace boost;
using namespace boost::lambda;
map objects;
template< typename Predicate >
map getObjects( const Predicate& aPredicate)
{
map matchedObjects;
for_each( objects.begin(),
objects.end(),
if_then(
bind(aPredicate, boost::lambda::_1) ,
bind(&map::insert,
&matchedObjects ,
make_pair(bind(&map::value_type::first, _1),bind(&map::value_type::second,_1)))));
return matchedObjects;
}
int main( int argc,
char* argv[])
{
objects.insert(make_pair("one","value"));
objects.insert(make_pair("two","value"));
objects.insert(make_pair("three","value"));
function< bool (string)> predicate = _1 == "value";
map matchedObjects = getObjects(predicate);
for_each(matchedObjects.begin(),matchedObjects.end(),cout << bind(&map::value_type::first, _1) << endl);
}
--
Groeten,
Joost Kraaijeveld
Askesis B.V.
Molukkenstraat 14
6524NB Nijmegen
tel: 024-3888063 / 06-51855277
fax: 024-3608416
web: www.askesis.nl