Questions tagged [boost-bind]

boost::bind is a generalization of the standard C++ functions std::bind1st and std::bind2nd. It supports arbitrary function objects, functions, function pointers, and member function pointers, and is able to bind any argument to a specific value or route input arguments into arbitrary positions.

boost::bind is a generalization of the standard C++ functions std::bind1st and std::bind2nd. It supports arbitrary function objects, functions, function pointers, and member function pointers, and is able to bind any argument to a specific value or route input arguments into arbitrary positions. bind does not place any requirements on the function object; in particular, it does not need the result_type, first_argument_type and second_argument_type standard typedefs.

boost::bind was proposed for standardization and a version of it was included in as std::tr1::bind and an improved version is included in the standard as std::bind (see ).

352 questions
2
votes
1 answer

Problem with boost::bind

The following code throws an error at the line where I want to create a functor object of Test::fun2: #include #include #include using namespace boost; class Test { public: float…
rallex
  • 73
  • 5
2
votes
1 answer

Automatically delete containers sent to asynchronous functions/io_service

I would like to use an unordered_map as a job or session context object. So, I would like to allocate in some function bundle it with a static function in a function object and send this function object to an io_service. And obviously, I do not…
feeling_lonely
  • 6,665
  • 4
  • 27
  • 53
2
votes
1 answer

Rewrite boost flavored code in C++11 manner (Boost.Bind, Boost.Function)

I have some legacy code I'd like to rewrite in C++11 style. There are some boost::function defined as following // void One::first(int) boost::function a1 = boost::bind(&One::first, this, this->a); // void…
Loom
  • 9,768
  • 22
  • 60
  • 112
2
votes
1 answer

c++ generic pointer to (member?) function

I can't seem to declare a generic pointer to function. Having these 2 functions to be called: void myfunc1(std::string str) { std::cout << str << std::endl; } struct X { void f(std::string str){ std::cout<< str << std::endl;} }; and…
João Portela
  • 6,338
  • 7
  • 38
  • 51
2
votes
1 answer

solving issue # C++98 Valid use of “for_each” in the code using Boost library 1.53 or 1.56

I already asked the question. I am wondering if there is any solution for this using boost::for_each and boost::bind. The question has been already answered, that's why I created another issue here; only for the curiosity. Thanks.
H'H
  • 1,638
  • 1
  • 15
  • 39
2
votes
2 answers

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; }
SimonD
  • 638
  • 5
  • 16
2
votes
1 answer

Storing function pointers with different types c++ boost::bind

I have dug around quite a bit today and have come up empty. Is there any way to store a functor that is returned from a boost::bind with different types? I found an example that used boost::variants but not sure that this is needed. (Foo and Bar…
2
votes
2 answers

boost::bind with templated functors

Just trying to get this simple test working for accessing the function operator. I have dug around the boost::bind (esp for the overloaded section ) but have not found a way to get this to work. #include #include…
2
votes
3 answers

boost::binding that which is already bound

I have a Visual Studio 2008 C++ application that does something like this: template< typename Fcn > inline void Bar( Fcn fcn ) // line 84 { fcn(); }; template< typename Fcn > inline void Foo( Fcn fcn ) { // this works fine Bar( fcn…
PaulH
  • 7,759
  • 8
  • 66
  • 143
2
votes
1 answer

Does an instance of boost::bind retain a shared_ptr for it's lifetime?

Does boost bind increment the ref count of a shared_ptr parameter for it's lifetime? For example, take the following code: void myFunc(boost::shared_ptr in) { in->doThing(); } void myOtherFunc() { { …
MM.
  • 4,224
  • 5
  • 37
  • 74
2
votes
1 answer

Boost.Bind return type

I'm trying to fill boost::property_tree::ptree with Boost.Assign. So, I got the following worked fine: namespace bpt = boost::property_tree; bpt::ptree pt; boost::assign::make_list_inserter (boost::bind(&bpt::ptree::put, pt, _1,…
Loom
  • 9,768
  • 22
  • 60
  • 112
2
votes
1 answer

Creating a menu handler with boost bind/function

I want to create a menu handler to replace a construct like this: void MyClass::handleMenu(MenuID id) { switch (id) { case option1: doFunction1(); break; case option2: doFunction2(true); break; case option3: …
the_mandrill
  • 29,792
  • 6
  • 64
  • 93
2
votes
3 answers

boost::bind, std::bind and overloaded functions

I noticed that boost::bind, unlike std::bind, can work with overloaded functions when one of these functions doesn't have any parameters. Am I right? Is this documented? #include #include #include void…
FrozenHeart
  • 19,844
  • 33
  • 126
  • 242
2
votes
3 answers

boost::bind to concatenate strings in std::transform

I am trying to concatenate two string using boost::bind inside std::transform Assuming that my class has two methods to get two strings (first and second) and the conatiner is vector of strings, I am trying to do as follows struct Myclass { …
polapts
  • 5,493
  • 10
  • 37
  • 49
2
votes
1 answer

C++: how to use std::less with boost::bind and boost::lambda?

I am trying to lean boost::bind, boost::lambda libraries and how they can be used with STL algorithms. Suppose I have vector of int-string pairs which is sorted by int key. Then a place to insert a new pair while keeping the vector sorted can be…
Laurynas Biveinis
  • 10,547
  • 4
  • 53
  • 66