Search code examples
boostboost-lambda

How do I create a simple boost::lambda function?


I'm trying to create a simple function that makes a simple test and return true or false.

myfunct = (_3 < someArray[i]);

When I do this, I get this error :

error: no match for 'operator<' in '<unnamed>::_1 < depths[i]'

What I hope is get something equivalent to this

bool myFunct(unsigned int a, unsigned int b, unsigned int c, unsigned int d)
{
   return c < 22; // Suppose 22 was in someArray[i]
}

Solution

  • Are you sure you've got the namespaces right?

    It should be either

    using namespace boost::lambda;
    

    or

    boost::lambda::_1
    

    Remember that placeholders are used in other parts of boost, or in other libraries (conflict with a local TR1 may happen!), which may induce errors.