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
4
votes
2 answers

delete boost function while in use

I have a situation where a boost::function and boost::bind (actually a std::tr1::function and bind) are being deleted while still in use. Is this safe? I would normally avoid it, but the offending code is a bit entrenched and my only other option…
deft_code
  • 57,255
  • 29
  • 141
  • 224
4
votes
2 answers

Boost bind and boost function, storing functions with arguments in a vector and then executing them

Sorry for the badly-worded title. I've been looking through the documentation, but I cannot find anything that might solve this problem I have. Basically I want to store several function1 , with arguments provided, in a vector, and…
KaiserJohaan
  • 9,028
  • 20
  • 112
  • 199
4
votes
1 answer

Using nested boost::binds

Compiler: g++ 4.4.3 Boost...: 1.49.0 OS......: Ubuntu Note: It's been 15 years since I seriously used C++, so I'm relearning and learning new things as I also try to learn Boost. Given the following code: 1. class Beta { 2. public: 3. …
EdwinW
  • 1,007
  • 2
  • 13
  • 32
3
votes
2 answers

Storing boost::bind functions in a std::map

I'm creating a bunch of functions which all effectively do the same thing: long Foo::check(long retValue, unsigned toCheck, const std::set& s) { auto it = s.find(toCheck); return (it == s.end()) ? -retValue : retValue; } where Foo…
Yuushi
  • 25,132
  • 7
  • 63
  • 81
3
votes
2 answers

Using boost::bind on std::string::find fails to compile

I have the following code: int MimeDocument::GetAttachmentId( std::string const& content_id ) { using namespace boost::lambda; using boost::lambda::_1; using boost::bind; int id = 0; std::vector::iterator it = …
void.pointer
  • 24,859
  • 31
  • 132
  • 243
3
votes
3 answers

how to combine 2 independent boost::bind() into one boost::function?

I have 2 functions f() and g(). I want to call them in order every time. Can I get a boost::function to do this? E.g. something like: boost::function functor = boost::bind( boost::bind(f), boost::bind(g) ); Extend this further, say it takes…
JQ.
  • 678
  • 7
  • 17
3
votes
1 answer

what's the benefit of Boost.Functional in comparison with Boost.Bind?

I've never used Boost.Functional, only briefly read its documentation. Looks like it's an improvement to Standard header. An example on the main page of Boost.Functional (Usage section) was chosen as an introduction to the library. The…
Andriy Tylychko
  • 15,967
  • 6
  • 64
  • 112
3
votes
2 answers

boost bind class function pointer

class Foo { double f1( int x, std::string s1 ); double f2( int x, SomeClass s2 ); } I want to be able to bind Foo.f1's s1 without an instance of foo to create in essense typedef double (Foo::* MyFooFunc)( int ) MyFooFunc func1 =…
Candy Chiu
  • 6,579
  • 9
  • 48
  • 69
3
votes
4 answers

Messaging system: Callbacks can be anything

I'm trying to write an event system for my game. The callbacks that my event manager will store can be both plain functions as well as functors. I also need to be able to compare functions/functors so I know which one I need to disconnect from the…
Paul Manta
  • 30,618
  • 31
  • 128
  • 208
3
votes
2 answers

Boost lambda bewilderment

Why is callback called once only? bool callback() { static bool res = false; res = !res; return res; } int main(int argc, char* argv[]) { vector x(10); bool result=false; …
pinto
  • 919
  • 2
  • 9
  • 12
3
votes
1 answer

Member functions comparison as predicates

I have a structure like this. struct A { int someFun() const; int _value; }; I store objects of this structure in a vector. How to find the object whose member someFun() returns 42? How to find the object whose _value is 42? I guess I have…
balki
  • 26,394
  • 30
  • 105
  • 151
3
votes
3 answers

std::foreach with boost::bind

What's wrong with this: template std::list & operator+=(std::list & first, std::list const& second) { std::for_each(second.begin(), second.end(), boost::bind(&std::list::push_back, first, _1)); return first; } It…
Heptic
  • 3,076
  • 4
  • 30
  • 51
3
votes
3 answers

Bind a function against a range to make an iterating function

I am trying to implement my own bind_range that can bind against a range. It should allow client code like this: void f(int x, int y) { std::cout << x + y << ','; } std::vector v1; // contains 1,2,3 void go() { …
paperjam
  • 8,321
  • 12
  • 53
  • 79
3
votes
1 answer

Problem with boost::bind, boost::function and boost::factory

I'm trying without success to use a boost::bind with a boost::factory I have this class Zambas with 4 arguments (2 strings and 2 ints) and class Zambas { public: Zambas(const std::string&, const std::string&,int z1=0,int z2=0) { if…
Alexandre
  • 31
  • 2
3
votes
3 answers

A more natural boost::bind alternative?

Don't get me wrong: Boost's bind() is great. But I do hate to write&read code with it, and I've given up hope my coworkers will ever grok/use it. I end up with code like this: btn.clicked.connect(bind(&BetBar::placeBet, this,…
Iraimbilanja