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
4
votes
1 answer

C++: how to find max_element using boost::range?

I am trying to return an iterator to the largest element in a filtered range. Here is what I have so far: #include #include #include #include #include…
linuxfever
  • 3,763
  • 2
  • 19
  • 43
4
votes
3 answers

c++ boost lambda libraries

What might be the best way to start programming using boost lambda libraries.
yesraaj
  • 46,370
  • 69
  • 194
  • 251
3
votes
1 answer

boost lambda collection size evaluation

I have a function of the form: void DoSomething(const boost::function& condition, other stuff); This function does some work and returns only when the condition is true. The condition has been expressed as a functor argument because I…
Miral
  • 12,637
  • 4
  • 53
  • 93
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

Boost Phoenix (or Boost Lambda) - taking a pointer lazily

Is there a way of taking a pointer of a lazy phoenix value / ref ? If so how ?
Hassan Syed
  • 20,075
  • 11
  • 87
  • 171
3
votes
2 answers

C++ boost::lambda::ret equivalent in phoenix

Boost lambda allows to overwrite deduced return type using ret template. I have tried searching for equivalent in phoenix but could not find one. Is there an equivalent in phoenix? I know how to make my own Replacement but I would rather not. …
Anycorn
  • 50,217
  • 42
  • 167
  • 261
3
votes
1 answer

cannot convert boost::lambda::placeholder1_type

I am trying to play with boost::lambda, but I bumped on an error I cannot figure out how to solve. I have the feeling this is a beginner error, so please excuse my ignorance (and, I have to admit, my laziness for not reading the whole boost lamda…
unagi
  • 428
  • 3
  • 15
3
votes
2 answers

boost::function and boost::bind are cool, but what is really cool about boost::lambda?

On Page 175 Paragraph 1 of Effective C++ Meyers has this to say about generalized functors and binding: I find what tr1::function lets you do so amazing, it makes me tingle all over. If you're not tingling , it may be because you're staring…
Hassan Syed
  • 20,075
  • 11
  • 87
  • 171
3
votes
1 answer

Boost.Lambda and Boost.Function don't play nicely with Boost.Array, why?

I'm running into extremely frustrating problems with Boost. When I try running something as simple as #include #include #include #include #include…
user541686
  • 205,094
  • 128
  • 528
  • 886
3
votes
2 answers

How to use Boost (Lambda?) to make std::sort() easier?

Let's say I have struct Value { int foo(); }; size_t *begin = ...,       *end   = ...; If I want to sort a bunch of Value indices in C++03, I have to write something tedious like this: struct Comparator { Value *data; Comparator(Value…
user541686
  • 205,094
  • 128
  • 528
  • 886
2
votes
3 answers

Using boost::lambda with an STL container

The complete code is on https://gist.github.com/1341623 I'd like to sort an index array (or vector) for another vector, such that the array is ordered by the index of the other vector. However, the type of vector::at cannot be resolved. I did a try…
CrBoy
  • 43
  • 4
2
votes
3 answers

Problem nesting boost::lambda::bind-s

I have a generic function: void ImageAlbum::ExpressButtonPressed( boost::function< void ( thumb::PhotoPrintThumbnail*, thumb::PhotoPrintFormat, thumb::PhotoPrintQuantity ) > memberToCall )…
Ivan Krechetov
  • 18,802
  • 8
  • 49
  • 60
2
votes
4 answers

Boost lambda with shared_ptr

If I have a polymorphic base class called Base as well as classes Derived1 and Derived2 which inherit from Base. I can then use boost::lambda to create a factory of sorts. Something like: typedef boost::function
2
votes
3 answers

return statement in lambda expression

I created a lambda expression inside my std::for_each call. In it there is code like this one, but I have building error telling me that error: expected primary-expression before ‘return’ error: expected `]' before ‘return’ In my head I think that…
Abruzzo Forte e Gentile
  • 14,423
  • 28
  • 99
  • 173
2
votes
1 answer

using boost::lambda or boost::phoenix with std::find_if

I have a class like this class Foo { public: int GetID() const { return m_id; } private: int m_id; }; I want to use find_if on a vector full of Foo objects, like this: std::find_if(foos.begin(), foos.end(), ???.GetID() ==…
gartenriese
  • 4,131
  • 6
  • 36
  • 60