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

Boost.Lambda: Insert into a different data structure

I have a vector that I want to insert into a set. This is one of three different calls (the other two are more complex, involving boost::lambda::if_()), but solving this simple case will help me solve the others. std::vector
Austin Ziegler
  • 776
  • 10
  • 17
2
votes
1 answer

Boost lambda example

I have a map created as a part of solution enum Opcode { OpFoo, OpBar, OpQux, }; // this should be a pure virtual ("abstract") base class class Operation { // ... }; class OperationFoo: public Operation { // this should be a…
Marshel Abraham
  • 87
  • 2
  • 12
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
2 answers

Trying to use boost lambda, but my code won't compile

I am trying to use boost lambda to avoid having to write trivial functors. For example, I want to use the lambda to access a member of a struct or call a method of a class, eg: #include #include #include #include…
hamishmcn
  • 7,843
  • 10
  • 41
  • 46
2
votes
6 answers

boost lambda or phoenix problem: using std::for_each to operate on each element of a container

I ran into a problem while cleaning up some old code. This is the function: uint32_t ADT::get_connectivity_data( std::vector< std::vector > &output ) { output.resize(chunks.size()); for(chunk_vec_t::iterator it = chunks.begin(); it…
Raindog
  • 1,468
  • 3
  • 14
  • 28
2
votes
2 answers

How do I create a simple boost::lambda function?

I'm trying to create a simple function that makes a simple test and return true or false. myfunct = (_3 < someArray[i]); When I do this, I get this error : error: no match for 'operator<' in '::_1 < depths[i]' What I hope is get something…
Mathieu Pagé
  • 10,764
  • 13
  • 48
  • 71
2
votes
1 answer

Calling a member function using boost::lambda

I am learning the boost::lambda library and for that I wrote this sample code to convert an vector into vector by extracting the value from A object. class A { public: A(int n) : m_n(n){} int get() const {return m_n;} private: …
Naveen
  • 74,600
  • 47
  • 176
  • 233
2
votes
2 answers

Usage of boost lambdas

I am new to boost and trying to write some simple programs to understand it. Here in the following piece of code I am trying to fill an array with random numbers. Here is my code: using namespace boost::lambda; srand(time(NULL)); …
Naveen
  • 74,600
  • 47
  • 176
  • 233
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
2
votes
1 answer

Assign object the return value of boost::lambda::bind?

I would think it could be useful to store a bound lambda function to be used later, yet I haven't seen any examples on the return value of the boost::lambda::bind function being assigned to an object of that return type. Is there no way to do this…
jwalk
  • 1,120
  • 11
  • 27
2
votes
1 answer

expressing _1.second->pair().first == r in boost::lambda

I've an expression that I need to put in std::transform as callback, but I don't want to write another method for it. I want to express the expression _1.second->pair().first == r to boost::lambda assuming _1 is the only argument passed to it of…
Neel Basu
  • 12,638
  • 12
  • 82
  • 146
2
votes
1 answer

What is wrong with this boost::lambda::bind usage?

Is there something wrong in this code? I keep getting compilation errors. Basically I want to connect a void returning function to a signal which has a non void return type. Boost version: Release 1.46.1 #include #include…
Sak
  • 269
  • 1
  • 4
  • 13
1
vote
1 answer

MSVC and boost::lambda::bind error: T0: standard-argment not allowed

This code compiles fine with GCC and Clang but not with MSVC 2010: #include #include #include #include #include enum Actions {}; std::string eventStart(size_t…
Albert
  • 65,406
  • 61
  • 242
  • 386
1
vote
2 answers

problems with C++ boost lambda and ==-operator

There is: template bool any(::Ref > i, boost::function pred) { // ... } And: template struct Ref { // ... }; template struct Iterator { // ... }; Then I have this call (which…
Albert
  • 65,406
  • 61
  • 242
  • 386
1
vote
1 answer

functional programming techniques for generating objects on the heap

There is example of code which generates N objects of class A on the heap: #include #include #include #include #include using boost::make_shared; using…
sigidagi
  • 864
  • 7
  • 17