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

boost lambda with a vector of shared pointers

Below is a slightly modified code from one good example how to copy values fro one vector of strings to another vector of objects. (see: another copy algorithm ) #include #include #include #include #include…
sigidagi
  • 864
  • 7
  • 17
0
votes
1 answer

Can I use C++11 lambda with libevent?

There is a callback function type in libevent used by event_new(). typedef void (*event_callback_fn)(evutil_socket_t, short, void *); I want use lambda with event_callback_fn. If I use [](evutil_socket_t fd, short flags, void *…
DinoStray
  • 696
  • 1
  • 6
  • 20
0
votes
3 answers

lambda bind problem?

I am a new beginner with boost. And here is my test code, using namespace boost::lambda; std::vector strings; strings.push_back("Boost"); strings.push_back("C++"); strings.push_back("Libraries"); std::vector sizes;…
leo
  • 61
  • 1
  • 9
0
votes
0 answers

Access member of returned struct in boost lambda/phoenix

I want to replace some older code with simpler, functor based code. But I don't want to introduce a functor class for this and use boost::lambda/phoenix for this as I don't have C++11 at hand. Old code looks like this int player = ...; Point…
Flamefire
  • 5,313
  • 3
  • 35
  • 70
0
votes
2 answers

Copy map to vector

I have to copy certain elements from a std::map into a vector. It should work like in this loop: typedef int First; typedef void* Second; std::map map; // fill map std::vector mVec; for (std::map::const_iterator…
0
votes
1 answer

Using static_cast in boost::lambda

I need to use boost::lambda for some conversion. I've tried this: static_cast(boost::lambda::_1 * 60 * 1000) But I've got error: error C2440: 'static_cast' : cannot convert from 'const boost::lambda::lambda_functor' to 'size_t' How to put…
brachistochron
  • 321
  • 1
  • 11
0
votes
2 answers

Boost lambda: Invoke method on object

I'm looking at boost::lambda as a way to to make a generic algorithm that can work with any "getter" method of any class. The algorithm is used to detect duplicate values of a property, and I would like for it to work for any property of any…
ckarras
  • 4,946
  • 2
  • 33
  • 37
0
votes
1 answer

How to write boost::lambda expression as function callback argument

Suppose I have the following code: #include #include #include #include
SunLiWei
  • 1,313
  • 4
  • 11
  • 30
0
votes
0 answers

Boost lambda with std::find_if does not compile

Consider this template member method of some class: template bool elementIsInSharedPtrVector(const T& p_elem, const std::vector< boost::shared_ptr< T > >& p_Vector) const { return (std::find_if(p_Vector.begin(), p_Vector.end(),…
Juergen
  • 3,489
  • 6
  • 35
  • 59
0
votes
2 answers

Boost lambda recursion?

Can boost::lambda be used recursively? This doesn't compile: using namespace boost::lambda; auto factorial = (_1 == 0) ? 1 : factorial(_1-1); Is there a suggested workaround? EDIT: Regarding using C++11 lambdas: The following does not compile on…
David H
  • 1,461
  • 2
  • 17
  • 37
0
votes
1 answer

How to use boost::lambda to create new object for an existing pointer?

What I want to do is --> create a new object in a new thread. Something like: Class* object = 0; Arg arg; boost::thread t( lambda::bind( object = lambda::new_ptr< Class >()( boost::ref( arg ) ); it doesn't compile, what's correct way?
JQ.
  • 678
  • 7
  • 17
0
votes
1 answer

Where is boost::lambda::ll?

I can't seem to find boost::lambda::ll for a nested ll::for_each() invocations in any header file in the boost_1_39_0 distribution. Could someone point me to the right direction? Thanks.
SYK
  • 644
  • 6
  • 17
0
votes
1 answer

ref() in Boost::Lambda?

What is the equivalent of Boost::Phoenix's ref in Boost::Lambda? I can't find it in the online docs. #include #include #include using namespace boost::lambda; int main() { std::string a, b; …
user541686
  • 205,094
  • 128
  • 528
  • 886
0
votes
1 answer

using boost::lambda_ to compress whitespaces in a string

I am using boost::lambda to remove subsequent whitespaces in a string, leaving only one space. I tried this program. #include #include #include #include int main() { std::string s =…
navigator
  • 1,588
  • 1
  • 13
  • 19
0
votes
1 answer

using boost lambda with compound expressions

I have a Visual Studio 2008 C++03 application where I would like to use boost::lambda to perform this action: enum { fooflag = 0x00000001; } bool IsFooFlagActive( DWORD flags ) { return ( flags & fooflag ) != 0; } Unfortunately, this doesn't…
PaulH
  • 7,759
  • 8
  • 66
  • 143