Search code examples
c++boostboost-bindboost-lambda

boost bind or lambda functor that returns a constant


Can I use boost::bind or the boost lambda library to create a functor that ignores its arguments and always returns a constant?

e.g. a functor with equivalent behaviour to:

int returnThree( SomeType arg ) { return 3; }

Solution

  • From Barry's comment on sehe's answer:

    #include "boost/lambda/lambda.hpp"
    
    ...
    
    auto returnThree = boost::lambda::constant(3);