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
1
vote
6 answers

boost function and lambda to wrap a function

I want to convert this simple code: void setZComp(Imath::V3f& pt) { pt.z = 0.0; } int myfunc() { ... std::vector vec(5,Imath::V3f(1.0,1.0,1.0)); std::for_each(vec.begin(),vec.end(),boost::bind(&setZComp,_1)); …
iaiotom
  • 11
  • 1
  • 3
1
vote
2 answers

accessing static members using boost lambda

I am trying to write some simple predicate using boost::lambda and I am getting tons of errors. I checked the documentation and I have some doubt on accessing the static variable std::string::npos in a lambda expression. Below my code. #include…
Abruzzo Forte e Gentile
  • 14,423
  • 28
  • 99
  • 173
1
vote
2 answers

Using boost::lambda to copy a container

I'm here learning how to use boost::lambda. One question I have is about member function calling. It's just a test, and I'd like to do this with boost::lambda, as there are, obviously, half a million ways to copy the elements from one container to…
Gabriel
  • 1,803
  • 1
  • 13
  • 18
1
vote
2 answers

using Boost.Fusion list of function

I am trying to apply list of function object to some value in the following code. But this code cause err boost_1_44\boost\fusion\algorithm\iteration\detail\for_each.hpp(82): error C2064: How to apply list of function object to some…
1
vote
0 answers

c++ translate ostream operator to function call

I feel there should be a single liner with boost::phoenix that would let me stream an object having a member function ...::stream_to(std::ostream&) with << syntax. Something like this: struct x { void stream_to(std::ostream&); } LOG_INFO <<…
bobah
  • 18,364
  • 2
  • 37
  • 70
1
vote
2 answers

boost::lambda bind expressions can't get bind to string's empty() to work

I am trying to get the below code snippet to compile. But it fails with: error C2665: 'boost::lambda::function_adaptor::apply' : none of the 8 overloads could convert all the argument types. Specifying the return type when calling bind does not…
navigator
  • 1,588
  • 1
  • 13
  • 19
1
vote
2 answers

boost lambda::bind return type selection

I would like to call a member through lambda::bind. Unfortunately I have got two members with the same name but different return types. Is there a way to help the lambda::bind to deduce the right return type for a member function call? (bind works…
psaghelyi
  • 500
  • 4
  • 12
1
vote
1 answer

Boost lambda function call

I am learning boost lambda (not c++0X lambda because I guess they are different). But I can't find a way online to call a member function (and then output the result) if the only input parameter is a call object. I mean this line…
tete
  • 4,859
  • 11
  • 50
  • 81
1
vote
1 answer

What is wrong with this boost::lambda use?

Why is this boost::lambda expression not working? boost::function myFunct = boost::lambda::_3 < 1; I get theses compilation errors, that won't probably help, because they are really…
Mathieu Pagé
  • 10,764
  • 13
  • 48
  • 71
1
vote
1 answer

nested usage of boost::bind in boost::lambda not working

My Following Simple program on boost lambda is spewing out the following error: maxInMap.cpp:29:71: instantiated from here /usr/include/boost/lambda/detail/function_adaptors.hpp:264:15: error: invalid initialization of reference of type…
1
vote
2 answers

Setting a member of struct using boost lambda

I am trying to create vector with same values as in v. I tried the below combinations, didn't work! using namespace std; struct Wrap { int data; //Other members }; int main() { int a[10] = {2345,6345,3,243,24,234}; vector
balki
  • 26,394
  • 30
  • 105
  • 151
1
vote
3 answers

What functional language approach most readily transfers to Boost Phoenix?

I am looking to learn functional programming with an am to integrate Boost.phoenix into my project. What language is most similar so that I can find books that will illustrate functional programming concepts in a way that can be readily applies in…
1
vote
0 answers

Use of custom subscript operator with Boost.Lambda

I'm using Visual Studio 2005 and Boost 1.37. I also tested this same code on Visual Studio 2012 Express Desktop and Boost 1.50 without success. I want to use a Boost.Lambda by accessing a custom subscript operator on my type. It also happens when…
Gustavo Muenz
  • 9,278
  • 7
  • 40
  • 42
1
vote
1 answer

How to use boost::is_same in c++ template along with boost::lambda::bind

I'm trying to connect a generic boost::function to many boost::signals2 of varying signature. I'm able to use boot::lambda::bind to do the binding part by passing the return value as part of the bind parameters, but have a problem when…
Sak
  • 269
  • 1
  • 4
  • 13
0
votes
1 answer

Boost.Lambda - dereference placeholder

Is there a way to dereference a placeholder inside lambda expression ? boost::function f = _1->myMethod(); f(myObject); I know I can make a binding: boost::function f = boost::bind(&MyClass::myMethod, _1); , but I…
Marc Andreson
  • 3,405
  • 5
  • 35
  • 51