Questions tagged [boost-lambda]

The Boost Lambda Library is a C++ template library, which implements a form of lambda abstractions for C++

The primary motivation for the Boost Lambda is to provide flexible and convenient means to define unnamed function objects for STL algorithms.

The following line outputs the elements of some STL container a separated by spaces:

for_each(a.begin(), a.end(), std::cout << _1 << ' ');

The expression std::cout << _1 << ' ' defines a unary function object.

The variable _1 is the parameter of this function, a placeholder for the actual argument. Within each iteration of for_each, the function is called with an element of a as the actual argument. This actual argument is substituted for the placeholder, and the “body” of the function is evaluated.

The essence of Boost Lambda is letting you define small unnamed function objects, such as the one above, directly on the call site of an STL algorithm.

76 questions
14
votes
3 answers

Does bind() have any advantage (other than compatibility) over C++11 lambdas?

I'm thinking about migrating my code toward using C++11-style lambdas instead of having binds everywhere. But I'm not sure if it's a good idea or not. Does using e.g. boost::lambda (or boost::phoenix) have any practical advantage over C++11-style…
user541686
  • 205,094
  • 128
  • 528
  • 886
12
votes
2 answers

Difference between boost::bind, boost::lambda::bind and boost::phoenix::bind

I am trying to understand the difference between these different bind approaches. There is a similar question at boost::bind and boost::phoenix::bind But, if anyone can explain this with examples it would be great. Also is it true that…
polapts
  • 5,493
  • 10
  • 37
  • 49
10
votes
1 answer

boost lambda versus phoenix

I recently started looking at boost phoenix, as replacement for lambda. Is phoenix a full replacement for lambda, or is there some lambda functionality which is not provided by phoenix? is phoenix mature? Are there any gotcha I should know…
Anycorn
  • 50,217
  • 42
  • 167
  • 261
10
votes
1 answer

Correct use of boost lambda

Consider the following piece of C++0x code: a_signal.connect([](int i) { if(boost::any_cast(_buffer[i]) == "foo") { base_class<>* an_object = new derived_class(); an_object->a_method(_buffer[i]); }}); How would it…
Karl von Moor
  • 8,484
  • 4
  • 40
  • 52
9
votes
2 answers

another copy algorithm

I have two vectors. vector objects; vector names; These two vectors are populated and have the same size. I need some algorithm which does assignment to the object variable. It could be using boost::lambda. Let's…
sigidagi
  • 864
  • 7
  • 17
8
votes
3 answers

How can I use Boost.Bind on compound types?

I have std::map >, and I need to find the minimal short in this map. How can I use boost::bind with std::min_element() for this? boost::lambda?
Andriy Tylychko
  • 15,967
  • 6
  • 64
  • 112
6
votes
1 answer

What is the difference between boost::bind and boost::lambda::bind?

I can see that there are two different bind libraries for Boost, one "standalone", that can be used by including boost/bind.hpp, and another by including boost/lambda/bind.hpp. What's the difference between these two?
petersohn
  • 11,292
  • 13
  • 61
  • 98
5
votes
2 answers

Using boost::format in a boost::lambda

For some reason, I fail to use boost::format in a boost::lambda. Here is a (hopefully) compilable simplification of my code : #include #include #include #include #include…
icecrime
  • 74,451
  • 13
  • 99
  • 111
5
votes
1 answer

How to use a phoenix expression with boost::transform_iterator?

As usual for me, the question was a wrong one. The actual question is: why doesn't transform_iterator use the conventional result_of<> metafunction to determine the return type, instead of accessing UnaryFunc::result_type directly. Posted…
academicRobot
  • 6,097
  • 1
  • 31
  • 29
4
votes
2 answers

boost::lambda expression fails to compile because of instantiation of abstract template arg. Any explanation and/or work arounds?

I'm in the process of learning boost::lambda and I've managed to create a situation that I can't resolve with what I know so far. Apparently in the bowels of boost::lambda, the following example causes the attempted instantiation of abstract class…
Catskul
  • 17,916
  • 15
  • 84
  • 113
4
votes
3 answers

How to write a boost::lambda functor that returns a new functor

How can I write a lambda expression with two placeholders, one for the callable object, and one for the function argument, such that supplying the callable object first returns a unary function. In the example below, generate should be a lambda…
Sebastian
  • 4,802
  • 23
  • 48
4
votes
2 answers

boost::lambda expression doesn't compile

I tried to write a function that calculates a hamming distance between two codewords using the boost lambda library. I have the following code: #include #include #include #include…
Venkat Shiva
  • 799
  • 1
  • 7
  • 9
4
votes
2 answers

Boost phoenix or lambda library problem: removing elements from a std::vector

I recently ran into a problem that I thought boost::lambda or boost::phoenix could help be solve, but I was not able to get the syntax right and so I did it another way. What I wanted to do was remove all the elements in "strings" that were less…
Raindog
  • 1,468
  • 3
  • 14
  • 28
4
votes
2 answers

Post callbacks to a task queue using boost::bind

Suppose I have a function called subscribe() that takes a callback handler, which will be called when the event is triggered. Now, I have another version, called subscribe2(). Everything is the same except that, when triggered, it needs to post it…
4
votes
1 answer

What's wrong of this use of boost::lambda::bind?

I'm trying to use boost::lambda::bind() to define a predicate that I pass to the find_if algorithm in Boost.Range. Specifically, I want to search a vector of structures to find the first entry where a particular member has a specified value. My…
Jason R
  • 11,159
  • 6
  • 50
  • 81
1
2 3 4 5 6